-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBall.cpp
64 lines (52 loc) · 1.05 KB
/
Ball.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
#include "Ball.h"
#include "ofMain.h"
#include "Paddle.h"
Ball::Ball () {
}
Ball::Ball(float x, float y, int r, float xV, float yV, int score, int lives, ofColor color) {
this->x = x;
this->y = y;
this->r = r;
this->xV = xV;
this->yV = yV;
this->score = score;
this->lives = lives;
this->color = color;
}
void Ball::draw() {
ofSetColor(0, 255, 0);
ofNoFill();
ofDrawCircle(x, y, 2*r);
ofSetCircleResolution(100);
}
void Ball::reset() {
x = ofGetWidth() / 2;
y = ofGetHeight() / 2;
xV = 1.25;
yV = -1.25;
}
void Ball::bulletMove() {
x += 20;
}
void Ball::move() {
y += yV;
x += xV;
if (x <= r) {
x = r;
xV *= -1;
--score;
--lives;
} else if (x >= ofGetWindowWidth() - r) {
x = ofGetWindowWidth() - r;
xV = -1.25;
++score;
reset();
}
if (y <= r) {
y = r;
yV *= -1;
} else if (y >= ofGetWindowHeight() - r) {
y = ofGetWindowHeight() - r;
yV *= -1;
}
}