Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 58 lines (47 sloc) 1.182 kB
b115495 @beerriot first working version
authored
1 // blockgame
2 // for NerdKits with ATmega168
65cdebf @beerriot MIT license
authored
3 // copyright 2011 Bryan Fink
4 // license: see LICENSE.txt
b115495 @beerriot first working version
authored
5
63ca707 @beerriot slide blocks into spaces and fill at the right
authored
6 #include <stdlib.h>
1549513 @beerriot break hardware-specific functions into separate files
authored
7 #include <inttypes.h>
b115495 @beerriot first working version
authored
8
9 #include <avr/pgmspace.h>
1549513 @beerriot break hardware-specific functions into separate files
authored
10 #include <avr/interrupt.h>
b115495 @beerriot first working version
authored
11
1549513 @beerriot break hardware-specific functions into separate files
authored
12 #include "lcd.h" //add nerdkits-provided library
b115495 @beerriot first working version
authored
13
538eb0d @beerriot a little namespacing to make things easier to find
authored
14 #include "nkbuttons.h"
1549513 @beerriot break hardware-specific functions into separate files
authored
15 #include "nkrand.h"
16 #include "nklcd.h"
538eb0d @beerriot a little namespacing to make things easier to find
authored
17 #include "nktimer.h"
c84be08 @beerriot put the display and MCU to sleep after a while of inactivity
authored
18 #include "nksleep.h"
b115495 @beerriot first working version
authored
19
afd88ab @beerriot break startup menu into bgmenu files
authored
20 #include "bggame.h"
21 #include "bgmenu.h"
579ebc8 @beerriot break highscore logic/screen into separate file
authored
22 #include "bghighscore.h"
23
6138b60 @beerriot break game stages out of main loop
authored
24 int main() {
db948d6 @beerriot typedef-ing the structs, for a bit of syntax economy
authored
25 game_t game;
c84be08 @beerriot put the display and MCU to sleep after a while of inactivity
authored
26 // idle/sleep timer
5e7414a @beerriot be explicit about signs and sizes of integer variables
authored
27 int8_t idle = 0;
bc3a7d4 @beerriot finally back to a non-global game state
authored
28
6138b60 @beerriot break game stages out of main loop
authored
29 // the playing board
bff130a @beerriot make game width/height/variety variable
authored
30 game.width = MAX_WIDTH;
31 game.height = MAX_HEIGHT;
32 game.variety = 5;
6138b60 @beerriot break game stages out of main loop
authored
33
538eb0d @beerriot a little namespacing to make things easier to find
authored
34 nklcd_init();
35 nkbuttons_init();
36 nktimer_init(60);
37 srand(nkrand_seed());
579ebc8 @beerriot break highscore logic/screen into separate file
authored
38 bghighscore_init();
6138b60 @beerriot break game stages out of main loop
authored
39 sei(); //enable interrupts
40
41 while(1) {
54ec849 @beerriot show highscores after 10sec of inactivity on menu
authored
42 if (bgmenu_display(&game)) {
c84be08 @beerriot put the display and MCU to sleep after a while of inactivity
authored
43 idle = 0;
54ec849 @beerriot show highscores after 10sec of inactivity on menu
authored
44 bggame_play(&game);
45 bggame_over(game.score);
46 bghighscore_maybe(game.score);
c84be08 @beerriot put the display and MCU to sleep after a while of inactivity
authored
47 } else if(++idle > 4) {
48 // go to sleep after cycling menu<->highscore
49 // without a game several times
50 idle = 0;
51 nksleep_standby();
54ec849 @beerriot show highscores after 10sec of inactivity on menu
authored
52 }
c33d7ce @beerriot get all mode transistions in one place
authored
53 bghighscore_screen();
6138b60 @beerriot break game stages out of main loop
authored
54 }
7413239 @beerriot end-of-game checking
authored
55
b115495 @beerriot first working version
authored
56 return 0;
57 }
Something went wrong with that request. Please try again.