-
Notifications
You must be signed in to change notification settings - Fork 53
Expand file tree
/
Copy pathplayer.cpp
More file actions
78 lines (59 loc) · 1.2 KB
/
Copy pathplayer.cpp
File metadata and controls
78 lines (59 loc) · 1.2 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
#include "player.h"
#include <math.h>
#include <vector>
const double pi = 3.1415926535897;
const int gravity = 1;
const int screenWidth = 800;
const int screenHeight = 450;
Player::Player(double x, double y, int width, int height) {
this->x = x;
this->y = y;
this->width = width;
this->height = height;
onPlatform = false;
}
double Player::getX() {
return x;
}
double Player::getY() {
return y;
}
void Player::setX(int x) {
this->x = x;
}
void Player::setY(int y) {
this->y = y;
}
int Player::getWidth() {
return width;
}
int Player::getHeight() {
return height;
}
bool Player::isOnGround() {
return onPlatform;
}
bool Player::isOnPlatform() {
return onPlatform;
}
void Player::setOnPlatform(bool result) {
onPlatform = result;
}
void Player::setVelocity(double x, double y) {
velocity = (Vector2){(int)x, (int)y};
}
Vector2 Player::getVelocity() {
return velocity;
}
void Player::updatePosition() {
x += velocity.x;
y += velocity.y;
if (!isOnGround())
velocity.y += gravity;
else
velocity = (Vector2){0, 0};
if (x < 0)
velocity.x *= -1;
if (x + width > 800)
velocity.x *= -1;
}