-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcBulletStuVer.cpp
More file actions
58 lines (51 loc) · 1.63 KB
/
cBulletStuVer.cpp
File metadata and controls
58 lines (51 loc) · 1.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
/*
=================
cBullet.cpp
- Header file for class definition - IMPLEMENTATION
=================
*/
#include "cBullet.h"
/*
=================================================================
Defualt Constructor
=================================================================
*/
cBullet::cBullet() : cSprite()
{
this->bulletVelocity = 0;
}
/*
=================================================================
Update the sprite position
=================================================================
*/
void cBullet::update(double deltaTime)
{
auto rads = PI / 180.0f * (this->getSpriteRotAngle() - 90.0f);
FPoint direction = { 0.0f, 0.0f };
direction.X = (float)(cos(rads));
direction.Y = (float)(sin(rads));
SDL_Rect currentSpritePos = this->getSpritePos();
currentSpritePos.x += (int)(direction.X * this->bulletVelocity * this->getSpriteTranslation().x * deltaTime);
currentSpritePos.y += (int)(direction.Y * this->bulletVelocity * this->getSpriteTranslation().y * deltaTime);
this->setSpritePos({ currentSpritePos.x, currentSpritePos.y });
this->setBoundingRect(this->getSpritePos());
}
/*
=================================================================
Sets the velocity for the Bullet
=================================================================
*/
void cBullet::setBulletVelocity(int bulletVel)
{
this->bulletVelocity = bulletVel;
}
/*
=================================================================
Gets the Bullet velocity
=================================================================
*/
int cBullet::getBulletVelocity()
{
return this->bulletVelocity;
}