//AsterPong - An Astroids/Hockey/Pong type game Version 0.02 //(Volume I of Ciphersoft Sports) //Copyright 2000 Justin Todd #define FRICTION 0.99 //Universal friction #define NET_SIZE 45 //Net size in pixels #define PADDLE_SIZE 20 //Length of the paddles #define B_COLOR 1 //Color of all the boundry lines etc... #define NET_COLOR 11 //Color of the net #define ROTATE_RATE 5 //Rotation speed of the object #define SPEED 0.2 //Speed of the paddle ships #include"allegro.h" #include //sprintf() BITMAP *Virtual; //Virtual screen for smooth animation typedef struct{ //Structure containing general data for an object float x,y; //Actual x and y location float xvel,yvel; //x and y velocity of the object int sx,sy; //x and y location on the screen float rxvel,ryvel; //Rotation velocity fixed angle; //View angle of the object }OBJECT; double radians; OBJECT ship; OBJECT puck; void Init(){ //Initialize Allegro allegro_init(); install_keyboard(); set_gfx_mode(GFX_AUTODETECT,640,480,0,0); //Set graphics mode to 640x480 Virtual=create_bitmap(SCREEN_W,SCREEN_H); //Create virtual screen double buffer animation } void Game_Init(){ //Set the ojects on the screen ship.x=SCREEN_W/2-5; ship.y=SCREEN_H/2; puck.x=SCREEN_W/2; puck.y=SCREEN_H/2; } void Input(){ //Process inputs from the keyboard if(key[KEY_LEFT]) ship.angle-=itofix(ROTATE_RATE); if(key[KEY_RIGHT]) ship.angle+=itofix(ROTATE_RATE); if(key[KEY_UP]){ ship.xvel+=fixtof(fsin(ship.angle))*SPEED; ship.yvel-=fixtof(fcos(ship.angle))*SPEED; } } void Update_Object(OBJECT *object){ //Apply friction to objects object->xvel*=FRICTION; object->yvel*=FRICTION; //Move the objects according to their x-y velocities object->x+=object->xvel; object->y+=object->yvel; //Get the screen coordinate (int) from the actual coordinate (float) object->sx=object->x; object->sy=object->y; //Keep objects within the boundries if(object->x<0) { object->x=0; object->xvel*=-1; } if(object->y<0) { object->y=0; object->yvel*=-1; } if(object->x>SCREEN_W) { object->x=SCREEN_W; object->xvel*=-1; } if(object->y>SCREEN_H) { object->y=SCREEN_H; object->yvel*=-1; } } void Draw_Objects(){ int i; for(i=0;i