works
This commit is contained in:
parent
ea1e89a2c2
commit
884badbc2f
|
@ -1,5 +1,6 @@
|
||||||
#include "common.h"
|
#include "common.h"
|
||||||
|
|
||||||
|
|
||||||
void ball_think (ball_t *b)
|
void ball_think (ball_t *b)
|
||||||
{
|
{
|
||||||
int8_t proj_x, proj_y, bounce;
|
int8_t proj_x, proj_y, bounce;
|
||||||
|
@ -9,6 +10,11 @@ void ball_think (ball_t *b)
|
||||||
/* projection of the new coordinates */
|
/* projection of the new coordinates */
|
||||||
proj_x = (b->x + (b->dir_x)) / 256;
|
proj_x = (b->x + (b->dir_x)) / 256;
|
||||||
proj_y = (b->y + (b->dir_y)) / 256;
|
proj_y = (b->y + (b->dir_y)) / 256;
|
||||||
|
|
||||||
|
/* ball fell out of the field */
|
||||||
|
if (proj_y >= NUM_ROWS)
|
||||||
|
ball_die (b);
|
||||||
|
|
||||||
|
|
||||||
bounce = check_bounce (proj_x, b->y / 256);
|
bounce = check_bounce (proj_x, b->y / 256);
|
||||||
if (bounce & BOUNCE_UNDEF)
|
if (bounce & BOUNCE_UNDEF)
|
||||||
|
@ -23,10 +29,6 @@ void ball_think (ball_t *b)
|
||||||
bounce = BOUNCE_X | BOUNCE_Y;
|
bounce = BOUNCE_X | BOUNCE_Y;
|
||||||
|
|
||||||
|
|
||||||
/* ball fell out of the field */
|
|
||||||
// if (proj_y >= NUM_ROWS)
|
|
||||||
// ball_die (b);
|
|
||||||
|
|
||||||
|
|
||||||
/* bounce in x direction */
|
/* bounce in x direction */
|
||||||
if (bounce & 0x01)
|
if (bounce & 0x01)
|
||||||
|
@ -64,10 +66,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;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
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)
|
void ball_die (ball_t *in_b)
|
||||||
|
@ -76,7 +74,10 @@ void ball_die (ball_t *in_b)
|
||||||
|
|
||||||
/* respawn ball with random direction */
|
/* respawn ball with random direction */
|
||||||
if (in_b->strength)
|
if (in_b->strength)
|
||||||
ball_spawn (in_b, (NUM_COLS / 2) << 8, (NUM_ROWS-2) << 8, - random8(), random8(), START_LIFES);
|
{
|
||||||
|
print_ballsleft(in_b);
|
||||||
|
ball_spawn (in_b, (uint16_t) (rebound_getpos() * 256), (uint16_t) (NUM_ROWS-2) * 256, -120, 150, in_b->strength);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ball_draw (ball_t *b)
|
void ball_draw (ball_t *b)
|
||||||
|
@ -85,17 +86,19 @@ void ball_draw (ball_t *b)
|
||||||
p.x = (uint8_t) abs(b->x / 256);
|
p.x = (uint8_t) abs(b->x / 256);
|
||||||
p.y = (uint8_t) abs(b->y / 256);
|
p.y = (uint8_t) abs(b->y / 256);
|
||||||
|
|
||||||
printf("db: %i %i\n", p.x, p.y);
|
|
||||||
|
|
||||||
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, uint8_t in_strength)
|
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->x = in_x;
|
||||||
in_ball->y = in_y;
|
in_ball->y = in_y;
|
||||||
in_ball->dir_x = in_dir_x;
|
in_ball->dir_x = in_dir_x;
|
||||||
in_ball->dir_y = in_dir_y;
|
in_ball->dir_y = in_dir_y;
|
||||||
in_ball->strength = in_strength;
|
in_ball->strength = in_strength;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ball_spawn_default (ball_t *in_b)
|
||||||
|
{
|
||||||
|
ball_spawn (in_b, (uint16_t) (NUM_COLS / 2) * 256, (uint16_t) (NUM_ROWS-2) * 256, -120, 150, START_LIFES);
|
||||||
|
}
|
||||||
|
|
|
@ -24,4 +24,6 @@ void ball_think (ball_t *in_ball);
|
||||||
void ball_die (ball_t *in_b);
|
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);
|
||||||
#endif /* BALL_H */
|
#endif /* BALL_H */
|
||||||
|
|
|
@ -20,15 +20,20 @@ void borg_breakout()
|
||||||
|
|
||||||
/* spawn a ball in the middle bottom of the field, let it move upwards with random speed & direction */
|
/* 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);
|
ball_spawn (&balls[0], (uint16_t) (NUM_COLS / 2) * 256, (uint16_t) (NUM_ROWS-2) * 256, -120, 150, START_LIFES);
|
||||||
level_init(3);
|
level_init(0);
|
||||||
rebound_init();
|
rebound_init();
|
||||||
|
|
||||||
while (rungame)
|
while (23)
|
||||||
{
|
{
|
||||||
wait(50);
|
wait(50);
|
||||||
rebound_tick();
|
rebound_tick();
|
||||||
ball_think(&balls[0]);
|
ball_think(&(balls[0]));
|
||||||
playfield_draw();
|
playfield_draw();
|
||||||
ball_draw(&balls[0]);
|
ball_draw(&(balls[0]));
|
||||||
|
if (!balls[0].strength)
|
||||||
|
{
|
||||||
|
print_score();
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,4 +18,5 @@
|
||||||
#include "score.h"
|
#include "score.h"
|
||||||
#include "level.h"
|
#include "level.h"
|
||||||
#include "rebound.h"
|
#include "rebound.h"
|
||||||
|
#include "messages.h"
|
||||||
#endif /* COMMON_H */
|
#endif /* COMMON_H */
|
||||||
|
|
|
@ -48,7 +48,7 @@ enum game_field_t level_field (uint8_t in_x, uint8_t in_y, uint8_t in_lvl)
|
||||||
if (in_y > (NUM_ROWS / 2))
|
if (in_y > (NUM_ROWS / 2))
|
||||||
return sp;
|
return sp;
|
||||||
|
|
||||||
return random8() % 4; /* fill field with random bricks (and spaces) */
|
return random8() & 0x03; /* fill field with random bricks (and spaces) */
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,8 +1,10 @@
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
#include "common.h"
|
||||||
|
|
||||||
#ifndef SCORE_H
|
#ifndef SCORE_H
|
||||||
#define SCORE_H
|
#define SCORE_H
|
||||||
|
|
||||||
|
|
||||||
void score_add(uint8_t);
|
void score_add(uint8_t);
|
||||||
|
uint16_t score_get();
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in New Issue