EasyManua.ls Logo

Arduino Pro Mini

Arduino Pro Mini
311 pages
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Loading...
if (z_button) {
-
init_game();
20
state = RUNNING;
-
}
-
}
-
-
void game_over() {
25
tv.clear_screen();
-
tv.select_font(font8x8);
-
tv.printPGM(28, 38, PSTR("Game Over"));
-
int x = (WIDTH - 7 * 8) / 2;
-
if (hits > 9)
30
x = (WIDTH - 8 * 8) / 2;
-
tv.printPGM(x, 50, PSTR("Hits: "));
-
tv.print(x + 6 * 8, 50, hits);
-
if (z_button) {
-
state = STARTING;
35
z_button = false;
-
delay(200);
-
}
-
}
-
40
void update_game() {
-
tv.clear_screen();
-
tv.draw_circle(target_x, target_y, target_r, WHITE);
-
move_crosshairs();
-
draw_crosshairs();
45
check_target();
-
if (target_count == MAX_TARGET + 1) {
-
state = DONE;
-
z_button = false;
-
delay(200);
50
}
-
}
-
The
intro
,
start_game
, and
game_over
functions are very similar. They print a
message to the screen, then they wait for a Z button press. If the Z button
was pressed, they move to the next state. Before they move to the next state,
they set
z_button
to false and wait for 200 milliseconds. This is necessary to
debounce the Z button.
All three functions use yet another TVout method. Look at line 3, for example.
Here we use TVouts
printPGM
method. It works like the regular
print
method,
but it reads the string to be output from the Arduinos flash memory and not
from its precious SRAM. For applications that display a lot of constant mes-
sages, this can save a lot of memory.
report erratum discuss
Creating Your Own Video Game 159
www.it-ebooks.info

Table of Contents

Related product manuals