-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPaddle.cpp
More file actions
60 lines (50 loc) · 1.23 KB
/
Copy pathPaddle.cpp
File metadata and controls
60 lines (50 loc) · 1.23 KB
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
#include "Paddle.h"
#include <iostream>
using namespace std;
Paddle::Paddle() {
cout << "loaded" << endl;
load("data/bat.bmp", 53, 10, 1);
this->speed = 7;
cleanup();
}
Paddle::~Paddle() {
SDL_FreeSurface(this->entitySurf);
}
void Paddle::tick() {
int newX = this->x;
if (this->goingLeft) {
newX = this->x - this->speed;
if (newX < 5) {
newX = 5;
}
} else if (this->goingRight) {
newX = this->x + this->speed;
if (newX > SWIDTH - this->width - 5) {
newX = SWIDTH - this->width - 5;
}
}
this->x = newX;
}
void Paddle::keyDown(int key) {
if (key == 1) {
this->goingLeft = true;
} else if (key == 2) {
this->goingRight = true;
}
}
void Paddle::keyUp(int key) {
if (key == 1) {
this->goingLeft = false;
} else if (key == 2) {
this->goingRight = false;
}
}
void Paddle::render(SDL_Surface* display) {
Draw::drawSurface(display, this->entitySurf, this->x, this->y, 0, 0, 53, 10);
}
void Paddle::cleanup() {
this->goingLeft = false;
this->goingRight = false;
this->x = SWIDTH/2 - 53;
this->y = SHEIGHT - 15;
}