/* ======================================= Box Game By Eddie Harrison Copyright (C) 1999 24/7 games design All Rights Reserved ======================================= */ /* ============== INCLUDES ============== */ #include "libps.h" // Playstation libary file #include "pad.h" // pad reading file /* ============= DEFINES ============= */ #define OT_LENGTH 2 // Ordering table legnth #define SCREENW 320 // Screen height #define SCREENH 256 // Screen width #define PI 3.14159265 // define the value of pi #define TRUE 1 #define FALSE 0 /* ============= GLOBALS ============= */ GsOT WorldOT[2]; // Two Ordering Tables GsOT_TAG OTTag[2][1<bullet.move == 0) { tcraft->bullet.box.x = tcraft->aim.line.x1; tcraft->bullet.box.y = tcraft->aim.line.y1; } if (tcraft->bullet.box.x > SCREENW) { tcraft->bullet.launch = 0; tcraft->bullet.move = -1; } if (tcraft->bullet.box.x < 0) { tcraft->bullet.launch = 0; tcraft->bullet.move = -1; } if (tcraft->bullet.box.y > SCREENH) { tcraft->bullet.launch = 0; tcraft->bullet.move = -1; } if (tcraft->bullet.box.y < 0) { tcraft->bullet.launch = 0; tcraft->bullet.move = -1; } tcraft->bullet.move ++; tcraft->bullet.box.x += (tcraft->bullet.move * SIN[tcraft->bullet.angle]); tcraft->bullet.box.y -= (tcraft->bullet.move * COS[tcraft->bullet.angle]); } /* ================ UPDATE AIM ================ */ void update_aim (CRAFT *tcraft) { tcraft->aim.line.x0 = tcraft->box.x + (tcraft->box.w / 2); tcraft->aim.line.y0 = tcraft->box.y + (tcraft->box.h / 2); tcraft->aim.line.x1 = (tcraft->aim.line.x0 + (8 * SIN[tcraft->aim.angle])); tcraft->aim.line.y1 = (tcraft->aim.line.y0 - (8 * COS[tcraft->aim.angle])); } /* ==================== UPDATE EXPLODE ==================== */ void update_explode (CRAFT *tcraft) { int i; explode = FALSE; for (i = 0; i < 25; i++) { if (explo[i].r > 5) { explo[i].r -= 1; explode = TRUE; } expposx[i] += expplusx[i]; expposy[i] += expplusy[i]; expangle1[i] += exprotate[i]; expangle2[i] += exprotate[i]; if (expangle1[i] > 360) expangle1[i] = 1; if (expangle2[i] > 360) expangle2[i] = 1; explo[i].x0 = expposx[i]; explo[i].y0 = expposy[i]; explo[i].x1 = (explo[i].x0 + (12 * SIN[expangle1[i]])); explo[i].y1 = (explo[i].y0 - (12 * COS[expangle1[i]])); } if (tcraft->aim.line.r > 10) tcraft->aim.line.r -= 10; if (tcraft->aim.line.g > 10) tcraft->aim.line.g -= 10; if (tcraft->aim.line.b > 10) tcraft->aim.line.b -= 10; if (tcraft->box.w > 1) { tcraft->box.w -= 2; tcraft->box.h -= 2; tcraft->box.x = tcraft->box.x + 1; tcraft->box.y = tcraft->box.y + 1; } for (i = 0; i < 25; i++) GsSortLine(&explo[i],&WorldOT[activebuff],0); } /* ================= WRAP AROUND ================= */ void wrap_around (CRAFT *tcraft) { if (tcraft->box.x < (0 - tcraft->box.w)) tcraft->box.x = 319; if (tcraft->box.x > 320) tcraft->box.x = (1 - tcraft->box.w); if (tcraft->box.y < (0 - tcraft->box.h)) tcraft->box.y = 255; if (tcraft->box.y > 256) tcraft->box.y = (1 - tcraft->box.h); } /* ========================= COLLISION DETECTION ========================= */ int check_for_collision (GsBOXF *col_box1,GsBOXF *col_box2) { int ax,ay; int bx,by; ax = (col_box1->x - col_box2->x); ay = (col_box1->y - col_box2->y); bx = (col_box2->x - col_box1->x); by = (col_box2->y - col_box1->y); if ((ax < col_box2->w && ay < col_box2->h) && (bx < col_box1->w && by < col_box1->h)) { return(1); } else { return(0); } } /* ========== MOVE ========== */ void move () { if (padstatus & PADcross) { if (box1.bullet.launch == 0) { box1.bullet.launch = 1; box1.bullet.angle = box1.aim.angle; } } if (padstatus & PADleft) { box1.box.x--; } if (padstatus & PADright) { box1.box.x++; } if (padstatus & PADup) { box1.box.y--; } if (padstatus & PADdown) { box1.box.y++; } if (padstatus & PADR1) { box1.aim.angle += 5; if (box1.aim.angle > 360) box1.aim.angle = 0; } if (padstatus & PADR2) { box1.aim.angle += 5; if (box1.aim.angle > 360) box1.aim.angle = 0; } if (padstatus & PADL1) { box1.aim.angle -= 5; if (box1.aim.angle < 0) box1.aim.angle = 360; } if (padstatus & PADL2) { box1.aim.angle -= 5; if (box1.aim.angle < 0) box1.aim.angle = 360; } if (padstatus & PADstart) { } if (padstatus & PAD2cross) { if (box2.bullet.launch < 1) { box2.bullet.launch = 1; box2.bullet.angle = box2.aim.angle; } } if (padstatus & PAD2left) { box2.box.x--; } if (padstatus & PAD2right) { box2.box.x++; } if (padstatus & PAD2up) { box2.box.y--; } if (padstatus & PAD2down) { box2.box.y++; } if (padstatus & PAD2R1) { box2.aim.angle += 5; if (box2.aim.angle > 360) box2.aim.angle = 0; } if (padstatus & PAD2R2) { box2.aim.angle += 5; if (box2.aim.angle > 360) box2.aim.angle = 0; } if (padstatus & PAD2L1) { box2.aim.angle -= 5; if (box2.aim.angle < 0) box2.aim.angle = 360; } if (padstatus & PAD2L2) { box2.aim.angle -= 5; if (box2.aim.angle < 0) box2.aim.angle = 360; } if (padstatus & PAD2start) { } } /* ==================== DRAW WORLD ==================== */ void draw_world () { DrawSync(0); // wait for end of drawing hsyncs = VSync(0); // get number of hsyncs FntFlush(0); FntFlush(1); GsSwapDispBuff(); // Swap display buffers GsSortClear(0,0,0, &WorldOT[activebuff]); // Register Clear in OT GsDrawOt(&WorldOT[activebuff]); // Draw the OT activebuff = GsGetActiveBuff(); // find out which buffer is active GsSetWorkBase((PACKET *)Packet[activebuff]); // set packet work base GsClearOt(0, 0, &WorldOT[activebuff]); // clear the ordering table padstatus = padread(); // get the status of the control pads } /* ====================== INITIALISE BOX 1 ====================== */ void init_box1 () { init_box (&box1.box, 10, 128, 20, 20, 143, 54, 143, 1<<25); init_line (&box1.aim.line, 20, 138, 20, 136, 200, 200, 200, 1<<25); init_box (&box1.bullet.box, -200, -200, 2, 2, 245, 0, 20, 1<<25); box1.bullet.move = 0; box1.aim.angle = 0; box1.bullet.angle = 0; box1.bullet.launch = 0; box1.score = 0; box1.aim.angle = 0; } /* ==================== I N I T I A L I S E P L A Y E R 2 ==================== */ void init_box2 () { init_box (&box2.box, 290, 128, 20, 20, 10, 200, 8, 1<<25); init_line (&box2.aim.line, 300, 138, 300, 130, 0, 0, 2000, 1<<25); init_box (&box2.bullet.box, -200, -200, 1, 1, 200, 200, 200, 1<<25); box2.bullet.move = 0; box2.aim.angle = 0; box2.bullet.angle = 0; box2.bullet.launch = 0; box2.score = 0; box2.aim.angle = 0; } /* ==================== I N I T I A L I S E E X P L O D E ==================== */ void init_explode () { int i; for (i=0; i<25; i++) { init_line (&explo[i], 160, 118, 160, 137, 200, 0, 0, 1 << 25 ); expplusx[i] = ((rand()%10)-5); expplusy[i] = ((rand()%10)-5); expangle1[i] = 0; expangle2[i] = 180; exprotate[i] = ((rand()%8) + 6); expposx[i] = 160; expposy[i] = 128; } } /* ==================== I N I T I A L I S E S T A R S ==================== */ void init_stars () { int count; for (count = 0; count < 65; count++) init_box (&stars[count], rand()%320, rand()%256, 1, 1, 243, 254, 255, 1<<24); for (count = 0; count < 35; count++) init_box (&big_stars[count], rand()%320, rand()%256, 2, 2, 243, 254, 255, 1<<24); } /* ==================== I N I T I A L I S E L O O K - UP TABLES ==================== */ void init_look_up_tables () { int count; for (count = 0; count < 361; count ++) { SIN[count] = sin(2 * PI * count / 360); COS[count] = cos(2 * PI * count / 360); } } /* ==================== I N I T I A L I S E L I N E ==================== */ void init_line (GsLINE *line, int x0, int y0, int x1, int y1, int r, int g, int b, u_long attri ) { line->x0 = x0; // set screenposition of line line->y0 = y0; line->x1 = x1; // set screenposition of line // set width and height of box line->y1 = y1; line->r = r; // set RGB values of line line->g = g; line->b = b; line->attribute = attri; // set line attribute to specify colour depth } /* ==================== I N I T I A L I S E B O X ==================== */ void init_box (GsBOXF *box, int x, int y, int w, int h, int r, int g, int b, u_long attri ) { box->x = x; // set screenposition of box box->y = y; box->w = w; // set width and height of box box->h = h; box->r = r; // set RGB values of box box->g = g; box->b = b; box->attribute = attri; // set line attribute to specify colour depth } /* ===================== I N I T I A L I S E G R A P H I C S ===================== */ void init_graphics() { int count; SetVideoMode(MODE_PAL); // set graphics mode to PAL 320x256 GsInitGraph(SCREENW, SCREENH, 4, 0, 0); // set resolution and mode GsDefDispBuff(0, 0, 0, SCREENH); // set position of the 2 display buffers for (count = 0 ; count < 2 ; count++) // initialise and clear the { // ordering tables WorldOT[count].length = OT_LENGTH; WorldOT[count].org = OTTag[count]; GsClearOt(0,0,&WorldOT[count]); } FntLoad(960, 256); // loads the debug font into frame buffer print [0] = FntOpen(8, 10, SCREENH, SCREENW, 0, 512); // font printing location print [1] = FntOpen(173, 10, SCREENH, SCREENW, 0, 512); // font printing location print [2] = FntOpen(100, 115, 148, 18, 1, 512); // font printing location padinit (); // set up control pads init_box1 (); // initialise player 1 init_box2 (); // initialise player 2 init_look_up_tables (); // initialise look-up tables init_explode (); init_stars (); activebuff = GsGetActiveBuff(); // find out which buffer is active GsSetWorkBase((PACKET *)Packet[activebuff]); // set packet work base } /* ==================== P A D I N I T ==================== */ void padinit () { GetPadBuf(&bb0, &bb1); } /* ==================== P A D R E A D ==================== */ u_long padread() { return(~(*(bb0+3) | *(bb0+2) << 8 | *(bb1+3) << 16 | *(bb1+2) << 24)); }