From 96939cf72d2b2c584a4fcf2279ebcce031e1d3b5 Mon Sep 17 00:00:00 2001 From: Christian Kroll Date: Fri, 9 Apr 2010 20:41:23 +0000 Subject: [PATCH] added breakout demo animation --- animations/Makefile | 3 +++ animations/breakout_demo.c | 6 ++++++ animations/breakout_demo.h | 6 ++++++ config.in | 1 + display_loop.c | 9 +++++++- games/breakout/breakout.c | 42 ++++++++++++++++++++++++++++++++------ games/breakout/breakout.h | 28 +++++++++++++++++++++++++ games/breakout/config.h | 2 ++ games/breakout/rebound.c | 28 +++++++++++++++++-------- games/breakout/rebound.h | 2 +- games/breakout/score.c | 4 +++- games/breakout/score.h | 1 + 12 files changed, 115 insertions(+), 17 deletions(-) create mode 100644 animations/breakout_demo.c create mode 100644 animations/breakout_demo.h create mode 100644 games/breakout/breakout.h diff --git a/animations/Makefile b/animations/Makefile index c3ef712..0f8392d 100644 --- a/animations/Makefile +++ b/animations/Makefile @@ -25,5 +25,8 @@ ifeq ($(ANIMATION_GAMEOFLIFE),y) SRC += gameoflife.c endif +ifeq ($(ANIMATION_BREAKOUT),y) + SRC += breakout_demo.c +endif include $(TOPDIR)/rules.mk diff --git a/animations/breakout_demo.c b/animations/breakout_demo.c new file mode 100644 index 0000000..4e41a6f --- /dev/null +++ b/animations/breakout_demo.c @@ -0,0 +1,6 @@ +#include "../games/breakout/breakout.h" + +void breakout_demo() +{ + borg_breakout(1); +} diff --git a/animations/breakout_demo.h b/animations/breakout_demo.h new file mode 100644 index 0000000..325c914 --- /dev/null +++ b/animations/breakout_demo.h @@ -0,0 +1,6 @@ +#ifndef BREAKOUT_DEMO_H_ +#define BREAKOUT_DEMO_H_ + +void breakout_demo(); + +#endif /* BREAKOUT_DEMO_H_ */ diff --git a/config.in b/config.in index cad3a79..93489f7 100644 --- a/config.in +++ b/config.in @@ -74,6 +74,7 @@ comment "Animations" dep_bool "Stonefly" ANIMATION_STONEFLY $RANDOM_SUPPORT $GAME_TETRIS_CORE dep_bool "Flying Dots" ANIMATION_FLYINGDOTS $RANDOM_SUPPORT dep_bool "Game of Life" ANIMATION_GAMEOFLIFE $RANDOM_SUPPORT + dep_bool "Breakout Demo" ANIMATION_BREAKOUT $GAME_BREAKOUT bool "M Herweg" ANIMATION_MHERWEG comment "Special Animations" diff --git a/display_loop.c b/display_loop.c index ba408fd..14fbb8c 100644 --- a/display_loop.c +++ b/display_loop.c @@ -9,6 +9,7 @@ #include "animations/gameoflife.h" #include "animations/stonefly.h" #include "animations/flyingdots.h" +#include "animations/breakout_demo.h" #include "borg_hw/borg_hw.h" #include "can/borg_can.h" #include "random/prng.h" @@ -117,8 +118,14 @@ void display_loop(){ break; #endif -#ifdef ANIMATION_MHERWEG +#ifdef ANIMATION_BREAKOUT case 12: + breakout_demo(); + break; +#endif + +#ifdef ANIMATION_MHERWEG + case 13: lines1(); dots1(); movinglines(); diff --git a/games/breakout/breakout.c b/games/breakout/breakout.c index 13f18dc..7346f27 100644 --- a/games/breakout/breakout.c +++ b/games/breakout/breakout.c @@ -17,7 +17,7 @@ */ #include "common.h" -static void borg_breakout(); +#include "breakout.h" #ifdef MENU_SUPPORT //static uint8_t breakout_icon[8] PROGMEM = {0x03, 0x03, 0x00, 0x00, 0xff, 0xff, 0x00, 0x00}; /* our Icon */ @@ -25,14 +25,34 @@ static uint8_t breakout_icon[8] PROGMEM = {0x00, 0x18, 0x18, 0x00, 0x00, 0xff, 0 game_descriptor_t breakout_game_descriptor __attribute__((section(".game_descriptors"))) = { - &borg_breakout, + &borg_breakout_game, breakout_icon }; #endif -void borg_breakout() + +void borg_breakout_game() { - uint8_t level = 0; + borg_breakout(0); +} + + +void borg_breakout(uint8_t demomode) +{ + uint8_t ignorescore_buffer = ignorescore; + uint16_t cycles = DEMO_CYCLES; + uint8_t level; + if (demomode) + { + level = 4; + ignorescore = 1; + } + else + { + level = 0; + ignorescore = 0; + } + ball_t balls[1]; /* spawn a ball in the middle bottom of the field, let it move upwards with random speed & direction */ @@ -41,10 +61,15 @@ void borg_breakout() level_init(level); rebound_init(); - while (23) + while (cycles != 0) { wait(50); - rebound_tick(); + + if (demomode) + rebound_tick(&balls[0]); + else + rebound_tick(NULL); + ball_think(&(balls[0])); playfield_draw(); ball_draw(&(balls[0])); @@ -63,5 +88,10 @@ void borg_breakout() level_init(level); rebound_init(); } + + if (demomode) + --cycles; } + + ignorescore = ignorescore_buffer; } diff --git a/games/breakout/breakout.h b/games/breakout/breakout.h new file mode 100644 index 0000000..9a0acd2 --- /dev/null +++ b/games/breakout/breakout.h @@ -0,0 +1,28 @@ +/* + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2, as published by the Free Software Foundation. + * + * This program is distributed in the hope it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along with + * this program; if not, write to the Free Software Foundation, Inc., 59 Temple + * Place - Suite 330, Boston, MA 02111-1307 USA. + * + * Author & Copyright (C) 2010: Soeren Heisrath (forename@surename.org) + * + */ + +#ifndef BREAKOUT_H_ +#define BREAKOUT_H_ + +#include + +void borg_breakout_game(); + +void borg_breakout(uint8_t demomode); + +#endif /* BREAKOUT_H_ */ diff --git a/games/breakout/config.h b/games/breakout/config.h index d375a6f..e4cd829 100644 --- a/games/breakout/config.h +++ b/games/breakout/config.h @@ -30,5 +30,7 @@ static const int8_t rebound_reflection[6][2] = { 72, -20} /* offside right */ }; +#define DEMO_CYCLES 1200; + #endif /* CONFIG_H */ diff --git a/games/breakout/rebound.c b/games/breakout/rebound.c index 213e760..40cf00f 100644 --- a/games/breakout/rebound.c +++ b/games/breakout/rebound.c @@ -54,18 +54,30 @@ void rebound_draw () printf("rpos: %i\n", rbpos); } -void rebound_tick() +void rebound_tick(ball_t *ball) { - /* directions are inverted (JOYISLEFT means RIGHT) */ - if (JOYISRIGHT && rbpos) + if (ball != NULL) { - rbpos--; + rbpos = (uint8_t) abs(ball->x / 256); + if (rbpos < 0) + rbpos = 0; + if (rbpos > (NUM_COLS - REBOUND_SIZE)) + rbpos = NUM_COLS - REBOUND_SIZE; rebound_draw(); } - - if (JOYISLEFT && rbpos < (NUM_COLS - (REBOUND_SIZE))) + else { - rbpos++; - rebound_draw(); + /* directions are inverted (JOYISLEFT means RIGHT) */ + if (JOYISRIGHT && rbpos) + { + rbpos--; + rebound_draw(); + } + + if (JOYISLEFT && rbpos < (NUM_COLS - (REBOUND_SIZE))) + { + rbpos++; + rebound_draw(); + } } } diff --git a/games/breakout/rebound.h b/games/breakout/rebound.h index cd8f45c..10c39dd 100644 --- a/games/breakout/rebound.h +++ b/games/breakout/rebound.h @@ -20,7 +20,7 @@ #ifndef REBOUND_H #define REBOUND_H void rebound_init(); -void rebound_tick(); +void rebound_tick(ball_t *ball); void rebound_draw(); uint8_t rebound_getpos(); void rebound_reflect(ball_t *b, int8_t in_x); diff --git a/games/breakout/score.c b/games/breakout/score.c index 01033f9..a88a75c 100644 --- a/games/breakout/score.c +++ b/games/breakout/score.c @@ -17,9 +17,11 @@ */ #include "score.h" static uint16_t score = 0; + void score_add (uint8_t in_score) { - score += in_score; + if (!ignorescore) + score += in_score; } uint16_t score_get() diff --git a/games/breakout/score.h b/games/breakout/score.h index 79bd767..73de979 100644 --- a/games/breakout/score.h +++ b/games/breakout/score.h @@ -20,6 +20,7 @@ #ifndef SCORE_H #define SCORE_H +uint8_t ignorescore; void score_add(uint8_t); uint16_t score_get();