-
Notifications
You must be signed in to change notification settings - Fork 0
/
Player.pde
132 lines (112 loc) · 3.03 KB
/
Player.pde
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
public class Player{
private float currentSpeed;
private float maxSpeed = 2000;
private float initialSpeed;
private PVector position;
private PVector size;
private PImage image;
private float stirSpeed = 300;
private float turn = 0;
private float turnRadius = radians(5);
private float currentHP = 1000;
private float initialHP = 1000;
private boolean isDead = false;
private boolean canTakeDamage = true;
private float lastTimeSinceDamage = 0;
private float invinsibleTime = 1;
private int score = 0;
private Minim minim;
private AudioPlayer ap;
private boolean slowMode;
public Player(PImage image, PVector inicialPos, PVector size, float inicialSpeed, Minim minim){
this.currentSpeed = inicialSpeed;
this.initialSpeed = inicialSpeed;
this.position = inicialPos;
this.image = image;
this.size = size;
image.resize((int)size.x, (int)size.y);
currentHP = initialHP;
this.minim = minim;
ap = minim.loadFile("motor.wav");
//ap.loop();
}
//TEST VALUES
public void display(){
imageMode(CENTER);
pushMatrix();
translate(position.x, position.y);
rotate(turn*turnRadius);
image(image, 0, 0, size.x, size.y);
popMatrix();
imageMode(CORNER);
}
public void stir(float position){
turn = position;
this.position.x += position * stirSpeed / frameRate;
}
public void speedUp(){
if(currentSpeed < maxSpeed)
currentSpeed += 20/frameRate;
}
public float getSpeed(){
return this.currentSpeed * (slowMode ? 0.5 : 1);
}
public PVector getPosition(){
return this.position;
}
public PVector getSize(){
return this.size;
}
public void collisionDetected(Obstacle ob, float dmg){
if(canTakeDamage){
//println("Collision");
lastTimeSinceDamage = millis();
canTakeDamage = false;
currentHP -= dmg;
}
}
public void update(){
if(isDead()){
currentSpeed = 0;
ap.pause();
}
if(!canTakeDamage && millis() - lastTimeSinceDamage >= invinsibleTime * 1000){
canTakeDamage = true;
}
if(position.x > width-image.width/2)
position.x = width-image.width/2;
if(position.x < image.width/2)
position.x = image.width/2;
if(position.x < 200 || position.x > 600 ){
currentHP -= 50/frameRate;
}
}
public boolean isDead(){
isDead = currentHP <= 0;
return isDead;
}
public void addScore(int add){
score += add;
}
private void passiveScore(){
score += round(millis() %1000);
}
public int getScore(){
return this.score;
}
public float getCurrentHP(){
return this.currentHP;
}
public float getInitialHP(){
return this.initialHP;
}
public void reset(){
currentHP = initialHP;
score = 0;
currentSpeed = initialSpeed;
isDead = false;
}
public void slowDown(boolean state){
this.slowMode = state;
}
}