#include #include #include "MyPad.h" #include "Sin.h" #include "Cos.h" #define OT_LENGTH 2 #define PACKETMAX 2048 #define PACKETMAX2 (PACKETMAX*24) #define ANIM_ADDRESS 0x80090000 #define SHIP_ADDRESS 0x800a8014 #define BALL_ADDRESS 0x800aa028 typedef struct { long x, y, vx, vy; int ang; u_char weapons; u_char health; } Ship; typedef struct { long x, y, vx, vy; u_char countDown, connected; } Ball; typedef struct { int x[256], y[256], vx[256], vy[256]; u_char age[256]; int first, last; } Particle; GsOT WorldOT[2]; GsOT_TAG OTTags[2][1< 359) ship.ang -= 360; else { if (ship.ang < 0) ship.ang += 360; } if (pad & PADLX) { ship.vx += intSin[ship.ang]; ship.vy -= intCos[ship.ang]; for (i=0; i<1; i++) { thrust.x[thrust.last & 255] = ship.x-intSin[ship.ang]*32; thrust.y[thrust.last & 255] = ship.y+intCos[ship.ang]*32; thrust.vx[thrust.last & 255] = (rand() & 4095)-intSin[ship.ang]-2048; thrust.vy[thrust.last & 255] = (rand() & 4095)+intCos[ship.ang]-2048; thrust.age[thrust.last & 255] = 31; thrust.last++; } } dx = (ship.x-ball.x)>>6; dy = (ship.y-ball.y)>>6; dis = IntSqrt(dx*dx+dy*dy); force = dis-4096; if (force<0) force = 0; if (dis<1) dis = 1; ball.vx += force*dx/dis; ball.vy += force*dy/dis; ship.vx -= force*dx/dis; ship.vy -= force*dy/dis; ball.x += ball.vx; ball.y += ball.vy; ball.vx = (ball.vx*15)>>4; ball.vy = ((ball.vy+2048)*15)>>4; shipSprite.u = u[frame]; shipSprite.v = v[frame++]; shipSprite.x = ship.x>>12; shipSprite.y = ship.y>>12; shipSprite.rotate = ship.ang<<12; ship.y += ship.vy>>1; ship.x += ship.vx>>1; if (ship.y>510<<12 || ship.y<0) { ship.y -= ship.vy>>1; ship.vy = -ship.vy>>1; } if (ship.x>639<<12 || ship.x<0) { ship.x -= ship.vx>>1; ship.vx = -ship.vx>>1; } ship.vy += 512; for (i=thrust.first; i>12); box.y = (short )(thrust.y[i & 255]>>12); box.g = thrust.age[i & 255]<<3; thrust.x[i & 255] += thrust.vx[i & 255]<<2; thrust.y[i & 255] += thrust.vy[i & 255]<<2; thrust.age[i & 255]--; if (thrust.age[i & 255] == 0) thrust.first++; GsSortBoxFill(&box, &WorldOT[activeBuff], 1); } GsSortSprite(&shipSprite, &WorldOT[activeBuff], 0); ballSprite.u = ((frame>>1) & 3)*48 + 64; ballSprite.x = ball.x>>12; ballSprite.y = ball.y>>12; GsSortSprite(&ballSprite, &WorldOT[activeBuff], 0); if (frame==13) shipSprite.scalex = -ONE; if (frame==24) { frame = 0; shipSprite.scalex = ONE; } VSync(0); ResetGraph(1); GsSwapDispBuff(); GsDrawOt(&WorldOT[activeBuff]); } while ((pad & PADLselect) == 0); return(0); } void ProperInitialiseTexture(long TIMdata, GsIMAGE *imageInfo) { RECT rect; GsGetTimInfo((u_long *)(TIMdata+4), imageInfo); rect.x = imageInfo->px; rect.y = imageInfo->py; rect.w = imageInfo->pw; rect.h = imageInfo->ph; LoadImage(&rect, imageInfo->pixel); if ((imageInfo->pmode>>3) & 0x01) { rect.x = imageInfo->cx; rect.y = imageInfo->cy; rect.w = imageInfo->cw; rect.h = imageInfo->ch; LoadImage(&rect, imageInfo->clut); } DrawSync(0); } void InitGame(void) { int i; SetVideoMode(MODE_PAL); GsInitGraph(640, 512, 5, 1, 0); GsDISPENV.screen.h = 255; GsDISPENV.screen.y = 16; GsDRAWENV.isbg = 1; GsDRAWENV.r0 = 0; GsDRAWENV.g0 = 0; GsDRAWENV.b0 = 0; GetPadBuf(&bb0, &bb1); for (i = 0; i < 2; i++) { WorldOT[i].length = OT_LENGTH; WorldOT[i].org = OTTags[i]; } GsClearOt(0,0,&WorldOT[0]); GsClearOt(0,0,&WorldOT[1]); } int IntSqrt(register int n) { register int i; register long k0, k1, nn; for (nn = i = n, k0 = 2; i > 0; i >>= 2, k0 <<= 1) ; nn <<= 2; for (;;) { k1 = (nn / k0 + k0) >> 1; if (((k0 ^ k1) & ~1) == 0) break; k0 = k1; } return (int )((k1 + 1) >> 1); } u_long ReadPad(void) { return(~(*(bb0+3) | *(bb0+2) << 8 | *(bb1+3) << 16 | *(bb1+2) << 24)); }