-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathball.cpp
101 lines (92 loc) · 1.75 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
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
#define SDL_MAIN_HANDLED
#include"ball.h"
using namespace std;
ball :: ball()
{
idle = true;
facingLeft = false;
frameClip = 0;
FRAME_Idle = 10;
DELAY_Idle = 6;
setIdle();
FRAME_MOVING = 8;
DELAY_MOVING = 6;
setMoving();
x = 200;
y = 200;
playerdesRect = {x,y,50,43 };
CatdesRect = {10,460,300,290};
DogdesRect = {310,460,300,290};
countdead = 0;
}
void ball::setMoving()
{
for (int i = 0; i < FRAME_MOVING; i++)
{
clipsMOVING[i].x = i * 189;
clipsMOVING[i].y = 0;
clipsMOVING[i].w = 189;
clipsMOVING[i].h = 165;
}
}
void ball::setIdle()
{
for (int i = 0; i < FRAME_Idle; i++)
{
clipsIDLE[i].x = i * 169;
clipsIDLE[i].y = 0;
clipsIDLE[i].w = 169;
clipsIDLE[i].h = 147;
}
}
void ball::animationIDLE()
{
frameClip++;
if (frameClip >= FRAME_Idle * DELAY_Idle) frameClip = 0;
playersourceRect = clipsIDLE[frameClip / DELAY_Idle];
}
void ball:: animationMOVING()
{
frameClip++;
if (frameClip >= FRAME_MOVING * DELAY_MOVING) frameClip = 0;
playersourceRect = clipsMOVING[frameClip / DELAY_MOVING];
}
void ball::MoveLeft()
{
facingLeft = false;
idle = false;
if(x >=0 )
x -= 4;
}
void ball::MoveRight()
{
facingLeft = true;
idle = false;
if(x < 560)
x += 4;
}
void ball::getinput()
{
const Uint8* key = SDL_GetKeyboardState(NULL);
idle = true;
if (key[SDL_SCANCODE_A]) {
ball::MoveLeft();
}
if (key[SDL_SCANCODE_D]) {
ball::MoveRight();
}
}
void ball::setdesrect() {
playerdesRect.x = x;
playerdesRect.y = y += 4;
}
void ball:: ballup()
{
playerdesRect.x = x;
playerdesRect.y = y -= 4 * 2;
}
void ball :: isDie()
{
playerdesRect.x = x;
playerdesRect.y = y -= 4 ;
}