238 bytes this time

This commit is contained in:
Christian Kroll 2011-02-25 19:54:05 +00:00
parent 9c6a778871
commit cd2f02f39a
10 changed files with 110 additions and 105 deletions

View File

@ -18,9 +18,30 @@
#include "ball.h" #include "ball.h"
/* internal functions */
static void ball_spawn (ball_t *in_ball, uint16_t in_x, uint16_t in_y, int16_t in_dir_x, int16_t in_dir_y)
{
in_ball->x = in_x;
in_ball->y = in_y;
in_ball->dir_x = in_dir_x;
in_ball->dir_y = in_dir_y;
}
static void ball_die (ball_t *in_b)
{
in_b->strength--;
/* respawn ball with random direction */
if (in_b->strength)
{
print_ballsleft(in_b);
ball_spawn_default (in_b);
}
}
/* modify a vecotor according to given type of bouncing */ /* modify a vecotor according to given type of bouncing */
void bounce_rand_vector (ball_t *in_b, uint8_t in_bouncetype); static void bounce_rand_vector (ball_t *in_b, uint8_t in_bouncetype)
void bounce_rand_vector (ball_t *in_b, uint8_t in_bouncetype)
{ {
uint8_t rval = random8(); uint8_t rval = random8();
@ -57,6 +78,9 @@ void bounce_rand_vector (ball_t *in_b, uint8_t in_bouncetype)
in_b->dir_y = 217; in_b->dir_y = 217;
} }
/* interface functions */
void ball_think (ball_t *b) void ball_think (ball_t *b)
{ {
int8_t proj_x, proj_y, bounce, tmp; int8_t proj_x, proj_y, bounce, tmp;
@ -141,18 +165,6 @@ void ball_think (ball_t *b)
b->y += b->dir_y; b->y += b->dir_y;
b->x += b->dir_x; b->x += b->dir_x;
} }
void ball_die (ball_t *in_b)
{
in_b->strength--;
/* respawn ball with random direction */
if (in_b->strength)
{
print_ballsleft(in_b);
ball_spawn_default (in_b);
}
}
void ball_draw (ball_t *b) void ball_draw (ball_t *b)
{ {
@ -163,14 +175,6 @@ void ball_draw (ball_t *b)
setpixel (p, 3); setpixel (p, 3);
} }
void ball_spawn (ball_t *in_ball, uint16_t in_x, uint16_t in_y, int16_t in_dir_x, int16_t in_dir_y)
{
in_ball->x = in_x;
in_ball->y = in_y;
in_ball->dir_x = in_dir_x;
in_ball->dir_y = in_dir_y;
}
void ball_spawn_default (ball_t *in_b) void ball_spawn_default (ball_t *in_b)
{ {
int16_t xdir; int16_t xdir;

View File

@ -30,15 +30,10 @@ typedef struct
uint8_t strength; uint8_t strength;
} ball_t; } ball_t;
void ball_spawn (ball_t *in_ball, uint16_t in_x, uint16_t in_y, int16_t in_dir_x, int16_t in_dir_y);
/* @description Called once per game tick. Move the ball further along it's vector. /* @description Called once per game tick. Move the ball further along it's vector.
*/ */
void ball_think (ball_t *in_ball); void ball_think (ball_t *in_ball);
void ball_die (ball_t *in_b);
void ball_draw (ball_t *); void ball_draw (ball_t *);
void ball_spawn_default (ball_t *in_b); void ball_spawn_default (ball_t *in_b);

View File

