#include #include "pad.h" #include "invs.h" #define OT_LENGTH 1 #define FRAME_X 320 #define FRAME_Y 240 #define WALL_X (FRAME_X-INV_SIZE) #define WALL_Y (FRAME_Y-INV_SIZE) #define NO_OF_SPRITES 42 #define ORIG_ALIEN_X 25 #define ORIG_ALIEN_Y 20 #define INV_SIZE 16 #define GAP 4 #define BULLET_SPEED 4 GsOT WorldOT[2]; GsOT_TAG OTTags[2][1<cy!=0) GsSortFastSprite(sp,&WorldOT[activeBuff],0); } DrawSync(0); VSync(0); GsSwapDispBuff(); GsSortClear(0,0,0,&WorldOT[activeBuff]); GsDrawOt(&WorldOT[activeBuff]); FntPrint("Score: %d",score); FntFlush(-1); } return(0); } static void init_prim() { GsSPRITE *sp; u_short tpage; RECT rect; int i; rect.x=640; rect.y=0; rect.w=INV_SIZE/4; rect.h=INV_SIZE; LoadImage(&rect,inv16x16); tpage=GetTPage(0,0,640,0); for (i=0;i<32;i++) { rect.x=0; rect.y=480+i; rect.w=256; rect.h=1; LoadImage(&rect,invcolor[i]); } for (sp=sprt,i=0;iattribute=0; sp->w=INV_SIZE; sp->h=INV_SIZE; sp->tpage=tpage; sp->u=0; sp->v=0; sp->cx=0; sp->cy=480+(i%32); sp->r=sp->g=sp->b=0xff; sp->mx=0; sp->my=0; sp->scalex=ONE; sp->scaley=ONE; sp->rotate=0; } } static long pad_read(long n) { u_long padd=PadRead(1); if (padd&PADLleft) left=1; else left=0; if (padd&PADLright) right=1; else right=0; if (padd&PADLup) up=1; else up=0; if (padd&PADLdown) down=1; else down=0; if (padd&PADRdown) bullet_attached=0; if (padd&PADselect) n=-1; return(n); } static u_long PadRead(long id) { return(~(*(bb0+3)|*(bb0+2)<<8|*(bb1+3)<<16|*(bb1+2)<<24)); } void init_aliens(void) { u_int alien_x,alien_y,i; GsSPRITE *sp; delay=20; x_vel=2; y_vel=8; alien_x=ORIG_ALIEN_X; alien_y=ORIG_ALIEN_Y; for (sp=sprt,i=0;ix=alien_x; sp->y=alien_y; alien_x=alien_x+(INV_SIZE+GAP); if (i%10==9) { alien_x=ORIG_ALIEN_X; alien_y+=(INV_SIZE+GAP); } } sp->x=100; /* Player */ sp->y=200; sp->cy=487; sp++; sp->x=100; /* Bullet */ sp->y=184; sp->cy=482; } void update_aliens(void) { u_char i,bounce; int save_x,save_y; GsSPRITE *sp; bounce=0; frame++; if (frame>=delay) { frame=0; for (sp=sprt,i=0;ix+=x_vel; if (sp->cy!=0 & (sp->x>=WALL_X | sp->x<=0)) bounce=1; } if (bounce) { x_vel=-x_vel; bounce=0; for (sp=sprt,i=0;iy+=y_vel; if (sp->cy!=0 &(sp->y>=WALL_Y | sp->y<=0)) bounce=1; } if (bounce) y_vel=-y_vel; } } sp=sprt+NO_OF_SPRITES-2; /* This sprite is player sprite! */ if (left) sp->x-=2; if (sp->x<0) sp->x+=2; if (right) sp->x+=2; if (sp->x>=WALL_X) sp->x-=2; save_x=sp->x; if (bullet_attached) { sp++; sp->x=save_x; sp->cy=500; } else { save_y=sp->y; sp++; sp->cy=480+(frame%32); sp->y-=BULLET_SPEED; if (sp->y<=0) { bullet_attached=1; sp->x=save_x; sp->y=save_y-INV_SIZE; } } } void check_hit(void) { int bullet_x,bullet_y,gap_x,gap_y,i; GsSPRITE *sp; sp=sprt+NO_OF_SPRITES-1; /* This is the bullet */ bullet_x=sp->x; bullet_y=sp->y; for (sp=sprt,i=0;ix); gap_y=(bullet_y-sp->y); if (gap_x>-INV_SIZE && gap_x-INV_SIZE && gap_ycy!=0 && bullet_attached==0) { bullet_attached=1; sp->cy=0; sp=sprt+NO_OF_SPRITES-2; bullet_x=sp->x; bullet_y=sp->y-INV_SIZE; sp++; sp->x=bullet_x; sp->y=bullet_y; score++; if (score%(NO_OF_SPRITES-2)==0) { init_aliens(); init_prim(); } if (delay>1 & (score%2==1)) delay--; break; } } }