invaders cleanup, no more warnings

This commit is contained in:
iggy 2011-08-03 18:01:16 +02:00
parent 4f5ec4e8fc
commit 3bb82a2676
1 changed files with 18 additions and 56 deletions

View File

@ -1,15 +1,13 @@
#include <sysinit.h>
#include <string.h>
#include "basic/basic.h"
#include "basic/random.h"
#include "lcd/render.h"
#include "lcd/display.h"
#include "lcd/allfonts.h"
//void ReinvokeISP(void);
//void EnableWatchdog(uint32_t ms);
//void delayms(uint32_t ms);
/**************************************************************************/
#define POS_PLAYER_Y 60
#define POS_PLAYER_X RESX/2-3
@ -20,11 +18,11 @@
#define UFO_PROB 1024
#define TYPE_PLAYER 1
#define TYPE_PLAYER 1
#define TYPE_ENEMY_A 3
#define TYPE_ENEMY_B 2
#define TYPE_ENEMY_C 4
#define TYPE_UFO 5
#define TYPE_UFO 5
#define BUNKERS 3
#define BUNKER_WIDTH 10
@ -52,16 +50,19 @@ struct gamestate {
char key;
void init_game();
void init_enemy();
void check_end();
void move_ufo();
void move_shot();
void move_shots();
void move_player();
void move_enemay();
void move_enemy();
void draw_score();
void draw_bunker();
void draw_player();
void draw_enemy();
void draw_shots();
void draw_sprite(char type, char x, char y);
void draw_ufo();
void screen_intro();
void screen_gameover();
@ -163,7 +164,7 @@ void init_game(void) {
game.score = 0;
init_enemy();
for (char col=0; col<ENEMY_COLUMNS; col++){
for (int col=0; col<ENEMY_COLUMNS; col++){
game.shots_x[col] = DISABLED;
}
@ -223,21 +224,8 @@ void move_shot() {
game.shot_x = DISABLED;
return;
}
//check for collision with bunker
// for (int b=0; b<BUNKERS; b++) {
// if (game.shot_x>BUNKER_X[BUNKERS-1-b] &&
// game.shot_x<BUNKER_X[BUNKERS-1-b]+BUNKER_WIDTH &&
// game.shot_y<RESY-8 &&
// game.shot_y>RESY-16) {
// int offset = BUNKER_WIDTH - (game.shot_x-BUNKER_X[BUNKERS-1-b]);
// if (game.bunker[b][offset]!=0) {
// game.bunker[b][offset]&=game.bunker[b][offset]<<1;
// game.shot_x=DISABLED;
// }
// }
// }
if (check_bunker(game.shot_x,game.shot_y-5,1 ))
if (check_bunker(game.shot_x,game.shot_y-5,1 ))
game.shot_x=DISABLED;
//check for collision with enemy, kill enemy if
@ -254,6 +242,7 @@ void move_shot() {
}
}
}
//check for collision with ufo
if (game.ufo != DISABLED &&
game.shot_x>game.ufo &&
@ -271,10 +260,10 @@ void move_shot() {
void move_shots() {
for (char col = 0; col<ENEMY_COLUMNS; col++){
for (int col = 0; col<ENEMY_COLUMNS; col++){
//No shot, maybe generate
if (game.shots_x[col] == DISABLED) {
for (char row = 0; row<ENEMY_ROWS; row++) {
for (int row = 0; row<ENEMY_ROWS; row++) {
if (game.enemy_x[row][col] != DISABLED) {
if(getRandom()%(game.alive*20/((game.level/3)+1))==0) {
game.shots_x[col] = game.enemy_x[row][col]+5;
@ -294,20 +283,7 @@ void move_shots() {
if (check_bunker(game.shots_x[col],game.shots_y[col],-1))
game.shots_x[col]=DISABLED;
// for (int b=0; b<BUNKERS; b++) {
// if (game.shots_x[col]>BUNKER_X[BUNKERS-1-b] &&
// game.shots_x[col]<BUNKER_X[BUNKERS-1-b]+BUNKER_WIDTH &&
// game.shots_y[col]<RESY-8 &&
// game.shots_y[col]>RESY-16) {
// int offset = BUNKER_WIDTH - (game.shots_x[col]-BUNKER_X[BUNKERS-1-b])-1;
// if (game.bunker[b][offset]!=0) {
// game.bunker[b][offset]&=game.bunker[b][offset]>>1;
// game.shots_x[col]=DISABLED;
// }
// }
// }
//check for collision with player
//check for collision with player
if (game.shots_y[col] >= RESY-13 &&
game.shots_x[col] > game.player+1 &&
game.shots_x[col] < game.player+6) {
@ -369,25 +345,12 @@ void move_enemy() {
game.killed = true;
}
check_bunker(pos,game.enemy_row_y[row]+8,-2);
//check for collision with bunker, dirty
// for (int b=0; b<BUNKERS; b++) {
// if (pos>=BUNKER_X[BUNKERS-1-b] &&
// pos<=BUNKER_X[BUNKERS-1-b]+BUNKER_WIDTH &&
// game.enemy_row_y[row]+8<RESY-8 &&
// game.enemy_row_y[row]+8>RESY-16) {
// int offset = BUNKER_WIDTH - (pos-BUNKER_X[BUNKERS-1-b]);
// if (game.bunker[b][offset]!=0) {
// game.bunker[b][offset]&=game.bunker[b][offset]>>2;
// }
// }
// }
//Are we at the beginning or end? Direction change
if((pos <=0 && game.direction != 1) ||
(pos >=RESX-10 && game.direction == 1)){
game.direction = (game.direction==1)?-1:1;
for (char r = 0; r<ENEMY_ROWS; r++) {
for (int r = 0; r<ENEMY_ROWS; r++) {
game.enemy_row_y[r]+=game.level>=23?4:2;
}
return;
@ -401,7 +364,6 @@ void move_enemy() {
}
void draw_player() {
//draw_sprite(50, 20);
draw_sprite(TYPE_PLAYER, game.player, POS_PLAYER_Y);
}
@ -433,7 +395,7 @@ void draw_shots() {
}
}
for (char col = 0; col < ENEMY_COLUMNS; col++) {
for (int col = 0; col < ENEMY_COLUMNS; col++) {
if (game.shots_x[col] != DISABLED) {
for (int length=0; length<=5; length++) {
lcdSetPixel(game.shots_x[col], game.shots_y[col]+length,true);