From f62b5f5c02ec280c038b7e40b9e106a743c8b3f1 Mon Sep 17 00:00:00 2001 From: Sebastian Steuer Date: Wed, 15 Jun 2011 03:03:52 +0200 Subject: [PATCH] invaders basics --- modules/mandelbrot.c | 4 +- modules/spaceinvaders.c | 142 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 144 insertions(+), 2 deletions(-) create mode 100644 modules/spaceinvaders.c diff --git a/modules/mandelbrot.c b/modules/mandelbrot.c index 6e6d9a7..2fa83fc 100644 --- a/modules/mandelbrot.c +++ b/modules/mandelbrot.c @@ -57,7 +57,7 @@ void module_mandelbrot(void) { double zoom = 1; int iteration_max = 300; int x_center = 45; - int y_center= 40; + int y_center= 20; while (1) { checkISP(); lcdDisplay(0); @@ -148,7 +148,7 @@ void module_mandelbrot(void) { //rmin*=zoom; //rmax*=zoom; - zoom *= 0.995; + zoom *= 0.996; iteration_max = iteration_max*1.02; x_center = RESX/2; diff --git a/modules/spaceinvaders.c b/modules/spaceinvaders.c new file mode 100644 index 0000000..5be2525 --- /dev/null +++ b/modules/spaceinvaders.c @@ -0,0 +1,142 @@ +#include + +#include "basic/basic.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 59 +#define ENEMY_ROWS 3 +#define ENEMY_COLUMNS 6 +#define DISABLED 255 + +struct gamestate { + int player; + int shot_x, shot_y; + int enemy_x[ENEMY_ROWS][ENEMY_COLUMNS]; + int enemy_row_y[ENEMY_ROWS]; + +} game = {RESX/2-4, DISABLED, 0}; +char key; + + +void checkISP(void) { + if(gpioGetValue(RB_BTN2)==0){ + gpioSetValue (RB_LED1, CFG_LED_ON); + delayms(200); + gpioSetValue (RB_LED1, CFG_LED_OFF); + while(gpioGetValue(RB_BTN0)==0); + EnableWatchdog(1000*5); + ReinvokeISP(); + } +} + +void init_enemy() { + for (int row = 0; row= game.shot_y && game.enemy_row_y[row] < game.shot_y+8) { + for(int col = 0; col= game.enemy_x[row][col] && game.shot_x < game.enemy_x[row][col]+8) { + game.enemy_x[row][col]=DISABLED; + game.shot_x = DISABLED; + } + } + } + } + + game.shot_y -= 3; +} + +void move_player() { + if(gpioGetValue(RB_BTN0)==0 && game.player >= 0 ){ + game.player-=2; + } + + if(gpioGetValue(RB_BTN1)==0 && game.player < RESX-8){ + game.player+=2; + } + + if(gpioGetValue(RB_BTN4)==0 && game.shot_x == 255){ + game.shot_x = game.player+4; + game.shot_y = POS_PLAYER_Y; + } +} + +void draw_player() { + //draw_sprite(50, 20); + draw_sprite(game.player, POS_PLAYER_Y); +} + +void draw_enemy() { + for (int row = 0; row