-
Notifications
You must be signed in to change notification settings - Fork 2
/
invaders.ino
118 lines (106 loc) · 3.24 KB
/
invaders.ino
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
#include <Gamebuino-Meta.h>
//----------------------------------------------------------------------
// I N V A D E R S
// coded by Yoda Zhang on Gamebuino
// ported on META by Jicehel
// V 1.0
//----------------------------------------------------------------------
//----------------------------------------------------------------------------
// define variables and constants
//----------------------------------------------------------------------------
# define Maxwhidth 80
String gamestatus;
int score;
int lives;
int gamelevel;
int shipx;
int invaderx[55];
int invadery[55];
int invaders[55];
int invaderframe[55];
int invaderanz;
int invaderctr;
int invadersound;
int checkdir;
int nextxdir;
int nextydir;
int invaderxr;
int invaderyr;
int invadershotx[4];
int invadershoty[4];
int invadershotframe;
int invadershots;
int invadershottimer;
int bunkers[4];
int shotx;
int shoty;
int checkl;
int checkr;
int checkt;
int checkb;
int yeahtimer;
int infoshow;
int deadcounter;
int saucerx;
int saucerdir;
int saucers;
int saucertimer;
int saucerwait;
int delayBip;
//----------------------------------------------------------------------------
// define images & sounds
//----------------------------------------------------------------------------
extern const byte gamelogo[];
extern const byte invader[8][7];
extern const byte playership[3][6];
extern const byte bunker[5][7];
extern const byte bomb[2][6];
extern const byte saucer[2][10];
extern const int soundfx[8][8];
/*
//----------------------------------------------------------------------------
// setup
//----------------------------------------------------------------------------
*/
void setup(){
gb.begin();
gb.setFrameRate(30);
initHighscore();
gb.pickRandomSeed();
gamestatus="title";
}
//----------------------------------------------------------------------------
// loop
//----------------------------------------------------------------------------
void loop(){
if(gb.update()){
if (gamestatus=="newgame"){ newgame(); } // new game
if (gamestatus=="newlevel"){ newlevel(); } // new level
if (gamestatus=="running"){ // game running loop
gb.display.clear();
showscore();
checkbuttons(); // check buttons and move playership
drawplayership(); // draw player ship
drawplayershot(); // move + draw player shoot
invaderlogic(); // invader logic
drawinvaders(); // draw invaders
invadershot(); // invaders shoot
nextlevelcheck(); // next level?
drawbunkers(); // draw bunkers & check collission with player shot
saucerappears(); // saucer appears?
movesaucer(); // move saucer
drawsaucer(); // draw saucer & remove if hit
showscore(); // show lives, score, level
} // end of: gamestatus = running
if (gamestatus=="title") { showtitle(); } // title
if (gamestatus=="gameover") { // game over
gb.display.clear();
for (int i = 0; i < 40 ; i++) {
if (invaders[i]!=-1) {
gb.display.drawBitmap(invaderx[i],invadery[i],invader[invaders[i]+invaderframe[i]]);
}
}
saveHighscore(score);
}
} // end of update
} // end of loop