-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPaddle.cpp
59 lines (46 loc) · 821 Bytes
/
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
#include "Paddle.h"
#include "Ball.h"
Paddle::Paddle() {
}
Paddle::Paddle( int x, int y, int w, int h, float v, ofColor color) {
this->x = x;
this->y = y;
this->w = w;
this->h = h;
this->v = 0;
this->color = color;
}
void Paddle::draw() {
ofSetColor(color);
ofDrawRectangle(x, y, w, h);
}
void Paddle::upKey() {
y += 20;
}
void Paddle::downKey() {
y -= 20;
}
void Paddle::MoveUp() {
v += 1;
}
void Paddle::MoveDown() {
v -= 1;
}
void Paddle::track(Ball *b) {
if (b->y >= y + h) {
MoveUp();
} else if (b->y <= y) {
MoveDown();
}
}
void Paddle::paddle_move(Paddle *p) {
y += v;
if (y + w >= ofGetWidth()) {
y = ofGetWidth() - w;
v *= -0.1;
}
if (y <= 0) {
y = 0;
v *= -0.1;
}
}