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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
|
#include "main.hpp"
// TODO in this app
// -
void app_game_falldown::update_game() {
m_player_ball.update();
for (auto platform : m_platforms) {
platform.update();
}
if (m_player_ball.m_has_died)
m_gamestate = gameover;
}
void app_game_falldown::draw_game() {
m_app_api->display_fill(0, 0);
m_player_ball.draw(m_app_api);
for (auto platform : m_platforms) {
platform.draw(m_app_api);
}
}
void app_game_falldown::draw_main_menu() {
m_app_api->gui_header_text("A Falldown clone", 0,0,true);
m_app_api->gui_header_text("Press select to start", 0,2);
m_app_api->gui_header_text("In game:", 0,3);
m_app_api->gui_header_text("up/down btns to move", 0,4);
}
void app_game_falldown::draw_gameover_menu() {
m_app_api->gui_header_text("Game Over!", 30,2,true);
}
void app_game_falldown::init_game() {
// place the player
m_platforms.push_back(30);
m_gamestate = game;
}
BaseApp::AppReturnValues app_game_falldown::render(Api *app_api) {
switch (m_gamestate) {
case menu:
draw_main_menu(); break;
case game:
update_game(); draw_game(); break;
case gameover:
draw_gameover_menu(); break;
}
return AppReturnValues::OK;
}
BaseApp::AppReturnValues app_game_falldown::btn_pressed(Api *app_api, uint gpio, unsigned long delta) {
switch (m_gamestate) {
case menu:
if (gpio == BUTTON_SELECT)
init_game();
break;
case game:
switch (gpio) {
case BUTTON_DOWN:
m_player_ball.m_pressed_left = true; break;
case BUTTON_UP:
m_player_ball.m_pressed_right = true; break;
}
break;
case gameover:
draw_gameover_menu(); break;
}
return AppReturnValues::OK;
}
BaseApp::AppReturnValues app_game_falldown::btn_released(Api *app_api, uint gpio, unsigned long delta) {
if (m_gamestate == game) {
switch (gpio) {
case BUTTON_DOWN:
m_player_ball.m_pressed_left = false; break;
case BUTTON_UP:
m_player_ball.m_pressed_right = false; break;
}
}
return AppReturnValues::OK;
}
app_game_falldown::app_game_falldown(Api *app_api) {
m_app_api = app_api;
}
app_game_falldown::~app_game_falldown() {
}
|