-
Notifications
You must be signed in to change notification settings - Fork 0
/
Paddle.cpp
110 lines (89 loc) · 1.75 KB
/
Paddle.cpp
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
//Paddle.cpp
//Jordan baxter
#include "Paddle.h"
#include "Ball.h"
#include "Bullet.h"
Paddle::Paddle(int x) {
this->x = x;
this->y = ofGetHeight() / 2;
this->h = ofGetHeight() / 10;
this->w = ofGetWidth() / 150;
this->s = ofGetHeight() * .01;
this->lives = 4;
this->ammo = 0;
this->color = ofColor(255, 255, 255);
this->state = "free";
this->time = 0;
};
void Paddle::draw() {
ofSetColor(this->color);
ofDrawRectangle(this->x, this->y, this->w, this->h);
}
void Paddle::moveUp() {
this->y -= this->s;
}
void Paddle::moveDown() {
this->y += this->s;
}
void Paddle::fire(vector<Bullet*> b) {
b[this->ammo]->fire(this);
this->ammo -= 1;
}
void Paddle::trackBall(vector<Ball*> balls) {
Ball* closest = balls[0];
for (int i = 0; i < balls.size(); ++i) {
if (balls[i]->getX() > closest->getX()) {
closest = balls[i];
}
}
if (this->state == "free") {
this->y = closest->getY() - this->h / 2;
}
}
void Paddle::trackMouse(float y) {
this->y = y - this->h/2;
}
void Paddle::leftResize() {
this->w = ofGetWidth() / 150;
this->h = ofGetHeight() / 15;
}
void Paddle::rightResize() {
this->w = ofGetWidth() / 150;
this->h = ofGetHeight() / 15;
this->x = ofGetWidth() - ofGetWidth() / 150 - 20;
}
void Paddle::changeLives(int n) {
this->lives += n;
}
void Paddle::changeAmmo(int n) {
this->ammo += n;
}
void Paddle::frozen() {
if (this->time < ofGetElapsedTimef() - 100) {
this->state = "frozen";
}
else {
this->state = "free";
}
}
void Paddle::changeTime(float t) {
this->time = t;
}
int Paddle::getLives() {
return this->lives;
}
int Paddle::getAmmo() {
return this->ammo;
}
int Paddle::getX() {
return this->x;
}
int Paddle::getY() {
return this->y;
}
int Paddle::getW() {
return this->w;
}
int Paddle::getH() {
return this->h;
}