@ -20,9 +20,10 @@
static uint16_t maxscore; static uint16_t maxscore;
/* internal functions */
/* real level definition */ /* real level definition */
game_field_t level_field (uint8_t in_x, uint8_t in_y, uint8_t in_lvl); static game_field_t level_field (uint8_t in_x, uint8_t in_y, uint8_t in_lvl)
game_field_t level_field (uint8_t in_x, uint8_t in_y, uint8_t in_lvl)
{ {
switch (in_lvl) switch (in_lvl)
{ {
@ -79,6 +80,8 @@ game_field_t level_field (uint8_t in_x, uint8_t in_y, uint8_t in_lvl)
} }
} }
/* interface functions */
void level_init (uint8_t in_levelnum) void level_init (uint8_t in_levelnum)
{ {
uint8_t x,y; uint8_t x,y;

View File

@ -19,6 +19,52 @@
#include "playfield.h" #include "playfield.h"
game_field_t (*playfield)[NUM_COLS][NUM_ROWS]; game_field_t (*playfield)[NUM_COLS][NUM_ROWS];
/* internal functions */
/* this is the actual draw function for a single field
*/
static void draw_single_field (uint8_t in_x, uint8_t in_y, game_field_t in_f)
{
pixel tmp;
uint8_t b;
switch (in_f)
{
case b1:
b = 1;
break;
case rb:
case b2:
b = 2;
break;
case b3:
case bl:
case bs:
b = 3;
break;
default: /* this includes freespace */
b = 0;
break;
}
tmp.x = in_x;
tmp.y = in_y;
setpixel (tmp, b);
}
static void brick_damage (uint8_t in_x, uint8_t in_y)
{
if ((*playfield)[in_x][in_y] >= bs || (*playfield)[in_x][in_y] == 0)
return;
(*playfield)[in_x][in_y] -= 1;
score_add (1);
}
/* interface functions */
void playfield_set (uint8_t in_x, uint8_t in_y, game_field_t in_field) void playfield_set (uint8_t in_x, uint8_t in_y, game_field_t in_field)
{ {
if (in_x >= NUM_ROWS || in_y >= NUM_COLS) if (in_x >= NUM_ROWS || in_y >= NUM_COLS)
@ -28,15 +74,6 @@ void playfield_set (uint8_t in_x, uint8_t in_y, game_field_t in_field)
(*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)
return;
(*playfield)[in_x][in_y] -= 1;
score_add (1);
}
uint8_t check_bounce (int8_t in_x, int8_t in_y) uint8_t check_bounce (int8_t in_x, int8_t in_y)
{ {
uint8_t ov = 0; uint8_t ov = 0;
@ -78,39 +115,6 @@ uint8_t check_bounce (int8_t in_x, int8_t in_y)
return ov; return ov;
} }
/* this is the actual draw function for a single field
*/
static inline void draw_single_field (uint8_t in_x, uint8_t in_y, game_field_t in_f)
{
pixel tmp;
uint8_t b;
switch (in_f)
{
case b1:
b = 1;
break;
case rb:
case b2:
b = 2;
break;
case b3:
case bl:
case bs:
b = 3;
break;
default: /* this includes freespace */
b = 0;
break;
}
tmp.x = in_x;
tmp.y = in_y;
setpixel (tmp, b);
}
void playfield_draw () void playfield_draw ()
{ {
uint8_t x,y; uint8_t x,y;

View File

@ -17,7 +17,7 @@
*/ */
#include "rebound.h" #include "rebound.h"
static uint8_t rbpos; uint8_t rbpos;
void rebound_reflect (ball_t *b, int8_t in_x) void rebound_reflect (ball_t *b, int8_t in_x)
{ {
@ -29,17 +29,6 @@ void rebound_reflect (ball_t *b, int8_t in_x)
b->dir_y += rebound_reflection[tmpidx][1]; b->dir_y += rebound_reflection[tmpidx][1];
} }
uint8_t rebound_getpos ()
{
return (rbpos + (REBOUND_SIZE / 2));
}
void rebound_init()
{
rbpos = (NUM_ROWS / 2) - (REBOUND_SIZE / 2);
rebound_draw();
}
void rebound_draw () void rebound_draw ()
{ {
uint8_t i; uint8_t i;

View File

@ -19,9 +19,20 @@
#ifndef REBOUND_H #ifndef REBOUND_H
#define REBOUND_H #define REBOUND_H
void rebound_init();
void rebound_tick(ball_t *ball); void rebound_tick(ball_t *ball);
void rebound_draw(); void rebound_draw();
uint8_t rebound_getpos();
extern unsigned char rbpos;
inline static uint8_t rebound_getpos ()
{
return (rbpos + (REBOUND_SIZE / 2));
}
inline static void rebound_init()
{
rbpos = (NUM_ROWS / 2) - (REBOUND_SIZE / 2);
rebound_draw();
}
void rebound_reflect(ball_t *b, int8_t in_x); void rebound_reflect(ball_t *b, int8_t in_x);
#endif /* REBOUND_H */ #endif /* REBOUND_H */

View File

@ -16,14 +16,5 @@
* *
*/ */
#include "score.h" #include "score.h"
static uint16_t score = 0; unsigned short score = 0;
void score_add (uint8_t in_score)
{
score += in_score;
}
uint16_t score_get()
{
return score;
}

View File

@ -20,6 +20,14 @@
#ifndef SCORE_H #ifndef SCORE_H
#define SCORE_H #define SCORE_H
void score_add(uint8_t); extern unsigned short score;
uint16_t score_get(); inline static void score_add (uint8_t in_score)
{
score += in_score;
}
inline static unsigned short score_get()
{
return score;
}
#endif #endif

View File

@ -91,7 +91,7 @@ static uint8_t menu_getIconPixel(uint8_t item, uint8_t x, uint8_t y)
{ {
// return pixel // return pixel
return (0x80 >> x) & return (0x80 >> x) &
pgm_read_word(&_game_descriptors_start__[item].icon[y]); pgm_read_byte(&_game_descriptors_start__[item].icon[y]);
} }
else else
{ {

View File

@ -47,13 +47,13 @@ Wenn der Command abgearbeitet ist wird automatisch das nächste Token eingelesen
unsigned char (*text_pixmap)[NUM_ROWS][LINEBYTES]; unsigned char (*text_pixmap)[NUM_ROWS][LINEBYTES];
void text_setpixel(pixel p, unsigned char value ){ static void text_setpixel(pixel p, unsigned char value ){
if(value){ if(value){
(*text_pixmap)[p.y%NUM_ROWS][p.x/8] |= shl_table[p.x%8]; (*text_pixmap)[p.y%NUM_ROWS][p.x/8] |= shl_table[p.x%8];
} }
} }
void clear_text_pixmap(unsigned char value){ static void clear_text_pixmap(unsigned char value){
unsigned char y, z; unsigned char y, z;
for(y=NUM_ROWS;y--;){ for(y=NUM_ROWS;y--;){
for(z=LINEBYTES;z--;){ for(z=LINEBYTES;z--;){
@ -151,7 +151,7 @@ void showBlob(blob_t * blob){
#define PW(a) pgm_read_word(&(a)) #define PW(a) pgm_read_word(&(a))
#define PB(a) pgm_read_byte(&(a)) #define PB(a) pgm_read_byte(&(a))
unsigned int getLen(blob_t *blob) { static unsigned int getLen(blob_t *blob) {
unsigned char glyph; unsigned char glyph;
unsigned int strLen = 0; unsigned int strLen = 0;
unsigned char * str = (unsigned char*)blob->str; unsigned char * str = (unsigned char*)blob->str;
@ -166,7 +166,7 @@ unsigned int getLen(blob_t *blob) {
} }
unsigned int getnum(blob_t * blob){ static unsigned int getnum(blob_t * blob){
unsigned int num=0; unsigned int num=0;
unsigned char gotnum = 0; unsigned char gotnum = 0;
@ -523,9 +523,9 @@ void scrolltext(char *str) {
text_pixmap = malloc(NUM_ROWS * LINEBYTES); text_pixmap = malloc(NUM_ROWS * LINEBYTES);
if(scrolltext_text[0] == 0){ if(scrolltext_text[0] == 0){
strcpy_P(scrolltext_text, default_text); strcpy_P(scrolltext_text, default_text);
} }
memcpy(tmp_str, str, SCROLLTEXT_BUFFER_SIZE); memcpy(tmp_str, str, SCROLLTEXT_BUFFER_SIZE);
blob_t *startblob=0, *aktblob, *nextblob=0; blob_t *startblob=0, *aktblob, *nextblob=0;