This commit is contained in:
soeren 2010-01-21 18:32:17 +00:00
parent e8291a5f36
commit 254d0d2f3d
4 changed files with 69 additions and 24 deletions

View File

@ -37,9 +37,10 @@ void bounce_rand_vector (ball_t *in_b, uint8_t in_bouncetype)
case BOUNCE_REBOUND: /* the rebound is rather percise */ case BOUNCE_REBOUND: /* the rebound is rather percise */
in_b->dir_x ^= (rval & 0x03); in_b->dir_x ^= (rval & 0x03);
in_b->dir_y ^= (rval & 0x03); in_b->dir_y ^= (rval & 0x03);
if (JOYISRIGHT || JOYISLEFT) if (JOYISRIGHT || JOYISLEFT)
{ {
/* a moving rebond accelerates the ball by 1/8th */ /* a moving rebond accelerates the ball 12,5% */
in_b->dir_y += (in_b->dir_y / 8); in_b->dir_y += (in_b->dir_y / 8);
in_b->dir_x += (in_b->dir_x / 8); in_b->dir_x += (in_b->dir_x / 8);
} }
@ -78,12 +79,7 @@ void ball_think (ball_t *b)
bounce = (BOUNCE_X | bounce) & (BOUNCE_X | BOUNCE_Y); bounce = (BOUNCE_X | bounce) & (BOUNCE_X | BOUNCE_Y);
bounce |= check_bounce (b->x / 256, proj_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); bounce |= check_bounce (proj_x, proj_y);
if (bounce & BOUNCE_UNDEF)
bounce = BOUNCE_X | BOUNCE_Y;
bounce_rand_vector (b, bounce); bounce_rand_vector (b, bounce);
@ -91,33 +87,52 @@ void ball_think (ball_t *b)
if (bounce & (BOUNCE_X | BOUNCE_BRICK)) if (bounce & (BOUNCE_X | BOUNCE_BRICK))
{ {
b->dir_x *= -1; /* invert x vector */ b->dir_x *= -1; /* invert x vector */
#if BOUNCE_SLOWDOWN
if (b->dir_x < 0)
{
b->dir_x += BOUNCE_SLOWDOWN;
} else
{
b->dir_x -= BOUNCE_SLOWDOWN;
}
#endif
} }
/* bounce in y direction */ /* bounce in y direction */
if (bounce & (BOUNCE_Y | BOUNCE_BRICK)) if (bounce & (BOUNCE_Y | BOUNCE_BRICK))
{ {
b->dir_y *= -1; /* invert y vector */ b->dir_y *= -1; /* invert y vector */
}
#if BOUNCE_SLOWDOWN #if BOUNCE_SLOWDOWN
if (b->dir_y < 0) if (bounce & BOUNCE_BRICK)
{
if (b->dir_y < -BALL_MINSPEED)
{ {
b->dir_y += BOUNCE_SLOWDOWN; b->dir_y += BOUNCE_SLOWDOWN;
} else } else if (b->dir_y > BALL_MINSPEED)
{ {
b->dir_y -= BOUNCE_SLOWDOWN; b->dir_y -= BOUNCE_SLOWDOWN;
} }
#endif
if (b->dir_x < -BALL_MINSPEED)
{
b->dir_x += BOUNCE_SLOWDOWN;
} else if (b->dir_y > BALL_MINSPEED)
{
b->dir_x -= BOUNCE_SLOWDOWN;
}
} }
#endif
if (bounce & BOUNCE_REBOUND)
{
rebound_reflect(b, proj_x);
}
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;
b->y += b->dir_y; b->y += b->dir_y;
b->x += b->dir_x; b->x += b->dir_x;

View File

@ -1,14 +1,32 @@
#ifndef CONFIG_H
#define CONFIG_H
/* amount of speed to slow down on bounce */ /* amount of speed to slow down on bounce */
#define BOUNCE_SLOWDOWN 0 #define BOUNCE_SLOWDOWN 8
/* minimum speed of the ball */ /* minimum speed of the ball */
#define BALL_MINSPEED 0x0010 #define BALL_MINSPEED 64
#define BALL_MAXSPEED 224
/* initial amount of lifes */ /* initial amount of lifes */
#define START_LIFES 3 #define START_LIFES 3
/* rebound size */ /* rebound size */
#define REBOUND_SIZE 5 #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 */ /* "color" of the rebound */
#define REBOUND_COLOR 2 #define REBOUND_COLOR 2
#endif /* CONFIG_H */

View File

@ -17,9 +17,20 @@
*/ */
#include "rebound.h" #include "rebound.h"
#include <stdio.h>
static uint8_t rbpos; static uint8_t rbpos;
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];
}
uint8_t rebound_getpos () uint8_t rebound_getpos ()
{ {
return (rbpos + (REBOUND_SIZE / 2)); return (rbpos + (REBOUND_SIZE / 2));

View File

@ -21,4 +21,5 @@
void rebound_init(); void rebound_init();
void rebound_tick(); void rebound_tick();
uint8_t rebound_getpos (); uint8_t rebound_getpos ();
void rebound_reflect (ball_t *b, int8_t in_x);
#endif #endif