#include #include #include #include #include "Display.h" #include "structs.h" #define ACCELERATION 0.1f #define TICK 0.01f #define LEFT_UP_BUTTON 0 #define LEFT_DOWN_BUTTON 1 #define RIGTH_UP_BUTTON 2 #define RIGTH_DOWN_BUTTON 3 #define MIN(a,b) (((a)<(b))?(a):(b)) #define MAX(a,b) (((a)>(b))?(a):(b)) struct Ball ball; struct Paddle left_paddle; struct Paddle right_paddle; void reset_pos() { ball.x = COLS/2 - 1; ball.y = ROWS/2 - 1; ball.vel_x = - 1; ball.vel_y = - 1; left_paddle.y = 0; left_paddle.length = 3; right_paddle.y = 0; right_paddle.length = 3; } void game() { int i,k; unsigned buttons; k=0; reset_pos(); while (1){ buttons = ~IORD_ALTERA_AVALON_PIO_DATA(PIO_BUTTON_BASE); //buttons = 10; if (buttons & (1<= left_paddle.y && ball.y <= (left_paddle.y + left_paddle.length -1)){ ball.vel_x = - ball.vel_x; } else { printf("%d ,, ballx: %f, ball y: %f",k,ball.x,ball.y); printf("rigth player lost"); getchar(); reset_pos(); } } if (ball.x >= COLS - 2){ if (ball.y >= right_paddle.y && ball.y <= (right_paddle.y + right_paddle.length -1)){ ball.vel_x = - ball.vel_x; } else { printf("%d ,, ballx: %f, ball y: %f",k,ball.x,ball.y); printf("left player lost"); getchar(); reset_pos(); } } if (ball.vel_x < 0) { ball.vel_x = ball.vel_x - ACCELERATION; } else { ball.vel_x = ball.vel_x + ACCELERATION; } if (ball.vel_y < 0) { ball.vel_y = ball.vel_y - ACCELERATION; } else { ball.vel_y = ball.vel_y + ACCELERATION; } reset_screen(); for (i=0;i