-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPlayer.cpp
More file actions
81 lines (69 loc) · 2.1 KB
/
Player.cpp
File metadata and controls
81 lines (69 loc) · 2.1 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
76
77
78
79
80
81
#include "Player.h"
Player::Player(double x, double y) : Character(x,y){
vel = 2;
Character::size = size;
};
Player::~Player(){};
//***********************************************
// OTHER FUNCTIONS
//***********************************************
void Player::reload(){};
void Player::update(){
checkInput();
updateInercia();
};
void Player::draw(){
double correctedX = X - CAMERA->getX();
double correctedY = Y - CAMERA->getY();
//GRAPHIC
circlefill(CANVAS, (int)correctedX, (int)correctedY, size, makecol(50,50,200));
circlefill(CANVAS, (int)correctedX-1, (int)correctedY-1, size-2, makecol(90,90,220));
circlefill(CANVAS, (int)correctedX-2, (int)correctedY-2, size-4, makecol(130,130,250));
circlefill(CANVAS, (int)correctedX-3, (int)correctedY-3, size-6, makecol(200,200,240));
circlefill(CANVAS, (int)correctedX-4, (int)correctedY-4, size-8, makecol(240,240,255));
circle(CANVAS, (int)correctedX, (int)correctedY, size, makecol(0,0,0));
};
void Player::checkInput(){
Helper myHelper;
//-MOVEMENT-//
if (key[KEY_W]) {
if (myHelper.abs(inerciaY) < inerciaSpeedLimit){
inerciaY -= inerciaInc * 4;
}
goUp();
}
if (key[KEY_S]) {
if (myHelper.abs(inerciaY) < inerciaSpeedLimit){
inerciaY += inerciaInc * 4;
}
goDown();
}
if (key[KEY_D]) {
if (myHelper.abs(inerciaX) < inerciaSpeedLimit){
inerciaX += inerciaInc * 4;
}
goRight();
}
if (key[KEY_A]) {
if (myHelper.abs(inerciaX) < inerciaSpeedLimit){
inerciaX -= inerciaInc * 4;
}
goLeft();
}
};
void Player::updateInercia(){
//IF LEGAL, MOVE; IF NOT BOUNCE ON WALL (or whatever)
if(legalMovement(X + inerciaX, Y)){
X += inerciaX;
}else{
inerciaX = -inerciaX;
}
if(legalMovement(X, Y + inerciaY)){
Y += inerciaY;
}else{
inerciaY = -inerciaY;
}
//INERCIA DECAY
if(inerciaY > 0){inerciaY -= inerciaInc;}else if(inerciaY < 0){inerciaY += inerciaInc;}
if(inerciaX > 0){inerciaX -= inerciaInc;}else if(inerciaX < 0){inerciaX += inerciaInc;}
};