-
Notifications
You must be signed in to change notification settings - Fork 0
/
paddles.cpp
55 lines (50 loc) · 1.01 KB
/
paddles.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
#include "paddles.h"
Paddle::Paddle(int xUser , int yUser, SDLKey key1, SDLKey key2)
{
x = xUser;
y = yUser;
yVelocity = 0;
paddleUp = key1;
paddleDown = key2;
}
void Paddle::handle_input()
{
if(event.type == SDL_KEYDOWN)
{
if(event.key.keysym.sym == paddleUp)
{
yVelocity -= SPEED;
}
else if(event.key.keysym.sym == paddleDown)
{
yVelocity += SPEED;
}
}
else if(event.type == SDL_KEYUP)
{
if(event.key.keysym.sym == paddleUp)
{
yVelocity += SPEED;
}
else if(event.key.keysym.sym == paddleDown)
{
yVelocity -= SPEED;
}
}
}
void Paddle::move(Uint32 deltaTicks)
{
y += yVelocity * ( deltaTicks / 1000.f );
if( y < 0 )
{
y = 0;
}
else if( y + PADDLE_HEIGHT > SCREEN_HEIGHT)
{
y = SCREEN_HEIGHT - PADDLE_HEIGHT;
}
}
void Paddle::show()
{
apply_surface( (int)x, (int)y, paddleSprite, screen );
}