-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBall.cpp
66 lines (59 loc) · 1.08 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
63
64
65
66
#include "Ball.h"
CBall::CBall(int x, int y, int width, int height, int dx, int dy, ACL_Image *img, rect r1)
: SpriteBase(x, y, width, height, dx, dy, img, r1), health(1), next(NULL)
{
}
CBall::CBall(CBall &bl) : SpriteBase(bl), health(bl.health), next(bl.next)
{
}
CBall::~CBall()
{
}
void CBall::move(rect r1)
{
if (x< r.x || x> (r.x+r.width-width)){
dx*= -1;
}
if (y< r.y || y> (r.y+r.height-height)){
dy*= -1;
}
x+= dx;
y+= dy;
}
void CBall::SetNext(CBall *nxt)
{
next= nxt;
}
void CBall::LoseHealth()
{
--health;
}
CBall* CBall::GetNext()
{
return next;
}
int CBall::ShowHealth()
{
return health;
}
int CBall::Collision(rect rc)
{
rect rr= {x, y, width, height};
if (rr.x< rc.x && rr.x+rr.width > rc.x){
if (rr.y< rc.y && rr.y+rr.height> rc.y){
return 1;
}
else if (rr.y> rc.y && rr.y< rc.y+rc.height){
return 1;
}
}
else if (rr.x> rc.x && rr.x< rc.x+rc.width){
if (rr.y< rc.y && rr.y+rr.height> rc.y){
return 1;
}
else if (rr.y> rc.y && rr.y< rc.y+rc.height){
return 1;
}
}
return 0;
}