-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPlayer.cpp
More file actions
executable file
·86 lines (77 loc) · 1.48 KB
/
Copy pathPlayer.cpp
File metadata and controls
executable file
·86 lines (77 loc) · 1.48 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
82
83
84
85
#include "Player.h"
#include <SFML/Window/Keyboard.hpp>
#include <iostream>
using namespace std;
using namespace sf;
Player::Player() : Object("Textures/ponytron.png"){
spr1.setScale(0.07,0.07);
spr1.setPosition(50,300);
lefttex.loadFromFile("Textures/ponytronback.png");
righttex.loadFromFile("Textures/ponytron.png");
t_up = Keyboard::Key::Up;
t_right = Keyboard::Key::Right;
t_left = Keyboard::Key::Left;
}
void Player::Update ( ) {
if(Keyboard::isKeyPressed(t_up)){
if(y<-600){
velocityY = +10;
}
else{
velocityY = -10;
}
}
if(Keyboard::isKeyPressed(t_right)){
if(x<limitrt && cont!=0){
velocityX = 13;
}
}
if(!Keyboard::isKeyPressed(t_right)){
if(x<limitrt && cont!=0){
velocityX = 8;
}
}
if(Keyboard::isKeyPressed(t_left)){
if(x>=25500){
velocityX = -13;
}
}
if(!Keyboard::isKeyPressed(t_left)){
if(x>=25500){
velocityX = -8;
}
}
if(x>=25500){
cont=0;
velocityX = -8;
spr1.setTexture(lefttex);
}
if(x<800){
velocityX = +8;
cont=1;
spr1.setTexture(righttex);
}
UpdateMovement();
spr1.setPosition(x,y);
}
void Player::UpdateMovement ( ) {
if(y<400){
velocityY += gravity; //gravity system
}
else if(y>400)
y=400; //ground
velocityX += accelerationX;
velocityY += accelerationY;
x += velocityX;
y += velocityY;
}
int Player::getPositionX ( ) {
return x;
}
int Player::getPositionY ( ) {
return y;
}
bool Player::checkpos ( ) {
if(cont!=1) return false; //pposition of the player + or -
else return true;
}