invaders can exit, size reduction with static fkts

This commit is contained in:
iggy 2011-08-04 20:37:02 +02:00
parent ccc8ce1395
commit b844a2b1a1
2 changed files with 55 additions and 52 deletions

View File

@ -79,3 +79,4 @@ setExtFont
getFontHeight getFontHeight
menuflags menuflags
delayms_queue_plus delayms_queue_plus
getInputWaitTimeout

View File

@ -52,33 +52,33 @@ struct gamestate {
uint8_t bunker[BUNKERS][BUNKER_WIDTH]; uint8_t bunker[BUNKERS][BUNKER_WIDTH];
} game; } game;
char key; char key;
bool highscore_set(uint32_t score, char nick[]);
uint32_t highscore_get(char nick[]);
void init_game(); static bool highscore_set(uint32_t score, char nick[]);
void init_enemy(); static uint32_t highscore_get(char nick[]);
void check_end(); static void init_game();
void move_ufo(); static void init_enemy();
void move_shot(); static void check_end();
void move_shots(); static void move_ufo();
void move_player(); static void move_shot();
void move_enemy(); static void move_shots();
void draw_score(); static void move_player();
void draw_bunker(); static void move_enemy();
void draw_player(); static void draw_score();
void draw_enemy(); static void draw_bunker();
void draw_shots(); static void draw_player();
void draw_sprite(char type, char x, char y); static void draw_enemy();
void draw_ufo(); static void draw_shots();
void screen_intro(); static void draw_sprite(char type, char x, char y);
void screen_gameover(); static void draw_ufo();
void screen_level(); static bool screen_intro();
bool check_bunker(char xpos, char ypos, int8_t shift); static bool screen_gameover();
static void screen_level();
static bool check_bunker(char xpos, char ypos, int8_t shift);
void ram(void) { void ram(void) {
//gpioSetValue (RB_LED1, CFG_LED_OFF);
//backlightInit();
while(1) { while(1) {
if (!screen_intro())
return;
screen_intro(); screen_intro();
game.rokets = 3; game.rokets = 3;
game.level = 1; game.level = 1;
@ -104,19 +104,20 @@ void ram(void) {
lcdDisplay(); lcdDisplay();
delayms(12); delayms(12);
} }
screen_gameover(); if (!screen_gameover())
}
return; return;
}
} }
void screen_intro() { static bool screen_intro() {
uint32_t highscore; uint32_t highscore;
char highnick[20]; char highnick[20];
char key=0; char key=0;
bool step = false;
while(key==0) { while(key==0) {
lcdFill(0); lcdFill(0);
font = &Font_Invaders; font = &Font_Invaders;
DoString(28,25,"ABC"); DoString(28,25,step?"ABC":"abc");
font = &Font_7x8; font = &Font_7x8;
DoString (28,40,"SPACE"); DoString (28,40,"SPACE");
DoString (18,50,"INVADERS"); DoString (18,50,"INVADERS");
@ -125,13 +126,13 @@ void screen_intro() {
DoInt(0, 0, highscore); DoInt(0, 0, highscore);
DoString (0, 9, highnick); DoString (0, 9, highnick);
lcdDisplay(); lcdDisplay();
step = !step;
delayms_queue(50); key=getInputWaitTimeout(1);
key=getInput();
} }
return !(key==BTN_LEFT);
} }
void screen_gameover() { static bool screen_gameover() {
char key =0; char key =0;
while(key==0) { while(key==0) {
lcdFill(0); lcdFill(0);
@ -143,9 +144,10 @@ void screen_gameover() {
lcdDisplay(); lcdDisplay();
key=getInputWaitTimeout(5); key=getInputWaitTimeout(5);
} }
return !(key==BTN_LEFT);
} }
void screen_level() { static void screen_level() {
lcdFill(0); lcdFill(0);
draw_score(); draw_score();
font = &Font_7x8; font = &Font_7x8;
@ -155,7 +157,7 @@ void screen_level() {
delayms_queue(500); delayms_queue(500);
} }
bool highscore_set(uint32_t score, char nick[]) { static bool highscore_set(uint32_t score, char nick[]) {
MPKT * mpkt= meshGetMessage('i'); MPKT * mpkt= meshGetMessage('i');
if(MO_TIME(mpkt->pkt)>score) if(MO_TIME(mpkt->pkt)>score)
return false; return false;
@ -165,7 +167,7 @@ bool highscore_set(uint32_t score, char nick[]) {
return true; return true;
} }
uint32_t highscore_get(char nick[]){ static uint32_t highscore_get(char nick[]){
MPKT * mpkt= meshGetMessage('i'); MPKT * mpkt= meshGetMessage('i');
strcpy(nick,(char*)MO_BODY(mpkt->pkt)); strcpy(nick,(char*)MO_BODY(mpkt->pkt));
@ -173,7 +175,7 @@ uint32_t highscore_get(char nick[]){
return MO_TIME(mpkt->pkt); return MO_TIME(mpkt->pkt);
} }
void init_game(void) { static void init_game(void) {
game.player = POS_PLAYER_X; game.player = POS_PLAYER_X;
game.shot_x = DISABLED; game.shot_x = DISABLED;
game.shot_y = 0; game.shot_y = 0;
@ -212,7 +214,7 @@ void init_game(void) {
} }
} }
void init_enemy() { static void init_enemy() {
for (int row = 0; row<ENEMY_ROWS; row++) { for (int row = 0; row<ENEMY_ROWS; row++) {
game.enemy_row_y[row] = 10 + (40/ENEMY_ROWS)*row; game.enemy_row_y[row] = 10 + (40/ENEMY_ROWS)*row;
for (int col = 0; col<ENEMY_COLUMNS; col++) { for (int col = 0; col<ENEMY_COLUMNS; col++) {
@ -221,7 +223,7 @@ void init_enemy() {
} }
} }
bool check_bunker(char xpos, char ypos, int8_t shift){ static bool check_bunker(char xpos, char ypos, int8_t shift){
for (int b=0; b<BUNKERS; b++) { for (int b=0; b<BUNKERS; b++) {
if (xpos>BUNKER_X[BUNKERS-1-b] && if (xpos>BUNKER_X[BUNKERS-1-b] &&
xpos<BUNKER_X[BUNKERS-1-b]+BUNKER_WIDTH && xpos<BUNKER_X[BUNKERS-1-b]+BUNKER_WIDTH &&
@ -240,7 +242,7 @@ bool check_bunker(char xpos, char ypos, int8_t shift){
return false; return false;
} }
void move_shot() { static void move_shot() {
//No shot, do nothing //No shot, do nothing
if(game.shot_x == DISABLED) { if(game.shot_x == DISABLED) {
return; return;
@ -286,7 +288,7 @@ void move_shot() {
void move_shots() { static void move_shots() {
for (int col = 0; col<ENEMY_COLUMNS; col++){ for (int col = 0; col<ENEMY_COLUMNS; col++){
//No shot, maybe generate //No shot, maybe generate
if (game.shots_x[col] == DISABLED) { if (game.shots_x[col] == DISABLED) {
@ -323,7 +325,7 @@ void move_shots() {
} }
} }
void move_ufo() { static void move_ufo() {
if (game.ufo == DISABLED) { if (game.ufo == DISABLED) {
if ((getRandom()%UFO_PROB)==0) { if ((getRandom()%UFO_PROB)==0) {
game.ufo = 0; game.ufo = 0;
@ -337,7 +339,7 @@ void move_ufo() {
game.ufo++; game.ufo++;
} }
void move_player() { static void move_player() {
if(gpioGetValue(RB_BTN0)==0 && game.player > 0 ){ if(gpioGetValue(RB_BTN0)==0 && game.player > 0 ){
game.player-=1; game.player-=1;
} }
@ -352,7 +354,7 @@ void move_player() {
} }
} }
void move_enemy() { static void move_enemy() {
if(game.move > 0){ if(game.move > 0){
game.move-=game.level/5+1; game.move-=game.level/5+1;
return; return;
@ -390,16 +392,16 @@ void move_enemy() {
game.move = game.alive*2-1; game.move = game.alive*2-1;
} }
void draw_player() { static void draw_player() {
draw_sprite(TYPE_PLAYER, game.player, POS_PLAYER_Y); draw_sprite(TYPE_PLAYER, game.player, POS_PLAYER_Y);
} }
void draw_ufo() { static void draw_ufo() {
if (game.ufo!=DISABLED) if (game.ufo!=DISABLED)
draw_sprite(TYPE_UFO, game.ufo, POS_UFO_Y); draw_sprite(TYPE_UFO, game.ufo, POS_UFO_Y);
} }
void draw_enemy() { static void draw_enemy() {
for (int row = 0; row<ENEMY_ROWS; row++) { for (int row = 0; row<ENEMY_ROWS; row++) {
for (int col = 0; col<ENEMY_COLUMNS; col++) { for (int col = 0; col<ENEMY_COLUMNS; col++) {
if (game.enemy_x[row][col] != DISABLED) { if (game.enemy_x[row][col] != DISABLED) {
@ -409,13 +411,13 @@ void draw_enemy() {
} }
} }
void draw_bunker() { static void draw_bunker() {
for (int b=0; b<BUNKERS; b++) { for (int b=0; b<BUNKERS; b++) {
memcpy(lcdBuffer+(RESX*1+BUNKER_X[b]),game.bunker+b,BUNKER_WIDTH); memcpy(lcdBuffer+(RESX*1+BUNKER_X[b]),game.bunker+b,BUNKER_WIDTH);
} }
} }
void draw_shots() { static void draw_shots() {
if (game.shot_x != 255) { if (game.shot_x != 255) {
for (int length=0; length<=5; length++) { for (int length=0; length<=5; length++) {
lcdSetPixel(game.shot_x, game.shot_y+length, true); lcdSetPixel(game.shot_x, game.shot_y+length, true);
@ -432,13 +434,13 @@ void draw_shots() {
} }
void draw_status() { static void draw_status() {
for (int p = 0; p<game.alive; p++){ for (int p = 0; p<game.alive; p++){
lcdSetPixel(p+1,1,true); lcdSetPixel(p+1,1,true);
} }
} }
void draw_sprite(char type, char x, char y) { static void draw_sprite(char type, char x, char y) {
font = &Font_Invaders; font = &Font_Invaders;
switch(type) { switch(type) {
case TYPE_PLAYER: case TYPE_PLAYER:
@ -459,7 +461,7 @@ void draw_sprite(char type, char x, char y) {
} }
} }
void draw_score() { static void draw_score() {
font = &Font_7x8; font = &Font_7x8;
DoInt(0,0,game.score); DoInt(0,0,game.score);
@ -469,7 +471,7 @@ void draw_score() {
} }
void check_end() { static void check_end() {
if (game.killed) { if (game.killed) {
game.rokets--; game.rokets--;
delayms_queue(500); delayms_queue(500);