-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcPlayer.cpp
More file actions
75 lines (68 loc) · 1.95 KB
/
cPlayer.cpp
File metadata and controls
75 lines (68 loc) · 1.95 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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
/*
=================
cPlayer.cpp
- Header file for class definition - IMPLEMENTATION
=================
*/
#include "cPlayer.h"
/*
=================================================================
Defualt Constructor
=================================================================
*/
cPlayer::cPlayer() : cSprite()
{
this->playerVelocity = 0;
}
/*
=================================================================
Update the sprite position
=================================================================
*/
void cPlayer::update(double deltaTime)
{
auto rads = PI / 180.0f * (this->getSpriteRotAngle() - 90.0f);
FPoint direction = { 0.0f, 0.0f };
direction.X = (float)(sin(rads));
direction.Y = (float)(cos(rads)) * (-1);
SDL_Rect currentSpritePos = this->getSpritePos();
currentSpritePos.x += (int)(this->playerVelocity * direction.X * this->move * deltaTime * 3);
this->setSpritePos({ currentSpritePos.x , currentSpritePos.y });
this->setBoundingRect(this->getSpritePos());
}
/*
=================================================================
Sets the velocity for the player
=================================================================
*/
void cPlayer::setPlayerVelocity(int playerVel)
{
playerVelocity = playerVel;
}
/*
=================================================================
Gets the player velocity
=================================================================
*/
int cPlayer::getPlayerVelocity()
{
return playerVelocity;
}
/*
=================================================================
Sets the move value for the player
=================================================================
*/
void cPlayer::setPlayerMove(int playerMove)
{
move = playerMove;
}
/*
=================================================================
Gets the player move value
=================================================================
*/
int cPlayer::getPlayerMove()
{
return move;
}