// My first PSX game // David Johnston - Programming, Level design, Concept // Mike Goatly - Graphics // ARM'd & Dangerous // 01/11/98 // v1.0 #include #include #include #include #include "pad.h" #include "asssert.h" #include "dump.h" #define MAINSPRS_ADDRESS 0x80090000 GsIMAGE MainSprsInfo; #define BACKGR_ADDRESS 0x800bd000 GsIMAGE BackGrInfo; #define SNAIL_ADDRESS 0x800c7000 GsIMAGE SnailInfo; #define ICONS_ADDRESS 0x800c9000 GsIMAGE IconsInfo; #define NUMS_ADDRESS 0x800ca000 GsIMAGE NumsInfo; #define MAP1_ADDRESS 0x800cb000 #define MAP2_ADDRESS 0x800cf000 #define MAP3_ADDRESS 0x800d3000 #define MAP4_ADDRESS 0x800d7000 #define MAP5_ADDRESS 0x800db000 #define MAP6_ADDRESS 0x800df000 #define TITLE_ADDRESS 0x800e3000 GsIMAGE TitleInfo; #define BIGNUMS_ADDRESS 0x800f9000 GsIMAGE BignumsInfo; #define MAP_ADDRESS 0x800fc000 #define NYTITLE_ADDRESS 0x80100000 GsIMAGE NYTitleInfo; #define INFO_ADDRESS 0x80126000 GsIMAGE InfoInfo; #define LOGO_ADDRESS 0x80129000 GsIMAGE LogoInfo; #define FONT_ADDRESS 0x80136000 GsIMAGE FontInfo; #define BOING_ADDRESS 0x80139000 #define SCREEN_WIDTH 320 // screen width and height #define SCREEN_HEIGHT 240 #define PACKETMAX 2048 /* Max GPU packets */ #define PACKETMAX2 (PACKETMAX*24) #define OT_LENGTH 4 static GsOT Wot[2]; /* Handler of OT */ static GsOT_TAG wtags[2][1<vx = x, (vector)->vy = y, (vector)->vz = z /**************************************************************************** functions ****************************************************************************/ void main (void) { int hsync = 0; int i; int codefalse; int nytitledel = 1152; int logodist, logospeed; int endingdel; int nextchardel = 32; int nextletpos; printf("IN MAIN\n"); InitialiseAll(); SetVideoMode(MODE_PAL); side = GsGetActiveBuff(); // Display Net Yaroze title screen while(nytitledel > 0) { GsSetWorkBase((PACKET*)packetArea[side]); GsClearOt(0,0,&Wot[side]); if (nytitledel>128) PlotNYTitle(128); else PlotNYTitle(nytitledel); nytitledel-=4; hsync = VSync(0); ResetGraph(1); GsSwapDispBuff(); GsSortClear(0,0,4,&Wot[side]); GsDrawOt(&Wot[side]); side ^= 1; FntFlush(-1); } // Loop until quit from menu while(quit != 2) { // ARM'd & dangerous logo loop logodist = 10240; while (logodist > 0) { GsSetWorkBase((PACKET*)packetArea[side]); GsClearOt(0,0,&Wot[side]); PlotARMdLogo(logodist); logodist-=256; hsync = VSync(0); ResetGraph(1); GsSwapDispBuff(); GsSortClear(0,0,4,&Wot[side]); GsDrawOt(&Wot[side]); side ^= 1; FntFlush(-1); } start = 0; quit = 0; fadeup = 0; // Title screen of game while(start<40 && quit == 0) { GsSetWorkBase((PACKET*)packetArea[side]); GsClearOt(0,0,&Wot[side]); pad = PadRead(); MenuControllerPad(); PlotTitle(); PlotCode(); if (fadeup<128) fadeup++; if (start>0) start++; hsync = VSync(0); ResetGraph(1); GsSwapDispBuff(); GsSortClear(0,0,4,&Wot[side]); GsDrawOt(&Wot[side]); side ^= 1; FntFlush(-1); } titleangle = 0; titlespeed = 0; titleypos = 120*4096; titleonscreen = 1; animtable[48] = 49; animtable[49] = 49; animtable[50] = 50; animtable[51] = 50; codefalse=0; level=1; hearts=passcode[2]*10 + passcode[3]; maxhearts=passcode[5]*10 + passcode[6]; for (i=0;i<5;i++) { if ((levelcodes[i]/10 == passcode[0]) && (levelcodes[i]%10 == passcode[1])) level=i+2; } if (!(passcode[4]==((passcode[0]+passcode[2])*(passcode[1]+passcode[3])%10))) codefalse=1; if (!(passcode[7]==((passcode[0]+passcode[5])*(passcode[1]+passcode[6])%10))) codefalse=1; if (codefalse==1 || (hearts==0 && maxhearts==0) || hearts>maxhearts) { level=1; hearts = 8; maxhearts = 8; } CopyMap(level); ScanMap(); snuffedit = 0; finishedlev = 0; // Main game loop while((snuffedit==0 && quit==0 && finishedlev==0) || fadeout>0) { //FntPrint("frame: %d\n", frameNumber); pad = PadRead(); DealWithControllerPad(); GsSetWorkBase((PACKET*)packetArea[side]); GsClearOt(0,0,&Wot[side]); PlotBackGround(); PlotScreen(); MoveSnail(); MoveNasties(); CollisionDetect(); CheckFloors(); PlotStatus(); MoveBricks(); if (titleonscreen==1) { if (titleypos<120*4096) { PlotTitleFalling2(); } else { PlotTitleFalling(); } } if (fadeout>0) fadeout--; hsync = VSync(0); ResetGraph(1); GsSwapDispBuff(); GsSortClear(0,0,4,&Wot[side]); GsDrawOt(&Wot[side]); side ^= 1; FntFlush(-1); } if (finishedlev==1 && level<6) { level++; passcode[0] = levelcodes[level-2] / 10; passcode[1] = levelcodes[level-2] % 10; passcode[2] = hearts / 10; passcode[3] = hearts % 10; passcode[4] = (passcode[0]+passcode[2])*(passcode[1]+passcode[3])%10; passcode[5] = maxhearts / 10; passcode[6] = maxhearts % 10; passcode[7] = (passcode[0]+passcode[5])*(passcode[1]+passcode[6])%10; } if (finishedlev==1 && level==6) { // Ending ProperInitialiseTexture(FONT_ADDRESS, &FontInfo); for (i=0;i<256;i++) letters[i].sprite = 256; endingdel = 256; nextchardel = 4; nextletpos = 0; messpos = message; endmessypos = -(96<<16); logodist = 5120<<8; logospeed = 0; while(endingdel > 0 || !(pad & PADstart)) { GsSetWorkBase((PACKET*)packetArea[side]); GsClearOt(0,0,&Wot[side]); if ((--nextchardel) == 0) {nextchardel = 4; nextletpos = NextLetter (nextletpos);} PlotLetters (); PlotARMdLogo(logodist>>8); logospeed-=1024; if ((logodist+=logospeed) < (512<<8)) { logodist = 512<<8; logospeed = -logospeed; } endingdel--; pad = PadRead(); hsync = VSync(0); ResetGraph(1); GsSwapDispBuff(); GsSortClear(0,0,4,&Wot[side]); GsDrawOt(&Wot[side]); side ^= 1; FntFlush(-1); } ProperInitialiseTexture(MAINSPRS_ADDRESS, &MainSprsInfo); } } ResetGraph(3); } void PlotLetters() { int i, u, tpagex; GsSPRITE letterspr; InitGsSprite(&letterspr); letterspr.w = 16; letterspr.h = 16; for (i=0;i<256;i++) { if (letters[i].sprite < 256) { letters[i].yspeed+=32768; if ((letters[i].ypos+=letters[i].yspeed) > letters[i].ytarget) { letters[i].ypos = letters[i].ytarget; letters[i].yspeed -= (letters[i].yspeed >> 2); letters[i].yspeed = -letters[i].yspeed; }; letterspr.x = letters[i].xpos; letterspr.y = (letters[i].ypos>>16); u = (int)(letters[i].sprite)*16; tpagex = 320; while (u>=256) { u-=256; tpagex+=128; } letterspr.u = u; letterspr.tpage = GetTPage (1, 0, tpagex, 0); GsSortSprite( &letterspr, &Wot[side], 0); } } } int NextLetter(int nextletpos) { if (*messpos != '.') { if (*messpos == '¤') { endmessxpos = -160 + ((int)(*(messpos+1)) - 48) * 16; messpos+=2; endmessypos+=(16<<16); } else { if (*messpos != ' ') { letters[nextletpos].xpos = endmessxpos; letters[nextletpos].ypos = -(136<<16); letters[nextletpos].yspeed = 0; letters[nextletpos].ytarget = endmessypos; letters[nextletpos].sprite = (int)(*messpos)-97; nextletpos++; } endmessxpos += 16; messpos++; } } return(nextletpos); } void MoveBricks() { int i; GsSPRITE brickspr; InitGsSprite(&brickspr); if (fadeout>0) { brickspr.r = fadeout; brickspr.g = fadeout; brickspr.b = fadeout; } for (i=0;i<64;i++) { if (bricks[i].x!=0) { brickspr.x = -16+((bricks[i].x-snailx)*32+((bricks[i].xdis>>16)-(snailxdis>>16))); brickspr.y = -16+((bricks[i].y-snaily)*32+((bricks[i].ydis>>16)-(snailydis>>16))); brickspr.w = 16; brickspr.h = 16; brickspr.tpage = GetTPage (1, 0, 704, 0); brickspr.u = 16 + (16*bricks[i].sprite); brickspr.v = 32; GsSortSprite( &brickspr, &Wot[side], 0); bricks[i].xdis += bricks[i].xspeed; bricks[i].ydis += bricks[i].yspeed; bricks[i].yspeed += 16384; if (bricks[i].xdis<0) { bricks[i].xdis+=32<<16; bricks[i].x--; } if (bricks[i].xdis>(32<<16)) { bricks[i].xdis-=32<<16; bricks[i].x++; } if (bricks[i].ydis<0) { bricks[i].ydis+=32<<16; bricks[i].y--; } if (bricks[i].ydis>(32<<16)) { bricks[i].ydis-=32<<16; bricks[i].y++; } if (bricks[i].delay-- == 0) bricks[i].x = 0; } } } void PlotCode() { int i, no, x, y, u, tpagex; long angle; if ((codeangle+=64) == 4096) codeangle = 0; bignumsprs.r = fadeup; bignumsprs.g = fadeup; bignumsprs.b = fadeup; x = -128; for (i=0;i<8;i++) { y=-32; if (start>0) { if (i % 2 == 0) y=-32+(start*4); else y=-32-(start*4); } if (i == digit) { bignumsprs.rotate = 45 * DJsin(codeangle); if (bignumsprs.rotate<0) bignumsprs.rotate+=(4096*360); angle = bignumsprs.rotate + (45*4096); if (angle>360*4096) angle-=360*4096; bignumsprs.x = x+16-(DJcos((short)(angle/360))/181); bignumsprs.y = y+16-(DJsin((short)(angle/360))/181); } else { bignumsprs.rotate = 0; bignumsprs.x = x; bignumsprs.y = y; } no = passcode[i]; u = 64; tpagex = 640; while (no>0) { no--; if ((u+=32) == 256) { u = 0; tpagex+=128; } } bignumsprs.tpage = GetTPage(1, 0, tpagex, 0); bignumsprs.u = (short)(u); GsSortSprite( &bignumsprs, &Wot[side], 0); x += 32; } } short DJsin (short angle) { short result; if (angle>2048) { if (angle<3072) result = -(SinCosTable[angle-2048]); else result = -(SinCosTable[4096-angle]); } else { if (angle<1024) result = SinCosTable[angle]; else result = SinCosTable[2048-angle]; } return(result); } short DJcos (short angle) { short result; if (angle>2048) { if (angle<3072) result = -(SinCosTable[3072-angle]); else result = SinCosTable[angle-3072]; } else { if (angle<1024) result = SinCosTable[1024-angle]; else result = -(SinCosTable[angle-1024]); } return(result); } void CopyMap(int map) { int i = 0; unsigned char * origptr; unsigned char * newptr = (unsigned char *)(MAP_ADDRESS); switch (map) { case 1: origptr = (unsigned char *)(MAP1_ADDRESS); break; case 2: origptr = (unsigned char *)(MAP2_ADDRESS); break; case 3: origptr = (unsigned char *)(MAP3_ADDRESS); break; case 4: origptr = (unsigned char *)(MAP4_ADDRESS); break; case 5: origptr = (unsigned char *)(MAP5_ADDRESS); break; default: origptr = (unsigned char *)(MAP6_ADDRESS); break; } for (i=0;i<16384;i++) *(newptr+i) = *(origptr+i); } void PlotARMdLogo(int zval) { GsSPRITE logo; int x1 = (-102400*16)/zval; int x2 = (102400*16)/zval; int y1 = (-76800*16)/zval; int y2 = (76800*16)/zval; InitGsSprite(&logo); logo.x = x1/16; logo.y = y1/16; logo.w = 128; logo.h = 192; logo.tpage = GetTPage (1, 0, 768, 256); logo.u = 64; logo.scalex = ((x2-x1)*256)/256; logo.scaley = ((y2-y1)*256)/192; GsSortSprite( &logo, &Wot[side], 2); logo.x = 0; logo.tpage = GetTPage (1, 0, 832, 256); GsSortSprite( &logo, &Wot[side], 2); } void PlotTitleFalling() { GsSPRITE title; if (titleangle<(45*4096)) titlespeed += 1024; else titlespeed -= 1024; if (titleangle<(50*4096) && titleangle>(40*4096)) { if (titlespeed>0) { if ((titlespeed-=1020) < 0) {titlespeed = 0; titleypos = -120*4096;} } else { if ((titlespeed+=1020) > 0) {titlespeed = 0; titleypos = -120*4096;} } } titleangle += titlespeed; InitGsSprite(&title); title.x = -160; title.y = -120; title.w = 160; title.h = 240; title.u = 0; title.rotate = titleangle; title.r = fadeup; title.g = fadeup; title.b = fadeup; title.tpage = GetTPage (1, 0, 320, 256); GsSortSprite( &title, &Wot[side], 0); title.u = 32; title.rotate = (360*4096)-titleangle; title.x = 160-(DJcos((short)(titleangle/360))/26); title.y = -120+(DJsin((short)(titleangle/360))/26); title.tpage = GetTPage (1, 0, 384, 256); GsSortSprite( &title, &Wot[side], 0); } void PlotTitleFalling2() { GsSPRITE title; titlespeed += 1024; titleypos += titlespeed; if (titleypos>120*4096) titleonscreen = 0; InitGsSprite(&title); title.x = -160; title.y = titleypos/4096; title.w = 160; title.h = 240; title.u = 0; title.rotate = titleangle; title.r = fadeup; title.g = fadeup; title.b = fadeup; title.tpage = GetTPage (1, 0, 320, 256); GsSortSprite( &title, &Wot[side], 0); title.u = 32; title.rotate = (360*4096)-titleangle; title.x = 160-(DJcos((short)(titleangle/360))/26); title.y = (titleypos/4096)+(DJsin((short)(titleangle/360))/26); title.tpage = GetTPage (1, 0, 384, 256); GsSortSprite( &title, &Wot[side], 0); } void PlotTitle() { GsSPRITE title; InitGsSprite(&title); title.x = -160; title.y = -120; title.w = 160; title.h = 240; title.u = 0; title.r = fadeup; title.g = fadeup; title.b = fadeup; title.tpage = GetTPage (1, 0, 320, 256); GsSortSprite( &title, &Wot[side], 2); title.x = 0; title.u = 32; title.tpage = GetTPage (1, 0, 384, 256); GsSortSprite( &title, &Wot[side], 2); } void PlotNYTitle(unsigned char fadeval) { GsSPRITE title, info; InitGsSprite(&title); title.attribute = 1<<25; title.x = -160; title.y = -120; title.w = 160; title.h = 240; title.u = 32; title.r = fadeval; title.g = fadeval; title.b = fadeval; title.tpage = GetTPage (1, 0, 448, 256); GsSortSprite( &title, &Wot[side], 1); title.x = 0; title.u = 0; title.tpage = GetTPage (1, 0, 640, 256); GsSortSprite( &title, &Wot[side], 1); InitGsSprite(&info); info.x = -128; info.y = 16; info.w = 256; info.h = 14; info.v = 240; info.r = fadeval; info.g = fadeval; info.b = fadeval; info.tpage = GetTPage (1, 0, 320, 256); GsSortSprite( &info, &Wot[side], 0); info.y = 16+32; info.tpage = GetTPage (1, 0, 320+128, 256); GsSortSprite( &info, &Wot[side], 0); info.y = 16+64; info.tpage = GetTPage (1, 0, 320+256, 256); GsSortSprite( &info, &Wot[side], 0); } void PlotStatus() { int i = 1; if (fadeout>0) { iconsprs.r = fadeout; numsprs.r = fadeout; iconsprs.g = fadeout; numsprs.g = fadeout; iconsprs.b = fadeout; numsprs.b = fadeout; } else { iconsprs.r = 128; numsprs.r = 128; iconsprs.g = 128; numsprs.g = 128; iconsprs.b = 128; numsprs.b = 128; } iconsprs.x = -160; iconsprs.y = -120; iconsprs.u = 64; while (i<=hearts) { GsSortSprite( &iconsprs, &Wot[side], 1); i++; iconsprs.x+=16; } iconsprs.u+=16; while (i<=maxhearts) { GsSortSprite( &iconsprs, &Wot[side], 1); i++; iconsprs.x+=16; } iconsprs.x = 144; i = 5; iconsprs.u+=16; while (i>spheres){ GsSortSprite( &iconsprs, &Wot[side], 1); i--; iconsprs.x-=16; } iconsprs.x = -160; iconsprs.y = -104; iconsprs.u+=16; GsSortSprite( &iconsprs, &Wot[side], 1); numsprs.x = -144; numsprs.u = 64+16*(coins / 10); GsSortSprite( &numsprs, &Wot[side], 1); numsprs.x = -128; numsprs.u = 64+16*(coins % 10); GsSortSprite( &numsprs, &Wot[side], 1); iconsprs.x = 144; i = 0; iconsprs.u+=16; while (i=0;nastyno--) { switch (nasties[nastyno].id) { case 0: if (nasties[nastyno].delaytonext--<0) { nasties[nastyno].delaytonext=127; firearrowright(nasties[nastyno].xpos+1, nasties[nastyno].ypos); } break; case 1: if (nasties[nastyno].delaytonext--<0) { nasties[nastyno].delaytonext=127; firearrowleft(nasties[nastyno].xpos-1, nasties[nastyno].ypos); } break; case 2: rightarrow(nastyno); break; case 3: leftarrow(nastyno); break; case 4: if (nasties[nastyno].delaytonext--<0) { nasties[nastyno].delaytonext=127; launchfireball(nasties[nastyno].xpos, nasties[nastyno].ypos-1); } break; case 5: fireball(nastyno); break; case 6: madgeezer(nastyno); break; } } } void madgeezer(int i) { int x = nasties[i].xpos; int y = nasties[i].ypos; unsigned char checkforward; unsigned char checkdown; if ((nasties[i].delaytonext++) == 2) { nasties[i].delaytonext=0; *(unsigned char *)(MAP_ADDRESS+(y*256)+x) = 8; *(unsigned char *)(MAP_ADDRESS+(y*256)+x+1) = 8; if (nasties[i].dirn == 0) { if ((nasties[i].spriteno-=2) == 84) { checkforward = *(unsigned char *)(MAP_ADDRESS+(y*256)+x+2); checkdown = *(unsigned char *)(MAP_ADDRESS+((y+1)*256)+x+2); if (checkforward == 8 && coldata[checkdown] != 0) { nasties[i].spriteno = 100; nasties[i].xpos++; x++; } else { nasties[i].spriteno = 88; nasties[i].dirn = 1; } } } else { if ((nasties[i].spriteno+=2) == 102) { checkforward = *(unsigned char *)(MAP_ADDRESS+(y*256)+x-1); checkdown = *(unsigned char *)(MAP_ADDRESS+((y+1)*256)+x-1); if (checkforward == 8 && coldata[checkdown] != 0) { nasties[i].spriteno = 86; nasties[i].xpos--; x--; } else { nasties[i].spriteno = 98; nasties[i].dirn = 0; } } } *(unsigned char *)(MAP_ADDRESS+(y*256)+x) = nasties[i].spriteno; *(unsigned char *)(MAP_ADDRESS+(y*256)+x+1) = nasties[i].spriteno+1; } } void fireball(int i) { unsigned char oldtile; int x = nasties[i].xpos; int y = nasties[i].ypos; switch (nasties[i].spriteno) { case 132: nasties[i].spriteno = 133; *(unsigned char *)(MAP_ADDRESS+(y*256)+x) = 133; break; case 133: *(unsigned char *)(MAP_ADDRESS+(y*256)+x) = nasties[i].whatwasthere; nasties[i].ypos--; y--; oldtile = *(unsigned char *)(MAP_ADDRESS+(y*256)+x); if (coldata[oldtile]==0) { if (oldtile==8) nasties[i].spriteno = 134; else nasties[i].spriteno = 132; *(unsigned char *)(MAP_ADDRESS+(y*256)+x) = nasties[i].spriteno; nasties[i].whatwasthere = oldtile; } else nasties[i].id = 255; break; case 134: nasties[i].spriteno = 135; *(unsigned char *)(MAP_ADDRESS+(y*256)+x) = 135; break; case 135: *(unsigned char *)(MAP_ADDRESS+(y*256)+x) = nasties[i].whatwasthere; nasties[i].ypos--; y--; oldtile = *(unsigned char *)(MAP_ADDRESS+(y*256)+x); if (coldata[oldtile]==0) { if (oldtile==8) nasties[i].spriteno = 134; else nasties[i].spriteno = 132; *(unsigned char *)(MAP_ADDRESS+(y*256)+x) = nasties[i].spriteno; nasties[i].whatwasthere = oldtile; } else nasties[i].id = 255; break; } } void rightarrow(int i) { unsigned char oldtile; int x = nasties[i].xpos; int y = nasties[i].ypos; switch (nasties[i].spriteno) { case 64: nasties[i].spriteno = 65; *(unsigned char *)(MAP_ADDRESS+(y*256)+x) = 65; break; case 65: *(unsigned char *)(MAP_ADDRESS+(y*256)+x) = nasties[i].whatwasthere; nasties[i].xpos++; x++; oldtile = *(unsigned char *)(MAP_ADDRESS+(y*256)+x); if (coldata[oldtile]==0) { if (oldtile==8) nasties[i].spriteno = 64; else nasties[i].spriteno = 70; *(unsigned char *)(MAP_ADDRESS+(y*256)+x) = nasties[i].spriteno; nasties[i].whatwasthere = oldtile; } else nasties[i].id = 255; break; case 70: nasties[i].spriteno = 71; *(unsigned char *)(MAP_ADDRESS+(y*256)+x) = 71; break; case 71: *(unsigned char *)(MAP_ADDRESS+(y*256)+x) = nasties[i].whatwasthere; nasties[i].xpos++; x++; oldtile = *(unsigned char *)(MAP_ADDRESS+(y*256)+x); if (coldata[oldtile]==0) { if (oldtile==8) nasties[i].spriteno = 64; else nasties[i].spriteno = 70; *(unsigned char *)(MAP_ADDRESS+(y*256)+x) = nasties[i].spriteno; nasties[i].whatwasthere = oldtile; } else nasties[i].id = 255; break; } } void leftarrow(int i) { unsigned char oldtile; int x = nasties[i].xpos; int y = nasties[i].ypos; switch (nasties[i].spriteno) { case 66: nasties[i].spriteno = 67; *(unsigned char *)(MAP_ADDRESS+(y*256)+x) = 67; break; case 67: *(unsigned char *)(MAP_ADDRESS+(y*256)+x) = nasties[i].whatwasthere; nasties[i].xpos--; x--; oldtile = *(unsigned char *)(MAP_ADDRESS+(y*256)+x); if (coldata[oldtile]==0) { if (oldtile==8) nasties[i].spriteno = 66; else nasties[i].spriteno = 72; *(unsigned char *)(MAP_ADDRESS+(y*256)+x) = nasties[i].spriteno; nasties[i].whatwasthere = oldtile; } else nasties[i].id = 255; break; case 72: nasties[i].spriteno = 73; *(unsigned char *)(MAP_ADDRESS+(y*256)+x) = 73; break; case 73: *(unsigned char *)(MAP_ADDRESS+(y*256)+x) = nasties[i].whatwasthere; nasties[i].xpos--; x--; oldtile = *(unsigned char *)(MAP_ADDRESS+(y*256)+x); if (coldata[oldtile]==0) { if (oldtile==8) nasties[i].spriteno = 66; else nasties[i].spriteno = 72; *(unsigned char *)(MAP_ADDRESS+(y*256)+x) = nasties[i].spriteno; nasties[i].whatwasthere = oldtile; } else nasties[i].id = 255; break; } } void launchfireball(int x, int y) { int i; int newslot = 255; unsigned char oldtile; for (i=0;i<128;i++) { if (nasties[i].id == 255) newslot=i; } if (newslot != 255) { oldtile = *(unsigned char *)(MAP_ADDRESS+(y*256)+x); nasties[newslot].id = 5; nasties[newslot].xpos = x; nasties[newslot].ypos = y; if (oldtile==8) nasties[newslot].spriteno = 134; else nasties[newslot].spriteno = 132; *(unsigned char *)(MAP_ADDRESS+(y*256)+x) = nasties[newslot].spriteno; nasties[newslot].whatwasthere = oldtile; } } void firearrowright(int x, int y) { int i; int newslot = 255; unsigned char oldtile; for (i=0;i<128;i++) { if (nasties[i].id == 255) newslot=i; } if (newslot != 255) { oldtile = *(unsigned char *)(MAP_ADDRESS+(y*256)+x); nasties[newslot].id = 2; nasties[newslot].xpos = x; nasties[newslot].ypos = y; if (oldtile==8) nasties[newslot].spriteno = 64; else nasties[newslot].spriteno = 70; *(unsigned char *)(MAP_ADDRESS+(y*256)+x) = nasties[newslot].spriteno; nasties[newslot].whatwasthere = oldtile; } } void firearrowleft(int x, int y) { int i; int newslot = 255; unsigned char oldtile; for (i=0;i<128;i++) { if (nasties[i].id == 255) newslot=i; } if (newslot != 255) { oldtile = *(unsigned char *)(MAP_ADDRESS+(y*256)+x); nasties[newslot].id = 3; nasties[newslot].xpos = x; nasties[newslot].ypos = y; if (oldtile==8) nasties[newslot].spriteno = 66; else nasties[newslot].spriteno = 72; *(unsigned char *)(MAP_ADDRESS+(y*256)+x) = nasties[newslot].spriteno; nasties[newslot].whatwasthere = oldtile; } } void ScanMap() { int mapx = 0; int mapy = 0; int nastyno = 0; int i; unsigned char * mapptr; for (i=0;i<128;i++) nasties[i].id = 255; for (i=0;i<64;i++) fallingbits[i].xpos = 0; for (i=0;i<64;i++) bricks[i].x = 0; while (mapy<64) { mapptr=(unsigned char *)(MAP_ADDRESS+(mapy*256)+mapx); switch (*mapptr) { case 255 : *mapptr = *(mapptr+1); snailx = mapx; snaily = mapy; break; case 3: *mapptr = rand() % 4; break; case 7: *mapptr = 4+(rand() % 4); break; case 62: nasties[nastyno].id = 0; nasties[nastyno].xpos = mapx; nasties[nastyno].ypos = mapy; nasties[nastyno].delaytonext = rand() % 128; nastyno++; break; case 63: nasties[nastyno].id = 1; nasties[nastyno].xpos = mapx; nasties[nastyno].ypos = mapy; nasties[nastyno].delaytonext = rand() % 128; nastyno++; break; case 86: *mapptr = 8; nasties[nastyno].id = 6; nasties[nastyno].xpos = mapx; nasties[nastyno].ypos = mapy; nasties[nastyno].spriteno = 86; nasties[nastyno].dirn = rand() % 2; nasties[nastyno].delaytonext = rand() % 2; nastyno++; break; case 132: *mapptr = 0; nasties[nastyno].id = 4; nasties[nastyno].xpos = mapx; nasties[nastyno].ypos = mapy+1; nasties[nastyno].delaytonext = rand() % 128; nastyno++; break; case 134: *mapptr = 8; nasties[nastyno].id = 4; nasties[nastyno].xpos = mapx; nasties[nastyno].ypos = mapy+1; nasties[nastyno].delaytonext = rand() % 128; nastyno++; break; } if ((mapx+=1) == 256) { mapx=0; mapy+=1; } } snailxdis = 0; snailydis = 0; snailxspeed = 0; snailyspeed = 0; invulnerable = 0; cursnailspr = 0; snaildirn = 0; turnsnaildel = 0; spheres = 0; keys = 0; coins = 0; fadeout = 0; } void CollisionDetect() { unsigned char tl = *(unsigned char *)(MAP_ADDRESS+(snaily*256)+snailx); unsigned char tr = *(unsigned char *)(MAP_ADDRESS+(snaily*256)+snailx+1); unsigned char bl = *(unsigned char *)(MAP_ADDRESS+((snaily+1)*256)+snailx); unsigned char br = *(unsigned char *)(MAP_ADDRESS+((snaily+1)*256)+snailx+1); beenupdrafted = 0; if (snailxdis==0) { if (snailydis==0) { runcheck(coldata[tl],0); } else { runcheck(coldata[tl],0); runcheck(coldata[bl],256); } } else { if (snailydis==0) { runcheck(coldata[tl],0); runcheck(coldata[tr],1); if (coldata[tl]==8) { snailx++; snailxdis=0; snailxspeed=524288; hitredswitch(); } if (coldata[tl]==9) { snailx++; snailxdis=0; snailxspeed=524288; hitblueswitch(); } if (coldata[tr]==8) { snailxdis=0; snailxspeed=-524288; hitredswitch(); } if (coldata[tr]==9) { snailxdis=0; snailxspeed=-524288; hitblueswitch(); } } else { runcheck(coldata[tl],0); runcheck(coldata[tr],1); runcheck(coldata[bl],256); runcheck(coldata[br],257); } } } void hitredswitch() { animtable[46]=47; animtable[47]=47; animtable[48]=48; animtable[49]=48; animtable[50]=51; animtable[51]=51; } void hitblueswitch() { animtable[46]=46; animtable[47]=46; animtable[48]=49; animtable[49]=49; animtable[50]=50; animtable[51]=50; } void runcheck(unsigned char tilevalue, short pos) { switch (tilevalue) { case 1: gotoutsidecoin(pos); break; case 2: gotinsidecoin(pos); break; case 3: *(unsigned char *)(MAP_ADDRESS+(snaily*256)+snailx+pos) = 0; keys++; break; case 4: *(unsigned char *)(MAP_ADDRESS+(snaily*256)+snailx+pos) = 8; keys++; break; case 13 : snailx+=24; break; case 15 : if (hearts524288) snailyspeed=524288; snailydis2+=snailyspeed; if (snailydis2<0) { snailydis2+=(32<<16); snaily2-=1; } if (snailydis2>=(32<<16)) { snailydis2-=(32<<16); snaily2+=1; } if (snailyspeed<0) checkfornut=1; hitwallval=CheckHitWall(snailx2, snaily2, snailxdis2, snailydis2); checkfornut=0; OKtojump=0; if (hitwallval==0){ snaily=snaily2; snailydis=snailydis2; } else { if (snailyspeed<0) { if (hitwallval==128) { *(unsigned char *)(MAP_ADDRESS+(snaily2*256)+snailx2); } } if (snailyspeed>0) OKtojump=1; if (snailydis>(16<<16)) snaily+=1; snailyspeed=0; snailydis=0; } if (onice()) { if (snailxspeed>0) { if ((snailxspeed-=16384)<0) snailxspeed=0; } if (snailxspeed<0) { if ((snailxspeed+=16384)>0) snailxspeed=0; } } snailxdis2+=snailxspeed; if (snailxdis2<0) { snailxdis2+=(32<<16); snailx2-=1; } if (snailxdis2>=(32<<16)) { snailxdis2-=(32<<16); snailx2+=1; } checkforpush = 1; hitwallval=CheckHitWall(snailx2, snaily, snailxdis2, snailydis); checkforpush = 0; if (hitwallval==0){ snailx=snailx2; snailxdis=snailxdis2; } else { if (snailxdis>(16<<16)) snailx+=1; snailxspeed=0; snailxdis=0; } if (turnsnaildel<2) turnsnaildel++; if (turnsnaildel==2) { if (snaildirn==0 && cursnailspr!=0) { cursnailspr--; turnsnaildel=0; } if (snaildirn==1 && cursnailspr!=5) { cursnailspr++; turnsnaildel=0; } } if (fadeout>0) { snailspr.r = fadeout; snailspr.g = fadeout; snailspr.b = fadeout; } else { snailspr.r = 128; snailspr.g = 128; snailspr.b = 128; } if (invulnerable>0) invulnerable--; if ((invulnerable % 16)<8) { u = (cursnailspr*32)+64; tpagex = 640; while (u>256) { u-=256; tpagex+=128; } snailspr.tpage = GetTPage(1,0,tpagex,0); snailspr.u = u; GsSortSprite( &snailspr, &Wot[side], 1); } } int CheckHitWall(int x, int y, int dx, int dy) { unsigned char tl = *(unsigned char *)(MAP_ADDRESS+(y*256)+x); unsigned char tr = *(unsigned char *)(MAP_ADDRESS+(y*256)+x+1); unsigned char bl = *(unsigned char *)(MAP_ADDRESS+((y+1)*256)+x); unsigned char br = *(unsigned char *)(MAP_ADDRESS+((y+1)*256)+x+1); int val = 0; if (dx==0) { if (dy==0) { if (coldata[tl]==255) val=255; if (coldata[tl]==26) val=255; if (coldata[tl]==27) val=255; if (coldata[tl]==10 || coldata[tl]==11 || coldata[tl]==12 || coldata[tl]==14 || coldata[tl]==19 || coldata[tl]==20) val=255; if (checkdoor(tl, x, y)==1) val=255; nutable(tl, x, y); pushabletl(tl, x, y); } else { if (coldata[tl]==255 || coldata[bl]==255) val=255; if (coldata[tl]==26 || coldata[bl]==26) val=255; if (coldata[tl]==27 || coldata[bl]==27) val=255; if (coldata[bl]==7) bounce(); if (coldata[tl]==10 || coldata[tl]==11 || coldata[tl]==12 || coldata[tl]==14 || coldata[tl]==19 || coldata[tl]==20) val=255; if (coldata[bl]==10 || coldata[bl]==11 || coldata[bl]==12 || coldata[bl]==14 || coldata[bl]==19 || coldata[bl]==20) val=255; if (checkdoor(tl, x, y)==1) val=255; if (checkdoor(bl, x, y+1)==1) val=255; nutable(tl, x, y); pushabletl(tl, x, y); } } else { if (dy==0) { if (coldata[tl]==255 || coldata[tr]==255) val=255; if (coldata[tl]==26 || coldata[tr]==26) val=255; if (coldata[tl]==27 || coldata[tr]==27) val=255; if (coldata[tl]==10 || coldata[tl]==11 || coldata[tl]==12 || coldata[tl]==14 || coldata[tl]==19 || coldata[tl]==20) val=255; if (coldata[tr]==10 || coldata[tr]==11 || coldata[tr]==12 || coldata[tr]==14 || coldata[tr]==19 || coldata[tr]==20) val=255; if (checkdoor(tl, x, y)==1) val=255; if (checkdoor(tr, x+1, y)==1) val=255; nutable(tl, x, y); nutable(tr, x+1, y); pushabletl(tl, x, y); pushabletr(tr, x, y); } else { if (coldata[tl]==255 || coldata[tr]==255 || coldata[bl]==255 || coldata[br]==255) val=255; if (coldata[tl]==26 || coldata[tr]==26 || coldata[bl]==26 || coldata[br]==26) val=255; if (coldata[tl]==27 || coldata[tr]==27 || coldata[bl]==27 || coldata[br]==27) val=255; if (coldata[bl]==7 && coldata[br]==7) bounce(); if (coldata[tl]==10 || coldata[tl]==11 || coldata[tl]==12 || coldata[tl]==14 || coldata[tl]==19 || coldata[tl]==20) val=255; if (coldata[tr]==10 || coldata[tr]==11 || coldata[tr]==12 || coldata[tr]==14 || coldata[tr]==19 || coldata[tr]==20) val=255; if (coldata[bl]==10 || coldata[bl]==11 || coldata[bl]==12 || coldata[bl]==14 || coldata[bl]==19 || coldata[bl]==20) val=255; if (coldata[br]==10 || coldata[br]==11 || coldata[br]==12 || coldata[br]==14 || coldata[br]==19 || coldata[br]==20) val=255; if (checkdoor(tl, x, y)==1) val=255; if (checkdoor(tr, x+1, y)==1) val=255; if (checkdoor(bl, x, y+1)==1) val=255; if (checkdoor(br, x+1, y+1)==1) val=255; nutable(tl, x, y); nutable(tr, x+1, y); pushabletl(tl, x, y); pushabletr(tr, x, y); } } return(val); } int checkdoor(unsigned char tiletype, int x, int y) { int hitdoor = 0; if (coldata[tiletype]==5 || coldata[tiletype]==6) hitdoor=1; if (coldata[tiletype]==5 && keys>0) { keys--; *(unsigned char *)(MAP_ADDRESS+(y*256)+x) = 0; } if (coldata[tiletype]==6 && keys>0) { keys--; *(unsigned char *)(MAP_ADDRESS+(y*256)+x) = 8; } return(hitdoor); } void bounce() { if (pad & PADRdown) snailyspeed=-983040; else snailyspeed=-262144; } void pushabletl(unsigned char tiletype, int x, int y) { if (checkforpush==1) { if (tiletype==130 && coldata[(*(unsigned char *)(MAP_ADDRESS+(y*256)+(x-1)))]==0 && coldata[(*(unsigned char *)(MAP_ADDRESS+((y+1)*256)+(x-1)))]) { *(unsigned char *)(MAP_ADDRESS+(y*256)+(x-1)) = 130; *(unsigned char *)(MAP_ADDRESS+(y*256)+x) = 0; } if (tiletype==131 && coldata[(*(unsigned char *)(MAP_ADDRESS+(y*256)+(x-1)))]==0 && coldata[(*(unsigned char *)(MAP_ADDRESS+((y+1)*256)+(x-1)))]) { *(unsigned char *)(MAP_ADDRESS+(y*256)+(x-1)) = 131; *(unsigned char *)(MAP_ADDRESS+(y*256)+x) = 8; } } } void pushabletr(unsigned char tiletype, int x, int y) { if (checkforpush==1) { if (tiletype==130 && coldata[(*(unsigned char *)(MAP_ADDRESS+(y*256)+x+2))]==0 && coldata[(*(unsigned char *)(MAP_ADDRESS+((y+1)*256)+x+2))]) { *(unsigned char *)(MAP_ADDRESS+(y*256)+x+2) = 130; *(unsigned char *)(MAP_ADDRESS+(y*256)+x+1) = 0; } if (tiletype==131 && coldata[(*(unsigned char *)(MAP_ADDRESS+(y*256)+x+2))]==0 && coldata[(*(unsigned char *)(MAP_ADDRESS+((y+1)*256)+x+2))]) { *(unsigned char *)(MAP_ADDRESS+(y*256)+x+2) = 131; *(unsigned char *)(MAP_ADDRESS+(y*256)+x+1) = 8; } } } void nutable(unsigned char tiletype, int x, int y) { int freeslot, i; if (checkfornut==1) { if (coldata[tiletype]==10) { *(unsigned char *)(MAP_ADDRESS+(y*256)+x) = 8; freeslot = 255; for (i=0;i<64;i++) { if (bricks[i].x == 0) freeslot=i; } if (freeslot != 255) { bricks[freeslot].x = x; bricks[freeslot].y = y; bricks[freeslot].xdis = 0; bricks[freeslot].ydis = 0; bricks[freeslot].xspeed = -(2*rand())-32768; bricks[freeslot].yspeed = -(6*rand())-32768; bricks[freeslot].delay = 128; bricks[freeslot].sprite = 0; } freeslot = 255; for (i=0;i<64;i++) { if (bricks[i].x == 0) freeslot=i; } if (freeslot != 255) { bricks[freeslot].x = x; bricks[freeslot].y = y; bricks[freeslot].xdis = (16<<16); bricks[freeslot].ydis = 0; bricks[freeslot].xspeed = (2*rand())+32768; bricks[freeslot].yspeed = -(6*rand())-32768; bricks[freeslot].delay = 128; bricks[freeslot].sprite = 1; } freeslot = 255; for (i=0;i<64;i++) { if (bricks[i].x == 0) freeslot=i; } if (freeslot != 255) { bricks[freeslot].x = x; bricks[freeslot].y = y; bricks[freeslot].xdis = 0; bricks[freeslot].ydis = (16<<10); bricks[freeslot].xspeed = -(2*rand())-32768; bricks[freeslot].yspeed = -(6*rand())-32768; bricks[freeslot].delay = 128; bricks[freeslot].sprite = 2; } freeslot = 255; for (i=0;i<64;i++) { if (bricks[i].x == 0) freeslot=i; } if (freeslot != 255) { bricks[freeslot].x = x; bricks[freeslot].y = y; bricks[freeslot].xdis = (16<<10); bricks[freeslot].ydis = (16<<10); bricks[freeslot].xspeed = (2*rand())+32768; bricks[freeslot].yspeed = -(6*rand())-32768; bricks[freeslot].delay = 128; bricks[freeslot].sprite = 3; } } if (coldata[tiletype]==11) { *(unsigned char *)(MAP_ADDRESS+(y*256)+x) = 0; freeslot = 255; for (i=0;i<64;i++) { if (bricks[i].x == 0) freeslot=i; } if (freeslot != 255) { bricks[freeslot].x = x; bricks[freeslot].y = y; bricks[freeslot].xdis = 0; bricks[freeslot].ydis = 0; bricks[freeslot].xspeed = -(2*rand())-32768; bricks[freeslot].yspeed = -(6*rand())-32768; bricks[freeslot].delay = 128; bricks[freeslot].sprite = 0; } freeslot = 255; for (i=0;i<64;i++) { if (bricks[i].x == 0) freeslot=i; } if (freeslot != 255) { bricks[freeslot].x = x; bricks[freeslot].y = y; bricks[freeslot].xdis = (16<<16); bricks[freeslot].ydis = 0; bricks[freeslot].xspeed = (2*rand())+32768; bricks[freeslot].yspeed = -(6*rand())-32768; bricks[freeslot].delay = 128; bricks[freeslot].sprite = 1; } freeslot = 255; for (i=0;i<64;i++) { if (bricks[i].x == 0) freeslot=i; } if (freeslot != 255) { bricks[freeslot].x = x; bricks[freeslot].y = y; bricks[freeslot].xdis = 0; bricks[freeslot].ydis = (16<<10); bricks[freeslot].xspeed = -(2*rand())-32768; bricks[freeslot].yspeed = -(6*rand())-32768; bricks[freeslot].delay = 128; bricks[freeslot].sprite = 2; } freeslot = 255; for (i=0;i<64;i++) { if (bricks[i].x == 0) freeslot=i; } if (freeslot != 255) { bricks[freeslot].x = x; bricks[freeslot].y = y; bricks[freeslot].xdis = (16<<10); bricks[freeslot].ydis = (16<<10); bricks[freeslot].xspeed = (2*rand())+32768; bricks[freeslot].yspeed = -(6*rand())-32768; bricks[freeslot].delay = 128; bricks[freeslot].sprite = 3; } } if (coldata[tiletype]==12) { *(unsigned char *)(MAP_ADDRESS+(y*256)+x) = 74; if (*(unsigned char *)(MAP_ADDRESS+((y-1)*256)+x) == 8) *(unsigned char *)(MAP_ADDRESS+((y-1)*256)+x) = 10; else *(unsigned char *)(MAP_ADDRESS+((y-1)*256)+x) = 26; } if (coldata[tiletype]==14) { *(unsigned char *)(MAP_ADDRESS+(y*256)+x) = 74; if (*(unsigned char *)(MAP_ADDRESS+((y-1)*256)+x) == 8) *(unsigned char *)(MAP_ADDRESS+((y-1)*256)+x) = 77; else *(unsigned char *)(MAP_ADDRESS+((y-1)*256)+x) = 81; } if (coldata[tiletype]==19) { *(unsigned char *)(MAP_ADDRESS+(y*256)+x) = 74; if (*(unsigned char *)(MAP_ADDRESS+((y-1)*256)+x) == 8) *(unsigned char *)(MAP_ADDRESS+((y-1)*256)+x) = 103; else *(unsigned char *)(MAP_ADDRESS+((y-1)*256)+x) = 102; } if (coldata[tiletype]==20) { *(unsigned char *)(MAP_ADDRESS+(y*256)+x) = 74; if (*(unsigned char *)(MAP_ADDRESS+((y-1)*256)+x) == 8) *(unsigned char *)(MAP_ADDRESS+((y-1)*256)+x) = 105; else *(unsigned char *)(MAP_ADDRESS+((y-1)*256)+x) = 104; } } } int onice () { unsigned char leftfloor, rightfloor; int result; result = 1; if (snailydis==0) { leftfloor = *(unsigned char *)(MAP_ADDRESS+((snaily+1)*256)+snailx); rightfloor = *(unsigned char *)(MAP_ADDRESS+((snaily+1)*256)+snailx+1); if (coldata[leftfloor]==26 || coldata[rightfloor]==26) result = 0; } return (result); } void PlotBackGround () { if (fadeout>0) { backgrtop.r = fadeout; backgrbottom.r = fadeout; backgrtop.g = fadeout; backgrbottom.g = fadeout; backgrtop.b = fadeout; backgrbottom.b = fadeout; } else { backgrtop.r = 128; backgrbottom.r = 128; backgrtop.g = 128; backgrbottom.g = 128; backgrtop.b = 128; backgrbottom.b = 128; } backgrtop.y = -128-((snailydis>>19)+(snaily*4)); for (backgrtop.x=-160;backgrtop.x<160;backgrtop.x+=80){ GsSortSprite( &backgrtop, &Wot[side], 4); } backgrbottom.y = backgrtop.y+256; for (backgrbottom.x=-160;backgrbottom.x<160;backgrbottom.x+=80){ GsSortSprite( &backgrbottom, &Wot[side], 4); } } void PlotScreen () { short x,y; int mapx,mapy,tpagex,tpagey; int tiletype; int u; if ((animate+=1) == 4) animate = 0; if (fadeout>0) { maptile.r = fadeout; maptile.g = fadeout; maptile.b = fadeout; } else { maptile.r = 128; maptile.g = 128; maptile.b = 128; } mapx = snailx; mapy = snaily; x = -16-(snailxdis>>16); y = -16-(snailydis>>16); while (x>-192) { x-=32; mapx-=1; } while (y>-152) { y-=32; mapy-=1; } while (y<152) { maptile.x = x; maptile.y = y; tiletype = (int)(*(unsigned char *)(MAP_ADDRESS+(mapy*256)+mapx)); if (animate == 0) { tiletype = (animtable[(tiletype)]); *(unsigned char *)(MAP_ADDRESS+(mapy*256)+mapx) = (unsigned char)(tiletype); } tpagex = 320; tpagey = 0; u = 0; maptile.v = 0; while (tiletype>=22) { tiletype-=22; if ((maptile.v+=32) == 256){ maptile.v = 0; tpagey+=256; } } while ((tiletype-=1)>=0){ if ((u+=32) == 256){ u = 0; tpagex+=128; } } maptile.u=(u_char)(u); maptile.tpage = GetTPage(1,0,tpagex,tpagey); GsSortSprite( &maptile, &Wot[side], 2); x+=32; mapx+=1; if (x==192) { x-=384; y+=32; mapx-=12 ;mapy+=1; } if (x>192) { x-=416; y+=32; mapx-=13 ;mapy+=1; } } } void DealWithControllerPad (void) { static int framesSinceLastModeToggle = 0; if (snuffedit == 0) { // quit program if (pad & PADselect && fadeout == 0) { quit = 1; fadeout = 128; } // pause if (pad & PADstart) { while (pad & PADstart) { pad = PadRead(); } while (!(pad & PADstart)) { pad = PadRead(); } while (pad & PADstart) { pad = PadRead(); } } if (pad & PADRdown) { if (OKtojump==1) snailyspeed=-540672; } if (pad & PADLleft) { snaildirn = 1; if ((snailxspeed-=32768)<-540672) { snailxspeed = -540672; } } if (pad & PADLright) { snaildirn = 0; if ((snailxspeed+=32768)>540672) { snailxspeed = 540672; } } } } void MenuControllerPad () { if ((pad & PADstart || pad & PADRdown) && start == 0) { start = 1; while (pad & PADstart || pad & PADRdown) pad = PadRead(); } if (pad & PADselect) { quit = 2; } if (changedcode==0) { if (pad & PADLup || pad & PADLdown || pad & PADLleft || pad & PADLright) changedcode=1; if (pad & PADLup && passcode[digit]<9) passcode[digit]++; if (pad & PADLdown && passcode[digit]>0) passcode[digit]--; if (pad & PADLleft && digit>0) digit--; if (pad & PADLright && digit<7) digit++; } else { if (!(pad & PADLup || pad & PADLdown || pad & PADLleft || pad & PADLright)) changedcode=0; } } void InitialiseAll (void) { PadInit(); GsInitGraph(SCREEN_WIDTH,SCREEN_HEIGHT,GsINTER|GsOFSGPU,1,0); if( SCREEN_HEIGHT<480 ) GsDefDispBuff(0,0,0,SCREEN_HEIGHT); else GsDefDispBuff(0,0,0,0); GsInit3D(); Wot[0].length=OT_LENGTH; Wot[0].org=wtags[0]; Wot[1].length=OT_LENGTH; Wot[1].org=wtags[1]; GsClearOt(0,0,&Wot[0]); GsClearOt(0,0,&Wot[1]); ProperInitialiseTexture(MAINSPRS_ADDRESS, &MainSprsInfo); ProperInitialiseTexture(BACKGR_ADDRESS, &BackGrInfo); ProperInitialiseTexture(SNAIL_ADDRESS, &SnailInfo); ProperInitialiseTexture(ICONS_ADDRESS, &IconsInfo); ProperInitialiseTexture(NUMS_ADDRESS, &NumsInfo); ProperInitialiseTexture(TITLE_ADDRESS, &TitleInfo); ProperInitialiseTexture(BIGNUMS_ADDRESS, &BignumsInfo); ProperInitialiseTexture(NYTITLE_ADDRESS, &NYTitleInfo); ProperInitialiseTexture(INFO_ADDRESS, &InfoInfo); ProperInitialiseTexture(LOGO_ADDRESS, &LogoInfo); InitGsSprite(&maptile); InitGsSprite(&backgrtop); InitGsSprite(&backgrbottom); backgrtop.w = 80; backgrtop.h = 256; backgrtop.tpage = GetTPage(1,0,960,0); backgrbottom.w = 80; backgrbottom.h = 256; backgrbottom.tpage = GetTPage(1,0,960,256); InitGsSprite(&snailspr); snailspr.x = -16; snailspr.y = -16; InitGsSprite(&iconsprs); iconsprs.w = 16; iconsprs.h = 16; iconsprs.tpage = GetTPage(1,0,640,0); iconsprs.v = 32; InitGsSprite(&numsprs); numsprs.y = -104; numsprs.w = 16; numsprs.h = 16; numsprs.tpage = GetTPage(1,0,640,0); numsprs.v = 48; InitGsSprite(&bignumsprs); bignumsprs.w = 32; bignumsprs.h = 32; bignumsprs.v = 64; //FntLoad( 896, 256); //FntOpen( -144, -104, 32, 16, 0, 2); } // the second argument is a global declared next to the #define for // the TIM file main memory address; // it allows endless sprites to be easily linked to it later on void ProperInitialiseTexture (long address, GsIMAGE* imageInfo) { RECT rect; // +4 because we need to skip head of TIM file GsGetTimInfo( (u_long *)(address+4), imageInfo); rect.x = imageInfo->px; rect.y = imageInfo->py; rect.w = imageInfo->pw; rect.h = imageInfo->ph; LoadImage( &rect, imageInfo->pixel); // if image needs a CLUT, load it up // (pmode: 8 or 9 ==> texture is 4-bit or 8-bit) 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); } // wait for loading to finish DrawSync(0); } void InitGsSprite (GsSPRITE* sprite) { // initialise sprite to dummy sprite->attribute = 1<<24; sprite->x = 0; sprite->y = 0; sprite->w = 32; sprite->h = 32; sprite->tpage = 0; sprite->u = 0; sprite->v = 0; sprite->cx = 320; sprite->cy = 511; sprite->r = 128; sprite->g = 128; sprite->b = 128; sprite->mx = 0; sprite->my = 0; sprite->scalex = ONE; sprite->scaley = ONE; sprite->rotate = 0; }