[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Linroids





Group-
I've added some code to control our ship.  Still no input, graphics
routines.  Anyone?
-Brett

int action;
enum {TURN_RIGHT,TURN_LEFT,THRUST};
#define SHIP_NUM_DIRECTIONS 8
#define SHIP_MAX_VELOCITY 10
int SHIP_THRUST_X[SHIP_NUM_DIRECTIONS]={0,1,1,1,0,-1,-1,-1};
int SHIP_THRUST_Y[SHIP_NUM_DIRECTIONS]={-1,-1,0,1,1,1,0,-1};
struct ship_t
{
     int x;
     int y;
     int vx;
     int vy;
     int direction;
} ship;
void process_input()
{
     switch (action){
     case TURN_LEFT:
       ship.direction--;
       ship.direction%=SHIP_NUM_DIRECTIONS;
       break;
     case TURN_RIGHT:
       ship.direction++;
       ship.direction%=SHIP_NUM_DIRECTIONS;
       break;
     case THRUST:
       ship.vx+=SHIP_THRUST_X[ship.direction];
       ship.vy+=SHIP_THRUST_Y[ship.direction];
       if (ship.vx>SHIP_MAX_VELOCITY) ship.vx=SHIP_MAX_VELOCITY;
       if (ship.vy>SHIP_MAX_VELOCITY) ship.vy=SHIP_MAX_VELOCITY;
       if (ship.vx<-SHIP_MAX_VELOCITY) ship.vx=-SHIP_MAX_VELOCITY;
       if (ship.vy<-SHIP_MAX_VELOCITY) ship.vy=-SHIP_MAX_VELOCITY;
       break;
     default:
     }
}