-
Notifications
You must be signed in to change notification settings - Fork 0
/
player.h
63 lines (54 loc) · 1.93 KB
/
player.h
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
#pragma once
#include "rocket.h"
#include "bboxed.h"
class Player : public Rocket, public Bboxed {
protected:
std::string name;
float rotationSpeed = 250;
float throttleStep = 1;
public:
Player(std::string _name, float life, float damage, sf::Vector2f position, sf::FloatRect bbox, std::vector<Entity*> *renderQueue) : Rocket(_name, life, damage, position, renderQueue), Bboxed(bbox) {
name = _name;
mass = 1000;
};
void checkBoundries() {
position = sprite.getPosition();
if(!bbox.contains(position)) {
if(position.x <= bbox.left) {
position.x = bbox.left;
velocity.x *= -1 * springiness;
}
if(position.y <= bbox.top) {
position.y = bbox.top;
velocity.y *= -1 * springiness;
}
if(position.x >= (bbox.width - bbox.left)) {
position.x = (bbox.width - bbox.left);
velocity.x *= -1 * springiness;
}
if(position.y >= (bbox.height - bbox.top)) {
position.y = (bbox.height - bbox.top);
velocity.y *= -1 * springiness;
}
sprite.setPosition(position);
}
//std::cout<<position.x << ", " << position.y << ": " << velocity.x << ", " << velocity.y << std::endl;
}
void throttleUp() {
setThrottle(throttle + throttleStep * animationTime.asMilliseconds()/1000);
}
void throttleDown() {
setThrottle(throttle - throttleStep * animationTime.asMilliseconds()/1000);
}
void rotateClockwise() {
rotation -= rotationSpeed * animationTime.asMilliseconds()/1000;
}
void rotateCounterClockwise() {
rotation += rotationSpeed * animationTime.asMilliseconds()/1000;
}
void animate() {
Rocket::animate();
checkBoundries();
animationTimer.restart();
}
};