From 108cf1321d20470fd0e1a74207ac484de1b1e03d Mon Sep 17 00:00:00 2001 From: Christian Kroll Date: Mon, 20 Dec 2010 22:52:39 +0000 Subject: [PATCH] Speicherschwein, Speicherschwein... wer kann das was ein Speicherschwein kann? --- games/breakout/breakout.c | 9 +++++++++ games/breakout/playfield.c | 12 ++++++------ games/breakout/playfield.h | 1 + 3 files changed, 16 insertions(+), 6 deletions(-) diff --git a/games/breakout/breakout.c b/games/breakout/breakout.c index ff11e0e..2cb6051 100644 --- a/games/breakout/breakout.c +++ b/games/breakout/breakout.c @@ -39,6 +39,13 @@ void borg_breakout_game() void borg_breakout(uint8_t demomode) { + // save pointer address just in case that the breakout demo was previously + // running so it can reentered + char (*old_playfield)[NUM_COLS][NUM_ROWS] = playfield; + // new playing field + char my_playfield[NUM_COLS][NUM_ROWS]; + playfield = &my_playfield; + uint8_t ignorescore_buffer = ignorescore; uint16_t cycles = DEMO_CYCLES; uint8_t level; @@ -99,4 +106,6 @@ void borg_breakout(uint8_t demomode) } ignorescore = ignorescore_buffer; + // restore saved pointer + playfield = old_playfield; } diff --git a/games/breakout/playfield.c b/games/breakout/playfield.c index b204b2a..52fe6f7 100644 --- a/games/breakout/playfield.c +++ b/games/breakout/playfield.c @@ -17,7 +17,7 @@ */ #include "playfield.h" -static enum game_field_t playfield[NUM_COLS][NUM_ROWS]; +char (*playfield)[NUM_COLS][NUM_ROWS]; void playfield_set (uint8_t in_x, uint8_t in_y, enum game_field_t in_field) { @@ -25,15 +25,15 @@ void playfield_set (uint8_t in_x, uint8_t in_y, enum game_field_t in_field) { return; } - playfield[in_x][in_y] = in_field; + (*playfield)[in_x][in_y] = in_field; } void brick_damage (uint8_t in_x, uint8_t in_y) { - if (playfield[in_x][in_y] >= bs || playfield[in_x][in_y] == 0) + if ((*playfield)[in_x][in_y] >= bs || (*playfield)[in_x][in_y] == 0) return; - playfield[in_x][in_y] -= 1; + (*playfield)[in_x][in_y] -= 1; score_add (1); } @@ -53,7 +53,7 @@ uint8_t check_bounce (int8_t in_x, int8_t in_y) } /* collisions with real objects */ - switch (playfield[abs(in_x)][abs(in_y)]) + switch ((*playfield)[abs(in_x)][abs(in_y)]) { case b2: case b3: @@ -119,7 +119,7 @@ void playfield_draw () { for (y=0;y