From 68dee062859e5af6ffedd7d675b57d49fdbbfae0 Mon Sep 17 00:00:00 2001 From: soeren Date: Thu, 21 Jan 2010 21:26:30 +0000 Subject: [PATCH] nu aber... --- games/breakout/Makefile | 10 ++++++++++ games/breakout/ball.c | 18 +++++++----------- games/breakout/ball.h | 4 +--- games/breakout/breakout.c | 6 ++---- games/breakout/common.h | 4 +--- games/breakout/config.h | 12 ------------ games/breakout/messages.c | 5 ++--- games/breakout/messages.h | 1 + games/breakout/playfield.c | 4 +--- games/breakout/playfield.h | 2 +- games/breakout/rebound.c | 14 ++++++++++++-- games/breakout/rebound.h | 10 ++++++---- 12 files changed, 44 insertions(+), 46 deletions(-) create mode 100644 games/breakout/Makefile diff --git a/games/breakout/Makefile b/games/breakout/Makefile new file mode 100644 index 0000000..c5dae36 --- /dev/null +++ b/games/breakout/Makefile @@ -0,0 +1,10 @@ +TARGET = +TOPDIR = ../.. + +include $(TOPDIR)/defaults.mk + +ifeq ($(GAME_BREAKOUT),y) + SRC = breakout.c playfield.c rebound.c score.c level.c ball.c messages.c +endif + +include $(TOPDIR)/rules.mk diff --git a/games/breakout/ball.c b/games/breakout/ball.c index 1a79cd0..6846493 100644 --- a/games/breakout/ball.c +++ b/games/breakout/ball.c @@ -75,6 +75,7 @@ void ball_think (ball_t *b) ball_die (b); bounce = check_bounce (proj_x, b->y / 256); + if (bounce & BOUNCE_UNDEF) bounce = (BOUNCE_X | bounce) & (BOUNCE_X | BOUNCE_Y); @@ -98,7 +99,7 @@ void ball_think (ball_t *b) #if BOUNCE_SLOWDOWN if (bounce & BOUNCE_BRICK) { - if (b->dir_y < -BALL_MINSPEED) + if (b->dir_y < - BALL_MINSPEED) { b->dir_y += BOUNCE_SLOWDOWN; } else if (b->dir_y > BALL_MINSPEED) @@ -106,7 +107,7 @@ void ball_think (ball_t *b) b->dir_y -= BOUNCE_SLOWDOWN; } - if (b->dir_x < -BALL_MINSPEED) + if (b->dir_x < - BALL_MINSPEED) { b->dir_x += BOUNCE_SLOWDOWN; } else if (b->dir_y > BALL_MINSPEED) @@ -124,23 +125,18 @@ void ball_think (ball_t *b) if (b->dir_x > BALL_MAXSPEED) b->dir_x = BALL_MAXSPEED; - if (b->dir_x < - BALL_MAXSPEED) - b->dir_x = - BALL_MAXSPEED; + if (b->dir_x < -BALL_MAXSPEED) + b->dir_x = -BALL_MAXSPEED; if (b->dir_y > BALL_MAXSPEED) b->dir_y = BALL_MAXSPEED; - if (b->dir_y < - BALL_MAXSPEED) - b->dir_y = - BALL_MAXSPEED; + if (b->dir_y < -BALL_MAXSPEED) + b->dir_y = -BALL_MAXSPEED; b->y += b->dir_y; b->x += b->dir_x; - - if (!b->dir_x || !b->dir_y) - { - printf("Ball stopped!\n"); - } } void ball_die (ball_t *in_b) diff --git a/games/breakout/ball.h b/games/breakout/ball.h index 2193317..31727fd 100644 --- a/games/breakout/ball.h +++ b/games/breakout/ball.h @@ -15,13 +15,11 @@ * Author & Copyright (C) 2010: Soeren Heisrath (forename@surename.org) * */ +#include "common.h" #ifndef BALL_H #define BALL_H -#include -#include "common.h" - typedef struct { diff --git a/games/breakout/breakout.c b/games/breakout/breakout.c index 31afa4d..aa9405c 100644 --- a/games/breakout/breakout.c +++ b/games/breakout/breakout.c @@ -16,9 +16,8 @@ * */ -#include #include "common.h" -void borg_breakout(); +static void borg_breakout(); #ifdef MENU_SUPPORT //static uint8_t breakout_icon[8] PROGMEM = {0x03, 0x03, 0x00, 0x00, 0xff, 0xff, 0x00, 0x00}; /* our Icon */ @@ -33,7 +32,7 @@ game_descriptor_t breakout_game_descriptor __attribute__((section(".game_descrip void borg_breakout() { - uint8_t rungame = 1, num_balls = 1, level = 0; + uint8_t level = 0; ball_t balls[1]; /* spawn a ball in the middle bottom of the field, let it move upwards with random speed & direction */ @@ -57,7 +56,6 @@ void borg_breakout() if (!level_getscorediff()) { - printf("lvl done\n"); level++; /* respawn ball at rebound position */ ball_spawn_default (&(balls[0])); diff --git a/games/breakout/common.h b/games/breakout/common.h index f4940b3..45153eb 100644 --- a/games/breakout/common.h +++ b/games/breakout/common.h @@ -31,12 +31,10 @@ #include "../../menu/menu.h" #include "../../pixel.h" #include "config.h" -#include "playfield.h" #include "ball.h" +#include "playfield.h" #include "score.h" #include "level.h" #include "rebound.h" #include "messages.h" - -#define MAX(a,b) (a > b) ? a : b #endif /* COMMON_H */ diff --git a/games/breakout/config.h b/games/breakout/config.h index f30b7cf..a14076e 100644 --- a/games/breakout/config.h +++ b/games/breakout/config.h @@ -13,18 +13,6 @@ /* rebound size */ #define REBOUND_SIZE 4 -/* rebound reflection: values to add to the vector at rebound field n - * note: directions are inverted - */ -static int8_t rebound_reflection[6][2] = -{ - {-54,-20}, /* offside */ - {-32,-12}, - {-16, -8}, /* side ... middle */ - {16, -8}, - {32, -12}, - {54, -20} -}; /* "color" of the rebound */ #define REBOUND_COLOR 2 diff --git a/games/breakout/messages.c b/games/breakout/messages.c index ca08818..d3e5793 100644 --- a/games/breakout/messages.c +++ b/games/breakout/messages.c @@ -21,7 +21,7 @@ void print_ballsleft (ball_t *in_b) { #ifdef SCROLLTEXT_SUPPORT - uint8_t txt[20]; + char txt[20]; snprintf (txt, sizeof(txt), "strength); scrolltext(txt); #endif @@ -30,9 +30,8 @@ void print_ballsleft (ball_t *in_b) void print_score () { #ifdef SCROLLTEXT_SUPPORT - uint8_t txt[32]; + char txt[32]; snprintf (txt, sizeof(txt), "= bs || playfield[in_x][in_y] == 0) return; diff --git a/games/breakout/playfield.h b/games/breakout/playfield.h index 53b2354..5ce1092 100644 --- a/games/breakout/playfield.h +++ b/games/breakout/playfield.h @@ -16,9 +16,9 @@ * */ +#include "common.h" #ifndef PLAYFIELD_H #define PLAYFIELD_H -#include "common.h" #define BOUNCE_NONE 0x00 #define BOUNCE_X 0x01 diff --git a/games/breakout/rebound.c b/games/breakout/rebound.c index 365aac7..654090b 100644 --- a/games/breakout/rebound.c +++ b/games/breakout/rebound.c @@ -17,6 +17,18 @@ */ #include "rebound.h" +/* rebound reflection: values to add to the vector at rebound field n + */ +const int8_t rebound_reflection[6][2] = +{ + {-54, -20}, /* offside */ + {-32, -12}, /* left */ + {-16, -8}, /* center */ + { 16, -8}, + { 32, -12}, + { 54, -20} +}; + static uint8_t rbpos; void rebound_reflect (ball_t *b, int8_t in_x) @@ -24,8 +36,6 @@ void rebound_reflect (ball_t *b, int8_t in_x) uint8_t tmpidx; tmpidx = (in_x - rbpos) +1; - - printf("bounce idx %i\n", tmpidx); b->dir_x += rebound_reflection[tmpidx][0]; b->dir_y += rebound_reflection[tmpidx][1]; diff --git a/games/breakout/rebound.h b/games/breakout/rebound.h index 627085a..cd8f45c 100644 --- a/games/breakout/rebound.h +++ b/games/breakout/rebound.h @@ -15,11 +15,13 @@ * Author & Copyright (C) 2010: Soeren Heisrath (forename@surename.org) * */ +#include "common.h" + #ifndef REBOUND_H #define REBOUND_H -#include "common.h" void rebound_init(); void rebound_tick(); -uint8_t rebound_getpos (); -void rebound_reflect (ball_t *b, int8_t in_x); -#endif +void rebound_draw(); +uint8_t rebound_getpos(); +void rebound_reflect(ball_t *b, int8_t in_x); +#endif /* REBOUND_H */