diff options
Diffstat (limited to 'apps/game_falldown/ball.cpp')
-rw-r--r-- | apps/game_falldown/ball.cpp | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/apps/game_falldown/ball.cpp b/apps/game_falldown/ball.cpp new file mode 100644 index 0000000..98d464f --- /dev/null +++ b/apps/game_falldown/ball.cpp @@ -0,0 +1,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); +}
\ No newline at end of file |