12 #define WINDOW_WIDTH 640 13 #define WINDOW_HEIGHT 480 16 #define FRAMES_PER_SECOND 60 17 #define FRAME_RATE 1000/FRAMES_PER_SECOND 20 #define YELLOW_COLOR 6 32 #define PADDLE_WIDTH 32 33 #define PADDLE_HEIGHT 8 36 #define BALL_DIAMETER 8 39 #define PLAYER_SPEED 2 40 #define COMPUTER_SPEED 2 43 #define BALL_SPEED_MODIFIER 4 // divide location on paddle by this 44 #define BALL_SPEED_Y 2 // max speed of ball along y axis 51 #define sgn(x) ((x<0)?-1:((x>0)?1:0)) 89 #define rot(x,k) (((x)<<(k))|((x)>>(32-(k)))) 92 unsigned int e = x->
a -
rot(x->
b, 27);
93 x->
a = x->
b ^
rot(x->
c, 17);
103 x->
a = 0xf1ea5eed, x->
b = x->
c = x->
d = seed;
112 static unsigned char table[] = {63, 6, 91, 79, 102, 109, 125, 7, 127, 111};
117 void line(
int x1,
int y1,
int x2,
int y2,
unsigned int color)
119 int i,dx,dy,sdx,sdy,dxabs,dyabs,
x,
y,px,py;
133 for(i=0; i<dxabs; i++)
147 for(i=0; i<dyabs; i++)
161 void rect(
int left,
int top,
int right,
int bottom,
unsigned int color)
163 line(left,top,right,top,color);
164 line(left,top,left,bottom,color);
165 line(right,top,right,bottom,color);
166 line(left,bottom,right,bottom,color);
169 void circle(
int x0,
int y0,
int radius,
unsigned int color)
171 int x = radius,
y = 0;
172 int radiusError = 1-
x;
175 plot(color,x + x0, y + y0);
176 plot(color,y + x0, x + y0);
177 plot(color,-x + x0, y + y0);
178 plot(color,-y + x0, x + y0);
179 plot(color,-x + x0, -y + y0);
180 plot(color,-y + x0, -x + y0);
181 plot(color,x + x0, -y + y0);
182 plot(color,y + x0, -x + y0);
189 radiusError+=2*(y-x+1);
194 void rect_fill(
int left,
int top,
int right,
int bottom,
unsigned int color)
197 for (currentline=top; currentline<=bottom; currentline++)
198 line(left,currentline,right,currentline,color);
208 unsigned long long sseg_val = 0;
209 for ( b =
'0' - 1; high_byte >= 0; high_byte -= 10 ) ++b;
210 a =
'0' + high_byte + 10;
213 for ( d =
'0' - 1; low_byte >= 0; low_byte -= 10 ) ++d;
214 c =
'0' + low_byte + 10;
265 if ( (ball_speed > 0) && (ball_y + ball_height >= paddle_y) &&
266 (ball_y + ball_height <= paddle_y + paddle_height) )
269 if ( (ball_x <= paddle_x + paddle_width) && (ball_x + ball_width >= paddle_x) )
277 if ( (ball_speed < 0) && (ball_y >= paddle_y) &&
278 (ball_y <= paddle_y + paddle_height) )
281 if ( (ball_x <= paddle_x + paddle_width) && (ball_x + ball_width >= paddle_x) )
379 _Bool left_pressed = 0;
380 _Bool right_pressed = 0;
381 unsigned char button_pressed =
btn_ctrl();
414 int paddle_location = ball_center - paddle_center;
426 int paddle_location = ball_center - paddle_center;
477 if (computer_x > ball_center)
483 else if (computer_x < ball_center)
_Bool check_wall_collisions(entity *entity, unsigned char dir)
#define BALL_SPEED_MODIFIER
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...
struct _random_state_t random_state_t
#define WINDOW_WIDTH
Pong game ported to the PandA framework by Fabrizio Ferrandi.
_Bool manage_player_score()
void circle(int x0, int y0, int radius, unsigned int color)
void line(int x1, int y1, int x2, int y2, unsigned int color)
obj_description screen_location
static random_state_t random_state
void rect_fill(int left, int top, int right, int bottom, unsigned int color)
unsigned int random_number(random_state_t *x)
void game_initialization()
struct _obj_description obj_description
unsigned char player_score
unsigned char computer_score
_Bool manage_computer_score()
void random_number_init(random_state_t *x, unsigned int seed)
unsigned char convert_char_digit_2_sseg(char c)
void rect(int left, int top, int right, int bottom, unsigned int color)
void sevensegments_ctrl(unsigned long long val, unsigned long long mask)
void plot(int color, int x, int y)
_Bool check_ball_collisions()