Browse Source

238 bytes this time

feature/2015
Christian Kroll 14 years ago
parent
commit
cd2f02f39a
  1. 48
      games/breakout/ball.c
  2. 5
      games/breakout/ball.h
  3. 7
      games/breakout/level.c
  4. 80
      games/breakout/playfield.c
  5. 13
      games/breakout/rebound.c
  6. 15
      games/breakout/rebound.h
  7. 11
      games/breakout/score.c
  8. 12
      games/breakout/score.h
  9. 2
      menu/menu.c
  10. 14
      scrolltext/scrolltext3.c

48
games/breakout/ball.c

@ -18,9 +18,30 @@
#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 */
void bounce_rand_vector (ball_t *in_b, uint8_t in_bouncetype);
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)
{
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;
}
/* interface functions */
void ball_think (ball_t *b)
{
int8_t proj_x, proj_y, bounce, tmp;
@ -141,18 +165,6 @@ void ball_think (ball_t *b)
b->y += b->dir_y;
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)
{
@ -163,14 +175,6 @@ void ball_draw (ball_t *b)
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)
{
int16_t xdir;

5
games/breakout/ball.h

@ -30,15 +30,10 @@ typedef struct
uint8_t strength;
} 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.
*/
void ball_think (ball_t *in_ball);
void ball_die (ball_t *in_b);
void ball_draw (ball_t *);
void ball_spawn_default (ball_t *in_b);

7
games/breakout/level.c

@ -20,9 +20,10 @@
static uint16_t maxscore;
/* internal functions */
/* real level definition */
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)
static game_field_t level_field (uint8_t in_x, uint8_t in_y, uint8_t 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)
{
uint8_t x,y;

80
games/breakout/playfield.c

@ -19,16 +19,42 @@
#include "playfield.h"
game_field_t (*playfield)[NUM_COLS][NUM_ROWS];
void playfield_set (uint8_t in_x, uint8_t in_y, game_field_t in_field)
/* 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)
{
if (in_x >= NUM_ROWS || in_y >= NUM_COLS)
pixel tmp;
uint8_t b;
switch (in_f)
{
return;
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;
}
(*playfield)[in_x][in_y] = in_field;
tmp.x = in_x;
tmp.y = in_y;
setpixel (tmp, b);
}
void brick_damage (uint8_t in_x, uint8_t in_y)
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;
@ -37,6 +63,17 @@ void brick_damage (uint8_t in_x, uint8_t in_y)
score_add (1);
}
/* interface functions */
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)
{
return;
}
(*playfield)[in_x][in_y] = in_field;
}
uint8_t check_bounce (int8_t in_x, int8_t in_y)
{
uint8_t ov = 0;
@ -78,39 +115,6 @@ uint8_t check_bounce (int8_t in_x, int8_t in_y)
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 ()
{
uint8_t x,y;

13
games/breakout/rebound.c

@ -17,7 +17,7 @@
*/
#include "rebound.h"
static uint8_t rbpos;
uint8_t rbpos;
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];
}
uint8_t rebound_getpos ()
{
return (rbpos + (REBOUND_SIZE / 2));
}
void rebound_init()
{
rbpos = (NUM_ROWS / 2) - (REBOUND_SIZE / 2);
rebound_draw();
}
void rebound_draw ()
{
uint8_t i;

15
games/breakout/rebound.h

@ -19,9 +19,20 @@
#ifndef REBOUND_H
#define REBOUND_H
void rebound_init();
void rebound_tick(ball_t *ball);
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);
#endif /* REBOUND_H */

11
games/breakout/score.c

@ -16,14 +16,5 @@
*
*/
#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;
}

12
games/breakout/score.h

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

2
menu/menu.c

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

14
scrolltext/scrolltext3.c

@ -47,13 +47,13 @@ Wenn der Command abgearbeitet ist wird automatisch das nächste Token eingelesen
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){
(*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;
for(y=NUM_ROWS;y--;){
for(z=LINEBYTES;z--;){
@ -151,7 +151,7 @@ void showBlob(blob_t * blob){
#define PW(a) pgm_read_word(&(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 int strLen = 0;
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 char gotnum = 0;
@ -523,9 +523,9 @@ void scrolltext(char *str) {
text_pixmap = malloc(NUM_ROWS * LINEBYTES);
if(scrolltext_text[0] == 0){
strcpy_P(scrolltext_text, default_text);
}
if(scrolltext_text[0] == 0){
strcpy_P(scrolltext_text, default_text);
}
memcpy(tmp_str, str, SCROLLTEXT_BUFFER_SIZE);
blob_t *startblob=0, *aktblob, *nextblob=0;

Loading…
Cancel
Save