blob: 98d464f452e1d6e0171c7f33d061c1210f941b21 (
plain)
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
|
#include "ball.hpp"
Ball::Ball(int x, int y, int speed) {
m_position[0] = x;
m_position[1] = y;
m_speed = speed;
}
void Ball::update() {
m_position[1] += 1 * m_speed;
if (m_pressed_left)
m_position[0] -= 5 * m_speed;
if (m_pressed_right)
m_position[0] += 5 * m_speed;
if (m_position[0] > DISPLAY_WIDTH)
m_position[0] = DISPLAY_WIDTH;
else if (m_position[0] < 0)
m_position[0] = 0;
if (m_position[1] > DISPLAY_HEIGHT)
m_position[1] = DISPLAY_HEIGHT;
else if (m_position[1] < 0) {
m_position[1] = 0;
m_has_died = true;
}
}
void Ball::draw(Api *app_api) {
app_api->display_draw_ellipse((int)m_position[0], (int)m_position[1], m_radius, m_radius, 1, 1);
}
|