This commit is contained in:
soeren 2010-01-19 09:55:28 +00:00
parent 731e6dadcb
commit ea1e89a2c2
8 changed files with 73 additions and 45 deletions

View File

@ -2,24 +2,38 @@
void ball_think (ball_t *b)
{
uint8_t new_x, new_y;
int8_t proj_x, proj_y, bounce;
if (!b->strength)
return;
new_x = (b->x + b->dir_x) >> 8;
new_y = (b->y + b->dir_y) >> 8;
/* projection of the new coordinates */
proj_x = (b->x + (b->dir_x)) / 256;
proj_y = (b->y + (b->dir_y)) / 256;
bounce = check_bounce (proj_x, b->y / 256);
if (bounce & BOUNCE_UNDEF)
bounce = (BOUNCE_X | bounce) & (BOUNCE_X | BOUNCE_Y);
bounce |= check_bounce (b->x / 256, proj_y);
if (bounce & BOUNCE_UNDEF)
bounce = (BOUNCE_Y | bounce) & (BOUNCE_X | BOUNCE_Y);
bounce |= check_bounce (proj_x, proj_y);
if (bounce & BOUNCE_UNDEF)
bounce = BOUNCE_X | BOUNCE_Y;
printf("B: %i %i, d: %i %i\n", new_x, new_y);
/* ball fell out of the field */
// if (new_y >= NUM_ROWS)
// if (proj_y >= NUM_ROWS)
// ball_die (b);
/* bounce in x direction */
if (check_bounce (new_x, b->y >> 8))
if (bounce & 0x01)
{
b->dir_x *= -1; /* invert x vector */
new_x += b->dir_x;
b->dir_x ^= random8() & 0x0F; /* randomize bouncing */
#if BOUNCE_SLOWDOWN
if (b->dir_x < 0)
@ -33,11 +47,10 @@ void ball_think (ball_t *b)
}
/* bounce in y direction */
if (check_bounce ((b->x >> 8), new_y))
if (bounce & 0x02)
{
b->dir_y *= -1; /* invert y vector */
new_y += b->dir_y;
b->dir_y ^= random8() & 0x0F;
#if BOUNCE_SLOWDOWN
if (b->dir_y < 0)
{
@ -49,8 +62,12 @@ void ball_think (ball_t *b)
#endif
}
b->x = new_x;
b->y = new_y;
b->y += b->dir_y;
b->x += b->dir_x;
printf("B: %i %i, d: %i %i\n", b->x, b->y, b->dir_x, b->dir_y);
}
void ball_die (ball_t *in_b)
@ -65,14 +82,17 @@ void ball_die (ball_t *in_b)
void ball_draw (ball_t *b)
{
pixel p;
p.x = b->x;
p.y = b->y;
p.x = (uint8_t) abs(b->x / 256);
p.y = (uint8_t) abs(b->y / 256);
printf("db: %i %i\n", p.x, p.y);
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, uint8_t in_strength)
{
printf ("spawn: %i %i, dir: %i, %i\n", in_x, in_y, in_dir_x, in_dir_y);
in_ball->x = in_x;
in_ball->y = in_y;
in_ball->dir_x = in_dir_x;

View File

@ -7,8 +7,8 @@
typedef struct
{
uint16_t x;
uint16_t y;
int16_t x;
int16_t y;
int16_t dir_x; /* direction vector */
int16_t dir_y;
uint8_t strength;

View File

@ -4,7 +4,7 @@ void borg_breakout();
#ifdef MENU_SUPPORT
//static uint8_t breakout_icon[8] PROGMEM = {0x03, 0x03, 0x00, 0x00, 0xff, 0xff, 0x00, 0x00}; /* our Icon */
static uint8_t breakout_icon[8] PROGMEM = {0x03, 0x03, 0x00, 0x00, 0xff, 0xff, 0x00, 0x00}; /* our Icon */
static uint8_t breakout_icon[8] PROGMEM = {0x18, 0x18, 0x00, 0x00, 0xff, 0xff, 0x00, 0x00}; /* our Icon */
game_descriptor_t breakout_game_descriptor __attribute__((section(".game_descriptors"))) =
{
@ -18,12 +18,11 @@ void borg_breakout()
uint8_t rungame = 1, num_balls = 1;
ball_t balls[1];
/* spawn a ball in the middle bottom of the field, let it move upwards with random speed & direction */
ball_spawn (&balls[0], (uint16_t) (NUM_COLS / 2) * 256, (uint16_t) (NUM_ROWS-2) * 256, -120, 150, START_LIFES);
level_init(3);
rebound_init();
/* spawn a ball in the middle bottom of the field, let it move upwards with random speed & x-direction */
ball_spawn (&balls[0], (NUM_COLS / 2) << 8, (NUM_ROWS-2) << 8, - (random8() % 8), (random8() % 8), START_LIFES);
level_init(1);
while (rungame)
{
wait(50);

View File

@ -1,6 +1,8 @@
#ifndef COMMON_H
#define COMMON_H
#include <stdint.h>
#include <stdlib.h>
#include <stdio.h>
#include "../../joystick/joystick.h"
#include "../../config.h"
#include "../../autoconf.h"

View File

@ -1,5 +1,5 @@
/* amount of speed to slow down on bounce */
#define BOUNCE_SLOWDOWN 1
#define BOUNCE_SLOWDOWN 0
/* minimum speed of the ball */
#define BALL_MINSPEED 0x0010

View File

@ -8,11 +8,11 @@ enum game_field_t level_field (uint8_t in_x, uint8_t in_y, uint8_t in_lvl)
{
case 1:
/* space for the lower half of the level */
if (in_y < (NUM_ROWS / 2))
if (in_y > (NUM_ROWS / 2))
return sp;
/* type 2 bricks for 1/4th of the field */
if (in_y >= (NUM_ROWS / 4))
if (in_y <= (NUM_ROWS / 4))
return b2;
/* fill the rest with type 1 */
@ -29,15 +29,15 @@ enum game_field_t level_field (uint8_t in_x, uint8_t in_y, uint8_t in_lvl)
case 2:
/* space for the lower third of the level */
if (in_y < (NUM_ROWS / 3))
if (in_y > (NUM_ROWS / 3))
return sp;
/* type 3 bricks for 1/8th of the field */
if (in_y >= (NUM_ROWS / 8))
if (in_y <= (NUM_ROWS / 8))
return b3;
/* type 2 bricks for 1/4th of the field */
if (in_y >= (NUM_ROWS / 4))
if (in_y <= (NUM_ROWS / 4))
return b2;
/* fill the rest with type 1 */
@ -45,10 +45,10 @@ enum game_field_t level_field (uint8_t in_x, uint8_t in_y, uint8_t in_lvl)
default: /* random level generation */
/* space for the lower half of the level */
if (in_y < (NUM_ROWS / 2))
if (in_y > (NUM_ROWS / 2))
return sp;
return random8() % 5; /* fill field with random bricks (and spaces) */
return random8() % 4; /* fill field with random bricks (and spaces) */
break;
}
}

View File

@ -12,27 +12,24 @@ 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]--;
playfield[in_x][in_y] -= 1;
score_add (1);
}
uint8_t check_bounce (uint8_t in_x, uint8_t in_y)
uint8_t check_bounce (int8_t in_x, int8_t in_y)
{
uint8_t ov = 0;
/* overflow check */
if (in_x >= NUM_ROWS)
return 1;
if (in_x >= NUM_ROWS || in_x < 0)
ov |= BOUNCE_X;
if (in_y >= NUM_COLS)
return 1;
if (in_y >= NUM_COLS || in_y < 0)
ov |= BOUNCE_Y;
if (ov) return ov;
/* collisions with real objects */
switch (playfield[in_x][in_y])
switch (playfield[abs(in_x)][abs(in_y)])
{
case sp:
case bl:
return 0;
case b2:
case b3:
case b1:
@ -40,11 +37,17 @@ uint8_t check_bounce (uint8_t in_x, uint8_t in_y)
/* intentional fallthrough */
case bs:
return 1;
return BOUNCE_UNDEF | ov;
/* bouncing on the rebound needs special care */
case rb:
return 2;
return BOUNCE_Y;
case sp:
case bl:
default:
return ov;
}
}

View File

@ -2,6 +2,10 @@
#define PLAYFIELD_H
#include "common.h"
#define BOUNCE_X 0x01
#define BOUNCE_Y 0x02
#define BOUNCE_UNDEF 0x04
/* entries for the playing field */
enum game_field_t
{
@ -23,6 +27,6 @@ void playfield_set (uint8_t in_x, uint8_t in_y, enum game_field_t in_field);
/* @description Checks if there is an object in the way. If so, it returns 1
*/
uint8_t check_bounce (uint8_t in_x, uint8_t in_y);
uint8_t check_bounce (int8_t in_x, int8_t in_y);
#endif /* PLAYFIELD_H */