11 #define WINDOW_WIDTH 640 12 #define WINDOW_HEIGHT 480 15 #define FRAMES_PER_SECOND 60 16 #define FRAME_RATE 1000/FRAMES_PER_SECOND 19 #define YELLOW_COLOR 6 27 #define BRICK_SCREEN_BUFFER_X 41 28 #define BRICK_SCREEN_BUFFER_Y 30 33 #define MAX_BRICKS NUM_ROWS*NUM_COLS 40 #define BRICK_WIDTH 62 41 #define BRICK_HEIGHT 16 44 #define PADDLE_WIDTH 32 45 #define PADDLE_HEIGHT 8 48 #define BALL_DIAMETER 8 51 #define PLAYER_SPEED 2 54 #define BALL_SPEED_MODIFIER 4 // divide location on paddle by this 55 #define BALL_SPEED_Y 2 // max speed of ball along y axis 69 #define sgn(x) ((x<0)?-1:((x>0)?1:0)) 105 static unsigned char table[] = {63, 6, 91, 79, 102, 109, 125, 7, 127, 111};
110 void line(
int x1,
int y1,
int x2,
int y2,
unsigned int color)
112 int i,dx,dy,sdx,sdy,dxabs,dyabs,
x,
y,px,py;
126 for(i=0; i<dxabs; i++)
140 for(i=0; i<dyabs; i++)
154 void rect(
int left,
int top,
int right,
int bottom,
unsigned int color)
156 line(left,top,right,top,color);
157 line(left,top,left,bottom,color);
158 line(right,top,right,bottom,color);
159 line(left,bottom,right,bottom,color);
162 void circle(
int x0,
int y0,
int radius,
unsigned int color)
164 int x = radius,
y = 0;
165 int radiusError = 1-
x;
168 plot(color,x + x0, y + y0);
169 plot(color,y + x0, x + y0);
170 plot(color,-x + x0, y + y0);
171 plot(color,-y + x0, x + y0);
172 plot(color,-x + x0, -y + y0);
173 plot(color,-y + x0, -x + y0);
174 plot(color,x + x0, -y + y0);
175 plot(color,y + x0, -x + y0);
182 radiusError+=2*(y-x+1);
187 void rect_fill(
int left,
int top,
int right,
int bottom,
unsigned int color)
190 for (currentline=top; currentline<=bottom; currentline++)
191 line(left,currentline,right,currentline,color);
199 short int low_byte =
level;
200 short int high_byte =
lives;
201 unsigned long long sseg_val = 0;
202 for ( b =
'0' - 1; high_byte >= 0; high_byte -= 10 ) ++b;
203 a =
'0' + high_byte + 10;
206 for ( d =
'0' - 1; low_byte >= 0; low_byte -= 10 ) ++d;
207 c =
'0' + low_byte + 10;
255 if ( (ball_speed > 0) && (ball_y + ball_height >= paddle_y) &&
256 (ball_y + ball_height <= paddle_y + paddle_height) )
259 if ( (ball_x <= paddle_x + paddle_width) && (ball_x + ball_width >= paddle_x) )
280 0, 3, 3, 3, 3, 3, 3, 3, 0,
281 2, 0, 3, 3, 3, 3, 3, 0, 2,
282 2, 2, 0, 3, 3, 3, 0, 2, 2,
283 2, 2, 2, 0, 3, 0, 2, 2, 2,
284 2, 2, 2, 2, 0, 2, 2, 2, 2,
285 2, 2, 2, 0, 4, 0, 2, 2, 2
287 3, 3, 3, 3, 3, 3, 3, 3, 3,
288 0, 4, 0, 4, 0, 4, 0, 4, 0,
289 2, 2, 2, 2, 2, 2, 2, 2, 2,
290 0, 4, 0, 4, 0, 4, 0, 4, 0,
291 3, 3, 3, 3, 3, 3, 3, 3, 3,
292 0, 4, 0, 4, 0, 4, 0, 4, 0
294 1, 2, 1, 2, 1, 2, 1, 2, 1,
295 1, 2, 1, 2, 1, 2, 1, 2, 1,
296 1, 2, 1, 2, 1, 2, 1, 2, 1,
297 1, 2, 1, 1, 1, 2, 1, 2, 1,
298 1, 2, 1, 2, 1, 2, 1, 2, 1,
299 1, 2, 1, 2, 1, 2, 1, 2, 1
334 switch (bricks[index].num_hits)
396 _Bool left_pressed = 0;
397 _Bool right_pressed = 0;
398 unsigned char button_pressed =
btn_ctrl();
424 if ( (x >= rect->
x) && (x <= rect->x + rect->
w) &&
425 (y >= rect->
y) && (y <= rect->y + rect->
h) )
459 if (bricks[index].num_hits == 0)
478 switch (bricks[index].num_hits)
525 for (brick_index=0; brick_index<
MAX_BRICKS; brick_index++)
527 if(bricks[brick_index].color ==
BLACK_COLOR)
continue;
603 int paddle_location = ball_center - paddle_center;
_Bool check_wall_collisions(entity *entity, unsigned char dir)
void * top(node_stack *head)
unsigned int get_ticks(unsigned char restart_value)
return an unsigned int which represents the elapsed processor time in milliseconds since some constan...
#define BRICK_SCREEN_BUFFER_X
obj_description screen_location
void bricks_initialization()
void circle(int x0, int y0, int radius, unsigned int color)
#define WINDOW_WIDTH
Breakout game ported to the PandA framework by Fabrizio Ferrandi on April 11th 2016.
#define BRICK_SCREEN_BUFFER_Y
void line(int x1, int y1, int x2, int y2, unsigned int color)
obj_description screen_location
void rect_fill(int left, int top, int right, int bottom, unsigned int color)
#define BALL_SPEED_MODIFIER
static unsigned char level_hits[NUM_LEVELS][MAX_BRICKS]
_Bool check_brick_collisions()
void game_initialization()
struct _obj_description obj_description
_Bool check_point_in_rect(int x, int y, obj_description *rect)
unsigned char convert_char_digit_2_sseg(char c)
void rect(int left, int top, int right, int bottom, unsigned int color)
_Bool manage_brick_collision(int index)
void sevensegments_ctrl(unsigned long long val, unsigned long long mask)
void plot(int color, int x, int y)
_Bool check_ball_collisions()