added logo splash screen
[gbajam22] / src / game.c
1 #include <string.h>
2 #include "gba.h"
3 #include "game.h"
4
5 struct screen *init_logo_screen(void);
6 struct screen *init_menu_screen(void);
7 struct screen *init_game_screen(void);
8
9 struct screen *curscr;
10
11 #define MAX_SCR 4
12 static struct screen *scrlist[MAX_SCR];
13 static int num_scr;
14
15 int init_screens(void)
16 {
17         if(!(scrlist[num_scr++] = init_logo_screen())) {
18                 return -1;
19         }
20         if(!(scrlist[num_scr++] = init_menu_screen())) {
21                 return -1;
22         }
23         if(!(scrlist[num_scr++] = init_game_screen())) {
24                 return -1;
25         }
26         return 0;
27 }
28
29 int change_screen(struct screen *scr)
30 {
31         if(!scr) return -1;
32
33         mask(INTR_VBLANK);
34
35         if(curscr && curscr->stop) {
36                 curscr->stop();
37         }
38         if(scr->start && scr->start() == -1) {
39                 return -1;
40         }
41         curscr = scr;
42
43         unmask(INTR_VBLANK);
44         return 0;
45 }
46
47 struct screen *find_screen(const char *name)
48 {
49         int i;
50         for(i=0; i<num_scr; i++) {
51                 if(strcmp(scrlist[i]->name, name) == 0) {
52                         return scrlist[i];
53                 }
54         }
55         return 0;
56 }