-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPaddle.cpp
41 lines (29 loc) · 1023 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
#include "Paddle.h"
#include "Game.h"
static Vector2 window_size = Vector2(0, 0);
static Vector2 paddle_size = Vector2(96, 16);
bool key_states[512];
Paddle::Paddle() {
for(int i = 0; i < 512; i++)
key_states[i] = false;
texture_name = "Resources/png/paddle.png";
window_size = Game::get_instance()->get_window()->get_size();
position = Vector2((window_size.X / 2) - (paddle_size.X / 2), window_size.Y - 100);
size = paddle_size;
object_name = "Paddle";
object_class_name = "Paddle";
load_texture();
}
void Paddle::event_update(SDL_Event event) {}
void Paddle::draw() { SpriteObject::draw(); }
void Paddle::update(float delta_time) {
SpriteObject::update(delta_time);
int mouseX, mouseY;
SDL_GetMouseState(&mouseX, &mouseY);
position.X = mouseX - (paddle_size.X / 2);
// Collision with wall
if(position.X > window_size.X - paddle_size.X)
position.X = (window_size.X - paddle_size.X) + 1.0f;
if(position.X < 0)
position.X = 0;
}