// --- katapila -------------------------------------------------------------- #include #include #include #include #include "pad.h" #include "dms.c" #define IMPCTFNT_TIM 0x80090000 #define LOGO_TIM 0x800948c0 #define CC_DMS 0x800993e0 #define CC_VB 0x8009aac8 #define CC_VH 0x800ce078 #define SOUND_VB 0x800cfa98 #define SOUND_VH 0x800dd3d8 #define BLUR_TIM 0x800dedf8 #define SCENE_TIM 0x800e0018 #define HEAD_TIM 0x800e3038 #define PLATFORM_TIM 0x800e3358 #define TAIL_TIM 0x800e33d8 #define BG_TIM 0x800e36f8 #define BG2_TIM 0x800eb738 #define BG3_TIM 0x800f3788 #define SHADOW_TIM 0x800f57d8 #define LOGOSHAD_TIM 0x800f5b78 #define BG5_TIM 0x800f8e48 #define END_OF_DATA 0x80100e98 #define SCREEN_WIDTH 320 #define SCREEN_HEIGHT 256 #define SHIP_SIZE 16 #define FLOOR_GAP 32 #define FLOOR_WIDTH 24 #define FLOOR_HEIGHT 4 #define MAX_FLOORS (SCREEN_HEIGHT / FLOOR_GAP) #define MAX_SPARKS 100 #define SHIP_ACCEL (FLT (0.5)) #define SHIP_DECEL (FLT (0.2)) #define SHIP_GRAV (FLT (0.2)) #define SHIP_BOUNCE (FLT (7.0)) #define NUM_TAILS 30 #define OT_LEN 4 #define MAX_PACKETS (192*1024) //-------------------------------------------------------------- typedef signed long flt; #define FIXED_POINT 16 #define FLT_ONE ((flt) (1 << FIXED_POINT)) #define FLT(x) ((flt) ((x) * FLT_ONE)) #define FLT2INT(x) (((int) (x)) >> FIXED_POINT) #define INT2FLT(x) (((flt) (x)) << FIXED_POINT) //-------------------------------------------------------------- typedef enum { IMPCTFNT_SPRITE = 0, LOGO_SPRITE, SCENE_SPRITE, BLUR_SPRITE, HEAD_SPRITE, TAIL_SPRITE, PLATFORM_SPRITE, BG_SPRITE, BG2_SPRITE, BG3_SPRITE, BG5_SPRITE, SHADOW_SPRITE, LOGOSHAD_SPRITE, NUM_SPRITES } SPRITE_DATA; typedef enum { STATE_FRONTEND = 0, STATE_INTRO, STATE_LEVELSTART, STATE_GAME, STATE_PAUSE, STATE_RESULTS, NUM_GAME_STATES } STATE; typedef struct { int sprite; int * xoff; int height; int space; } FONT_DATA; typedef struct { flt x; flt y; } FLTXY; typedef struct { int x; int y; int move; } FLOOR; typedef struct { GsGLINE line; int x0; int y0; int x1; int y1; int ax; int ay; } SPARK; //-------------------------------------------------------------- PACKET out_packet[2][MAX_PACKETS]; GsOT othWorld[2]; GsOT_TAG otWorld[2][1< px; rect.y = tim1 -> py; rect.w = tim1 -> pw; rect.h = tim1 -> ph; LoadImage (&rect, tim1 -> pixel); if ((tim1 -> pmode>>3) & 0x01) { rect.x = tim1 -> cx; rect.y = tim1 -> cy; rect.w = tim1 -> cw; rect.h = tim1 -> ch; LoadImage(&rect, tim1 -> clut); } if ((tim1 -> pmode & 3) == 0) tim1 -> pw *= 4; else if ((tim1 -> pmode & 3) == 1) tim1 -> pw *= 2; DrawSync (0); return 0; } //-------------------------------------------------------------- void Init() { GetPadBuf(&bb0, &bb1); SetVideoMode (MODE_PAL); GsInitGraph (SCREEN_WIDTH, SCREEN_HEIGHT, GsNONINTER|GsOFSGPU, 0, 0); GsDefDispBuff (0, 0, 0, SCREEN_HEIGHT); GsDISPENV.screen.x = 0; GsDISPENV.screen.y = 20; GsDISPENV.screen.w = SCREEN_WIDTH; GsDISPENV.screen.h = SCREEN_HEIGHT; othWorld[0].length = OT_LEN; othWorld[1].length = OT_LEN; othWorld[0].org = otWorld[0]; othWorld[1].org = otWorld[1]; GsClearOt (0,0,&othWorld[0]); GsClearOt (0,0,&othWorld[1]); LoadTIM (IMPCTFNT_TIM, &spritedata [IMPCTFNT_SPRITE]); LoadTIM (LOGO_TIM, &spritedata [LOGO_SPRITE]); LoadTIM (SCENE_TIM, &spritedata [SCENE_SPRITE]); LoadTIM (BLUR_TIM, &spritedata [BLUR_SPRITE]); LoadTIM (HEAD_TIM, &spritedata [HEAD_SPRITE]); LoadTIM (TAIL_TIM, &spritedata [TAIL_SPRITE]); LoadTIM (PLATFORM_TIM, &spritedata [PLATFORM_SPRITE]); LoadTIM (BG_TIM, &spritedata [BG_SPRITE]); LoadTIM (BG2_TIM, &spritedata [BG2_SPRITE]); LoadTIM (BG3_TIM, &spritedata [BG3_SPRITE]); LoadTIM (SHADOW_TIM, &spritedata [SHADOW_SPRITE]); LoadTIM (LOGOSHAD_TIM, &spritedata [LOGOSHAD_SPRITE]); LoadTIM (BG5_TIM, &spritedata [BG5_SPRITE]); vab1 = SsVabTransfer ((u_char *)SOUND_VH, (u_char *)SOUND_VB, -1, 1); SsSetMVol (127,127); DMSInit(&d, 0, DMS_PAL, (unsigned char *)CC_VH, (unsigned char *)CC_VB, (unsigned char *)CC_DMS); DMSSetMasterVol (&d, 160); srand (VSync (-1)); font.sprite = IMPCTFNT_SPRITE; font.xoff = &fontpos[0]; font.height = 29; font.space = 8; state = STATE_INTRO; febg = BG2_SPRITE; // VSyncCallback (&FrameFunc); hiscore[0] = 0; hiscore[1] = 0; hiscore[2] = 0; hiscore[3] = 0; } //-------------------------------------------------------------- void SetDefaultSpriteData (GsSPRITE * sprite, int data) { sprite -> u = spritedata [data].px % 64; sprite -> v = spritedata [data].py % 256; sprite -> w = spritedata [data].pw; sprite -> h = spritedata [data].ph; sprite -> cx = spritedata [data].cx; sprite -> cy = spritedata [data].cy; if ((spritedata [data].pmode & 3) == 0) sprite -> u *= 4; else if ((spritedata [data].pmode & 3) == 1) sprite -> u *= 2; sprite -> tpage = GetTPage (spritedata [data].pmode, 0, spritedata [data].px, spritedata [data].py); sprite -> attribute = ((spritedata [data].pmode & 3)<< 24); sprite -> mx = 0; sprite -> my = 0; sprite -> scalex = ONE; sprite -> scaley = ONE; sprite -> rotate = 0; sprite -> r = 128; sprite -> g = 128; sprite -> b = 128; } //-------------------------------------------------------------- int GetCharXOff (char c) { return (*(font.xoff + (c-33))); } //-------------------------------------------------------------- int GetCharYOff (char c) { int ret = 0; if (c >= '8') { ret += font.height; } if (c >= 'K') { ret += font.height; } if (c >= '\\') { ret += font.height; } if (c >= 's') { ret += font.height; } return ret; } //-------------------------------------------------------------- int GetCharWidth (char c) { if (c < 33) { return font.space; } else if (c == '7') { return 14; } else if (c == 'J') { return 14; } else if (c == '[') { return 7; } else if (c == 'r') { return 9; } else { return (GetCharXOff (c+1) - GetCharXOff (c)); } } //-------------------------------------------------------------- int GetFontHeight (void) { return font.height; } //-------------------------------------------------------------- int GetStringLen (char * string) { int len = 0; char c; while (*string) { c = *string; len += GetCharWidth (c); string++; } return len; } //-------------------------------------------------------------- void DrawText (char * string, int x, int y, int r, int g, int b) { int temp; int width; int u,v; char cur; GsSPRITE sprite; SetDefaultSpriteData (&sprite, font.sprite); if (r>=0) sprite.attribute |= 1 << 28 | 1 << 30; else { sprite.attribute |= 2 << 28 | 1 << 30; r = -r; g = -g; b = -b; } u = sprite.u; v = sprite.v; if (x < 0 || x > SCREEN_WIDTH) { x = (SCREEN_WIDTH - (GetStringLen (string) )) / 2; } if (y < 0 || y > SCREEN_HEIGHT) { y = (SCREEN_HEIGHT - GetFontHeight()) / 2; } sprite.x = x; sprite.y = y; sprite.r = r; sprite.g = g; sprite.b = b; while (*string) { cur = *string; if (cur >= 33) { sprite.u = u + GetCharXOff (cur); sprite.v = v + GetCharYOff (cur); sprite.w = GetCharWidth (cur); sprite.h = GetFontHeight () - 1; GsSortFastSprite (&sprite, &othWorld [nBuffer], 0); sprite.x += sprite.w; } else { sprite.x += font.space; } string++; } } //-------------------------------------------------------------- int WasButtonPressed (int key) { if ((PADstatus & key) && (!(PADlast & key))) { return 1; } else { return 0; } } //-------------------------------------------------------------- int RectInRect (RECT * r1, RECT * r2) { int ret=0; if ((r1->x < (r2->x + r2->w)) && ((r1->x + r1->w) > r2->x)) { if ((r1->y < (r2->y + r2->h)) && ((r1->y + r1->h) > r2->y)) { ret=1; } } return ret; } //-------------------------------------------------------------- void StartSpark (int x, int y) { int count=0; while (((spark[count].ax) || (spark[count].ay)) && (count0) spark[count].ax--; else if(spark[count].ax<0) spark[count].ax++; if(spark[count].ay>0) spark[count].ay--; else if(spark[count].ay<0) spark[count].ay++; spark[count].x1=spark[count].x0; spark[count].y1=spark[count].y0; spark[count].x0+=spark[count].ax; spark[count].y0+=spark[count].ay; } } } //-------------------------------------------------------------- int AddFloor (void) { int nCount; nCount = 0; while (floors [nCount].x > -1) { nCount++; } if (nCount < MAX_FLOORS) { floors [nCount].x = rand () % (SCREEN_WIDTH - FLOOR_WIDTH); } return nCount; } //-------------------------------------------------------------- void SetFloorSpeed (int nCount) { if (diff == 0) floors [nCount].move = 0; if (diff == 1) floors [nCount].move = (rand() % 3) -1; if (diff == 2) floors [nCount].move = (rand() % 5) -3; if (diff == 3) floors [nCount].move = (rand() % 7) -4; } //-------------------------------------------------------------- void InitGame (void) { int nCount; gametime = 0; state = STATE_GAME; score = 0; pause = 0; shipx = FLT ((SCREEN_WIDTH - SHIP_SIZE) / 2); shipy = FLT ((SCREEN_HEIGHT - SHIP_SIZE) / 2); shipy = -shipy; shipax = 0; shipay = -SHIP_BOUNCE; mapy = -SCREEN_HEIGHT; for (nCount = 0; nCount < NUM_TAILS; nCount++) { tails [nCount].x = shipx; tails [nCount].y = shipy; } for (nCount = 0; nCount < MAX_FLOORS; nCount++) { floors [nCount].x = rand () % (SCREEN_WIDTH - FLOOR_WIDTH); floors [nCount].y = nCount * FLOOR_GAP; SetFloorSpeed (nCount); } } //-------------------------------------------------------------- #define SPACE_AREA 1024 #define SPACE_xTURN (FLT (0.05)) #define SPACE_YTURN (FLT (0.025)) #define SPACE_MAX (FLT (6.0)) void DrawSpace (int timer) { static flt x = FLT (SPACE_AREA + (SPACE_AREA / 2) - (SCREEN_WIDTH / 2)); static flt y = FLT (SPACE_AREA + (SPACE_AREA / 2) - (SCREEN_HEIGHT / 2)); static flt ax; static flt ay; static flt dx = FLT (SPACE_AREA + (SPACE_AREA / 2) - (SCREEN_WIDTH / 2)); static flt dy = FLT (SPACE_AREA + (SPACE_AREA / 2) - (SCREEN_HEIGHT / 2)); GsSPRITE sprite; if (x > dx) ax -= SPACE_xTURN; else if (x < dx) ax += SPACE_xTURN; if (y > dy) ay -= SPACE_YTURN; else if (y < dy) ay += SPACE_YTURN; if (ax > SPACE_MAX) ax = SPACE_MAX; else if (ax < -SPACE_MAX) ax = -SPACE_MAX; if (ay > SPACE_MAX) ay = SPACE_MAX; else if (ay < -SPACE_MAX) ay = -SPACE_MAX; x += ax; y += ay; if (!(timer % 500)) { dx = FLT ((rand() % SPACE_AREA) + SPACE_AREA); dy = FLT ((rand() % SPACE_AREA) + SPACE_AREA); } SetDefaultSpriteData (&sprite, febg); sprite.r = 0; sprite.g = 128; sprite.b = 0; sprite.x = -((FLT2INT(x)) % spritedata [febg].pw); sprite.y = -((FLT2INT(y)) % spritedata [febg].ph); GsSortFastSprite (&sprite, &othWorld [nBuffer], 10); sprite.x += spritedata [febg].pw; GsSortFastSprite (&sprite, &othWorld [nBuffer], 10); sprite.x += spritedata [febg].pw; GsSortFastSprite (&sprite, &othWorld [nBuffer], 10); sprite.x -= spritedata [febg].pw * 2; sprite.y += spritedata [febg].ph; GsSortFastSprite (&sprite, &othWorld [nBuffer], 10); sprite.x += spritedata [febg].pw; GsSortFastSprite (&sprite, &othWorld [nBuffer], 10); sprite.x += spritedata [febg].pw; GsSortFastSprite (&sprite, &othWorld [nBuffer], 10); sprite.x -= spritedata [febg].pw * 2; sprite.y += spritedata [febg].ph; GsSortFastSprite (&sprite, &othWorld [nBuffer], 10); sprite.x += spritedata [febg].pw; GsSortFastSprite (&sprite, &othWorld [nBuffer], 10); sprite.x += spritedata [febg].pw; GsSortFastSprite (&sprite, &othWorld [nBuffer], 10); } //-------------------------------------------------------------- void FrontendLoop (void) { int nCount; static int centre; static int menu; static int init = 0; static int timer; GsSPRITE sprite; GsLINE line = {0, 16,16,304,16,255,255,255}; if (init == 0) { SetBlurParam (ONE, ONE, 0,64,64,64); init = 1; timer = 0; menu = 0; centre = 0; } DrawSpace (timer); if (!centre) { if (WasButtonPressed (PADLup)) { menu --; timer = 0; SsUtKeyOn (vab1, 6,0, 48, 0, 128, 128); } else if (WasButtonPressed (PADLdown)) { menu ++; timer = 0; SsUtKeyOn (vab1, 2,0, 48, 0, 128, 128); } if (menu < 0) menu = 4; if (menu > 4) menu = 0; } if (centre) { DrawText ("Centre screen", -1,32, 50,50,50); DrawText ("Use directional buttons", -1, 32*2, 100,100,100); DrawText ("to position screen", -1, 32*3, 100,100,100); DrawText ("Press X to accept", -1, 32*6, 100,100,100); sprintf (tempstring, "x:%d y:%d", GsDISPENV.screen.x, GsDISPENV.screen.y-20); DrawText (tempstring, -1, (32*4) + 16, 50,50,50); GsSortLine (&line, &othWorld [nBuffer], 0); line.x0 = 304; line.y0 = 240; GsSortLine (&line, &othWorld [nBuffer], 0); line.x1 = 16; line.y1 = 240; GsSortLine (&line, &othWorld [nBuffer], 0); line.x0 = 16; line.y0 = 16; GsSortLine (&line, &othWorld [nBuffer], 0); if (WasButtonPressed (PADcross)) { if ((PADstatus & PADL1) && (PADstatus & PADL2) && (PADstatus & PADR1) && (PADstatus & PADR2) && (GsDISPENV.screen.x == -11 && GsDISPENV.screen.y == -3)) { febg = BG_SPRITE; } if ((PADstatus & PADL1) && (PADstatus & PADL2) && (PADstatus & PADR1) && (PADstatus & PADR2) && (GsDISPENV.screen.x == -10 && GsDISPENV.screen.y == -2)) { febg = BG5_SPRITE; } timer = 0; centre = 0; SsUtKeyOn (vab1, 5,0, 64, 0, 128, 128); } if (WasButtonPressed (PADLleft)) GsDISPENV.screen.x--; if (WasButtonPressed (PADLright)) GsDISPENV.screen.x++; if (WasButtonPressed (PADLup)) GsDISPENV.screen.y--; if (WasButtonPressed (PADLdown)) GsDISPENV.screen.y++; if (GsDISPENV.screen.x < -11) GsDISPENV.screen.x = -11; if (GsDISPENV.screen.y < -3) GsDISPENV.screen.y = -3; } else if (timer < 400) { SetDefaultSpriteData (&sprite, LOGO_SPRITE); sprite.attribute |= 1 << 28 | 1 << 30; sprite.x = (SCREEN_WIDTH - sprite.w) >> 1; sprite.y = 20; GsSortFastSprite (&sprite, &othWorld [nBuffer], 0); SetDefaultSpriteData (&sprite, LOGOSHAD_SPRITE); sprite.attribute |= 2 << 28 | 1 << 30; sprite.x = (SCREEN_WIDTH - sprite.w) >> 1; sprite.y = 16; GsSortFastSprite (&sprite, &othWorld [nBuffer], 0); sprintf (tempstring, "Let's go!"); if (menu == 0) DrawText (tempstring, -1, 94, 150, 150, 150); else DrawText (tempstring, -1, 94, 50, 50, 50); sprintf (tempstring, "Difficulty: "); if (diff == 0) strcat (tempstring, "Easy"); else if (diff == 1) strcat (tempstring, "Normal"); else if (diff == 2) strcat (tempstring, "Hard"); else if (diff == 3) strcat (tempstring, "Very hard"); if (menu == 1) DrawText (tempstring, -1, 122, 150, 150, 150); else DrawText (tempstring, -1, 122, 50, 50, 50); sprintf (tempstring, "Music: "); if (music == 0) strcat (tempstring, "Off"); else if (music == 1) strcat (tempstring, "Low"); else if (music == 2) strcat (tempstring, "High"); if (menu == 2) DrawText (tempstring, -1, 150, 150, 150, 150); else DrawText (tempstring, -1, 150, 50, 50, 50); sprintf (tempstring, "Show score: "); if (disp == 1) strcat (tempstring, "Yes"); else if (disp == 0) strcat (tempstring, "No"); if (menu == 3) DrawText (tempstring, -1, 178, 150, 150, 150); else DrawText (tempstring, -1, 178, 50, 50, 50); sprintf (tempstring, "Centre screen"); if (menu == 4) DrawText (tempstring, -1, 206, 150, 150, 150); else DrawText (tempstring, -1, 206, 50, 50, 50); if (WasButtonPressed (PADRdown)) { if (menu == 0) { init = 0; InitGame (); } else if (menu == 1) { diff++; if (diff > 3) diff = 0; } else if (menu == 2) { music++; if (music > 2) music = 0; if (music == 1) DMSSetMasterVol (&d, 160); else if (music == 2) DMSSetMasterVol (&d, 255); else { DMSNoteKeyOffAll (&d); DMSSetMasterVol (&d, 0); } } else if (menu == 3) { disp++; if (disp > 1) disp = 0; } else if (menu == 4) { centre = 1; } SsUtKeyOn (vab1, 5,0, 64, 0, 128, 128); } } else if (timer < 800) { DrawText ("Best scores", -1, 24, 50,50,50); DrawText ("Easy",48, 32*2, 50,50,50); DrawText ("Normal", 48, 32*3, 50,50,50); DrawText ("Hard", 48, 32*4, 50,50,50); DrawText ("Very hard", 48, 32*5, 50,50,50); for (nCount = 0; nCount < 4; nCount++) { sprintf (tempstring, "%7.7d", hiscore [nCount]); DrawText (tempstring, 180, 32 * (nCount + 2), 100,100,100); } } else if (timer < 1200) { DrawText ("Game", -1, 32*1, 50,50,50); DrawText ("BEN JAMES", -1, 32*2, 100,100,100); DrawText ("meep42@clara.co.uk", -1, 32*3, 50,50,50); DrawText ("Music player", -1, 32*5, 50,50,50); DrawText ("ELLIOT LEE", -1, 32*6, 100,100,100); } timer ++; if (timer > 1400) { timer = 0; } if (WasButtonPressed (PADRdown) || WasButtonPressed (PADstart)) { timer = 0; } } //-------------------------------------------------------------- //-------------------------------------------------------------- #define DEAD_ZONE 32 void GetPlayerInput () { if (PADstatus & PADLleft) { shipax -= SHIP_ACCEL; } else if (PADstatus & PADLright) { shipax += SHIP_ACCEL; } } //-------------------------------------------------------------- void UpdatePlatforms (void) { int nCount; for (nCount = 0; nCount < MAX_FLOORS; nCount++) { if (floors [nCount].move > 0) { if ((floors [nCount].x + FLOOR_WIDTH + floors [nCount].move) < SCREEN_WIDTH) floors [nCount].x += floors [nCount].move; else floors [nCount].move = -floors [nCount].move; } else { if ((floors [nCount].x - floors [nCount].move) >= 0) floors [nCount].x += floors [nCount].move; else floors [nCount].move = -floors [nCount].move; } } } //-------------------------------------------------------------- void Collision (void) { int x; int y; int nCount; int explode; x = FLT2INT (shipx); y = FLT2INT (shipy); for (nCount = 0; nCount < MAX_FLOORS; nCount++) { if (floors [nCount].x > -1) { if (((x + SHIP_SIZE) > floors [nCount].x) && (x < (floors [nCount].x + FLOOR_WIDTH)) && ((y + SHIP_SIZE) > floors [nCount].y) && ((y + (SHIP_SIZE / 3)) < (floors [nCount].y + FLOOR_HEIGHT))) { shipay =- SHIP_BOUNCE; if (diff == 3) { SsUtKeyOn (vab1, 7,0, 48, 0, 64, 64); for (explode = 0; explode < MAX_SPARKS; explode ++) { StartSpark ((floors [nCount].x + (rand () % FLOOR_WIDTH)), (floors [nCount].y + (rand () % FLOOR_HEIGHT))); } floors [nCount].y -= (SCREEN_WIDTH + (FLOOR_HEIGHT * 2)); } else { SsUtKeyOn (vab1, 1,0, 32, 0, 64, 64); } } } } if (shipy > FLT (SCREEN_HEIGHT - SHIP_SIZE)) { shipay =- SHIP_BOUNCE; } } //-------------------------------------------------------------- void UpdateGame (void) { int nCount; score = -mapy - SCREEN_HEIGHT; if (WasButtonPressed (PADstart)) { pause = 1-pause; SsUtKeyOn (vab1, 5,0, 64, 0, 128, 128); } if (pause) { if (PADstatus & PADtriangle) { state = STATE_FRONTEND; SsUtKeyOn (vab1, 0,0, 48, 0, 128, 128); } } else { GetPlayerInput(); UpdatePlatforms(); shipay += SHIP_GRAV; shipx += shipax; shipy += shipay; if (shipax > FLT (0.0)) shipax -= SHIP_DECEL; else if (shipax < FLT (0.0)) shipax += SHIP_DECEL; if ((shipax < SHIP_DECEL) && (shipax > -SHIP_DECEL)) shipax = FLT (0.0); if (shipx < -FLT (0.0)) { shipx = FLT (0.0); shipax = -shipax; } else if (shipx > FLT (SCREEN_WIDTH - SHIP_SIZE)) { shipx = FLT (SCREEN_WIDTH - SHIP_SIZE); shipax = -shipax; } for (nCount = NUM_TAILS - 1; nCount > 0; nCount--) { tails [nCount] = tails [nCount-1]; } tails [0].x = shipx; tails [0].y = shipy; if (shipay > FLT (0.0)) { Collision (); } if (shipy < FLT (mapy + (SCREEN_HEIGHT / 2))) mapy -= 1; if (shipy < FLT (mapy + (SCREEN_HEIGHT / 3))) mapy -= 1; if (shipy < FLT (mapy + (SCREEN_HEIGHT / 4))) mapy -= 1; for (nCount = 0; nCount < MAX_FLOORS; nCount++) { if ((floors [nCount].y - mapy) > (SCREEN_HEIGHT)) { floors [nCount].x = rand () % (SCREEN_WIDTH - FLOOR_WIDTH); floors [nCount].y -= (SCREEN_WIDTH + (FLOOR_HEIGHT * 2)); SetFloorSpeed (nCount); } } gametime ++; if (((FLT2INT (tails [nCount].y) - mapy)) > SCREEN_HEIGHT) { SsUtKeyOn (vab1, 3,0, 32, 0, 128, 128); state = STATE_RESULTS; } UpdateSparks(); } } //-------------------------------------------------------------- void DrawFloors (void) { int nCount; GsSPRITE sprite; SetDefaultSpriteData (&sprite, SHADOW_SPRITE); sprite.attribute |= 2 << 28 | 1 << 30; sprite.r = 64; sprite.g = 64; sprite.b = 64; for (nCount = 0; nCount < MAX_FLOORS; nCount++) { sprite.x = floors [nCount].x; sprite.y = floors [nCount].y - mapy; GsSortSprite (&sprite, &othWorld[nBuffer], 4); } SetDefaultSpriteData (&sprite, PLATFORM_SPRITE); sprite.attribute |= 1 << 28 | 1 << 30; sprite.r = 64; sprite.g = 64; sprite.b = 64; switch (diff) { case 0: sprite.b = 100; break; case 1: sprite.g = 100; break; case 2: sprite.r = 100; sprite.b = 100; break; case 3: sprite.r = 100; break; default: break; } for (nCount = 0; nCount < MAX_FLOORS; nCount++) { sprite.x = floors [nCount].x; sprite.y = floors [nCount].y - mapy; GsSortSprite (&sprite, &othWorld[nBuffer], 3); } } //-------------------------------------------------------------- void DrawBG (void) { GsSPRITE sprite; SetDefaultSpriteData (&sprite, BG3_SPRITE); sprite.y = (-(mapy % sprite.h)) - sprite.h; switch (diff) { case 0: sprite.r = 0; sprite.g = 0; sprite.b = 128; break; case 1: sprite.r = 0; sprite.g = 64; sprite.b = 0; break; case 2: sprite.r = 128; sprite.g = 0; sprite.b = 128; break; case 3: sprite.r = 128; sprite.g = 0; sprite.b = 0; break; default: break; } while (sprite.y < SCREEN_HEIGHT) { sprite.x = 0; while (sprite.x < SCREEN_WIDTH) { GsSortSprite (&sprite, &othWorld[nBuffer], 10); sprite.x += sprite.w; } sprite.y += sprite.h; } } //-------------------------------------------------------------- void DrawKatapila (void) { int nCount; GsSPRITE sprite; SetDefaultSpriteData (&sprite, HEAD_SPRITE); sprite.x = FLT2INT (shipx); sprite.y = FLT2INT (shipy) - mapy; GsSortSprite (&sprite, &othWorld[nBuffer], 0); SetDefaultSpriteData (&sprite, TAIL_SPRITE); sprite.attribute |= 1 << 28 | 1 << 30; for (nCount = 1; nCount < NUM_TAILS - 1; nCount++) { if (!(nCount % 3)) { sprite.x = FLT2INT (tails [nCount].x); sprite.y = FLT2INT (tails [nCount].y) - mapy; sprite.r = (NUM_TAILS * 2) - (nCount * 2); sprite.g = sprite.r; sprite.b = sprite.r; GsSortSprite (&sprite, &othWorld[nBuffer], 1); } } } //-------------------------------------------------------------- void DrawGame (void) { DrawKatapila (); DrawSparks (); DrawFloors (); DrawBG (); if (disp) { sprintf (tempstring, "%7.7d", score); DrawText (tempstring, 16, SCREEN_HEIGHT - font.height, 32, 32, 32); sprintf (tempstring, "%7.7d", hiscore[diff]); DrawText (tempstring, SCREEN_WIDTH - 16 - GetStringLen (tempstring), SCREEN_HEIGHT - font.height, 32, 32, 32); } if (pause) { DrawText ("Paused", -1,-1, 100, 100, 100); } } //-------------------------------------------------------------- void ResultsLoop (void) { // DrawFloors (); mapy--; DrawBG (); DrawText ("Game over", -1, 32, 100, 100, 100); DrawText ("You fell off!", -1, 100, 50, 50, 50); sprintf (tempstring, "Your score: %7.7d", score); DrawText (tempstring, -1, 128, 75, 75, 75); DrawText ("Press X", -1, 200, 100 - (time % 50), 100 - (time % 50), 100 - (time % 50)); if (score > hiscore[diff]) { DrawText ("New best score!", -1, 156, 100, 100, 100); } if (WasButtonPressed (PADcross)) { if (score > hiscore[diff]) { hiscore[diff] = score; } SsUtKeyOn (vab1, 5,0, 64, 0, 128, 128); state = STATE_FRONTEND; } } //-------------------------------------------------------------- #define MAX_BLURS 4 #define BLUR_LEFT 60 #define BLUR_GAP ((SCREEN_WIDTH - (BLUR_LEFT * 2)) / MAX_BLURS) void IntroLoop (void) { int count; int temp; static int sound; static int fade = 0; static int init = 0; static int timer = 0; static int rot = 0; GsSPRITE sprite; if (init == 0) { SetFrameSTP(); timer = 0; fade = 0; sound = SsUtKeyOn (vab1, 4,0, 24, 0, 128, 128); SetBlurParam (ONE + 512, ONE + 512, 0, 0,0,128); init = 1; } if (timer < 230) { SetDefaultSpriteData (&sprite, BLUR_SPRITE); sprite.mx = 32; sprite.my = 32; sprite.attribute |= 1 << 28 | 1 << 30; sprite.r = 0; sprite.g = 0; sprite.b = (250 - timer) >> 3; for (count = 0; count <= MAX_BLURS; count ++) { sprite.scalex = ONE + (rand() % ONE); sprite.scaley = ONE + (rand() % ONE); sprite.rotate = rot; sprite.x = BLUR_LEFT + (count * BLUR_GAP); sprite.y = SCREEN_HEIGHT/2; GsSortSprite (&sprite, &othWorld[nBuffer], 0); } if (fade < 128) { fade += 4; } SetDefaultSpriteData (&sprite, SCENE_SPRITE); sprite.x = 68; sprite.y = 96; sprite.r = fade; sprite.g = fade; sprite.b = fade; GsSortFastSprite (&sprite, &othWorld[nBuffer], 10); } timer++; rot += 256; if (PADstatus & PADstart) { SsUtKeyOff (sound, vab1,4,0,24); timer = 250; } if (timer >= 250) { init = 0; state = STATE_FRONTEND; } } //-------------------------------------------------------------- int main() { RECT vram = {0,0,1024,512}; ClearImage (&vram, 0,0,0); Init(); while (!(PADstatus & PADselect)) { switch (state) { case STATE_FRONTEND: FrameStart(0); FrontendLoop(); // BlurScreen (); break; case STATE_GAME: FrameStart(0); UpdateGame(); DrawGame(); break; case STATE_RESULTS: FrameStart(0); ResultsLoop(); break; case STATE_INTRO: FrameStart(1); IntroLoop(); BlurScreen(); break; default: break; } FrameEnd(); } DMSDeInit(&d); SsUtAllKeyOff (0); SsVabClose (vab1); ClearImage (&vram, 0,32,0); ResetGraph (3); return 0; }