map.c'*0smap.c8"NHhdB@LLLPTEXTCWIE'*s##include #include #include #include #include "map.h" #include "platform.h" #include "sprite.h" #include "addrs.h" #include "global.h" extern u_char screen; static u_char shoogle = 0; // For how long the screen still has to shake. static void Explode(u_char x, u_char y); static u_char CheckCollect2(u_char walldata, u_char* mappos, u_char heartcollect, u_char x, u_char y); static void GirderPuzzle(u_char x, u_char y); static void FlickGirder(u_char no); void CopyMap() { u_long pos; for (pos=0;pos<0x9000;pos++) { *((u_char*)mapaddr + pos) = *((u_char*)fullmapaddr + pos); } } void DisplayScreen(GsOT* OT) { GsSPRITE tilespr; u_char x,y,tile; u_short u,v; u_char *mapptr; char dispx,dispy; mapptr = (u_char*)mapaddr + screen*(20*15); InitSpr(&tilespr); tilespr.w = tilespr.h = 16; dispx = dispy = 0; if (shoogle>0) { shoogle--; dispx = (rand() % 5) - 2; dispy = (rand() % 5) - 2; } for (y=0;y<15;y++) { for (x=0;x<20;x++) { tile = *(mapptr++); v = 0; while (tile>=48) { tile-=48; v+=16; } u = 320*2 + tile*16; tilespr.x = x*16 + dispx; tilespr.y = y*16 + dispy; CalcSprPos(tilespr, u, v); GsSortFastSprite(&tilespr, OT, 15); } } } u_char Solid(int fullx, int fully) { u_char xdis = fullx & 15; u_char ydis = fully & 15; u_char x = fullx>>4; u_char y = fully>>4; u_char tltile, trtile, bltile, brtile; u_char *scrbase = (u_char*)mapaddr + screen*(20*15); tltile = *(scrbase+(y*20)+x); trtile = *(scrbase+(y*20)+x+1); bltile = *(scrbase+((y+1)*20)+x); brtile = *(scrbase+((y+1)*20)+x+1); tltile = *((u_char*)walldataaddr + tltile); trtile = *((u_char*)walldataaddr + trtile); bltile = *((u_char*)walldataaddr + bltile); brtile = *((u_char*)walldataaddr + brtile); if (xdis==0) {trtile = tltile; brtile = bltile;} if (ydis==0) {bltile = tltile; brtile = trtile;} return (tltile & 1 || trtile & 1 || bltile & 1 || brtile & 1); } u_char Deadly(int fullx, int fully) { u_char xdis = fullx & 15; u_char ydis = fully & 15; u_char x = fullx>>4; u_char y = fully>>4; u_char tltile, trtile, bltile, brtile; u_char *scrbase = (u_char*)mapaddr + screen*(20*15); tltile = *(scrbase+(y*20)+x); trtile = *(scrbase+(y*20)+x+1); bltile = *(scrbase+((y+1)*20)+x); brtile = *(scrbase+((y+1)*20)+x+1); tltile = *((u_char*)walldataaddr + tltile); trtile = *((u_char*)walldataaddr + trtile); bltile = *((u_char*)walldataaddr + bltile); brtile = *((u_char*)walldataaddr + brtile); if (xdis==0) {trtile = tltile; brtile = bltile;} if (ydis==0) {bltile = tltile; brtile = trtile;} return (tltile & 16 || trtile & 16 || bltile & 16 || brtile & 16); } u_char InWater(int fullx, int fully) { u_char xdis = fullx & 15; u_char ydis = fully & 15; u_char x = fullx>>4; u_char y = fully>>4; u_char tltile, trtile, bltile, brtile; u_char *scrbase = (u_char*)mapaddr + screen*(20*15); tltile = *(scrbase+(y*20)+x); trtile = *(scrbase+(y*20)+x+1); bltile = *(scrbase+((y+1)*20)+x); brtile = *(scrbase+((y+1)*20)+x+1); tltile = *((u_char*)walldataaddr + tltile); trtile = *((u_char*)walldataaddr + trtile); bltile = *((u_char*)walldataaddr + bltile); brtile = *((u_char*)walldataaddr + brtile); if (xdis==0) {trtile = tltile; brtile = bltile;} if (ydis==0) {bltile = tltile; brtile = trtile;} return (tltile & 32 || trtile & 32 || bltile & 32 || brtile & 32); } u_char SolidPix(int fullx, int fully) { u_char x = fullx>>4; u_char y = fully>>4; u_char tile; u_char *scrbase = (u_char*)mapaddr + screen*(20*15); if (x<0 || x>=20 || y<0 || y>=15) return 0; tile = *(scrbase+(y*20)+x); tile = *((u_char*)walldataaddr + tile); return (tile & 1); } u_char Target(int fullx, int fully) { u_char x = fullx>>4; u_char y = fully>>4; u_char tile; u_char *scrbase = (u_char*)mapaddr + screen*(20*15); if (x<0 || x>=20 || y<0 || y>=15) return 0; tile = *(scrbase+(y*20)+x); return (tile==75); } void Explosion(int fullx, int fully) { u_char x = fullx>>4; u_char y = fully>>4; Explode(x-1,y); Explode(x+1,y); Explode(x+2,y); Explode(x,y+1); Explode(x+1,y+1); Explode(x,y-1); Explode(x+1,y-1); } static void Explode(u_char x, u_char y) { u_char *scrbase = (u_char*)mapaddr + screen*(20*15); u_char tile; tile = *(scrbase+(y*20)+x); if (tile==68) *(scrbase+(y*20)+x) = 14; if (tile==71) *(scrbase+(y*20)+x) = 53; } u_char CheckCollect(int fullx, int fully, u_char heartcollect) { u_char xdis = fullx & 15; u_char ydis = fully & 15; u_char x = fullx>>4; u_char y = fully>>4; u_char tltile, trtile, bltile, brtile; u_char *scrbase = (u_char*)mapaddr + screen*(20*15); tltile = *(scrbase+(y*20)+x); trtile = *(scrbase+(y*20)+x+1); bltile = *(scrbase+((y+1)*20)+x); brtile = *(scrbase+((y+1)*20)+x+1); tltile = *((u_char*)walldataaddr + tltile); trtile = *((u_char*)walldataaddr + trtile); bltile = *((u_char*)walldataaddr + bltile); brtile = *((u_char*)walldataaddr + brtile); tltile = CheckCollect2(tltile, scrbase+(y*20)+x, heartcollect, x, y); if (xdis!=0) trtile = CheckCollect2(trtile, scrbase+(y*20)+x+1, heartcollect, x, y); else trtile = 0; if (ydis!=0) bltile = CheckCollect2(bltile, scrbase+((y+1)*20)+x, heartcollect, x, y); else bltile = 0; if (xdis!=0 && ydis!=0) brtile = CheckCollect2(brtile, scrbase+((y+1)*20)+x+1, heartcollect, x, y); else brtile = 0; return tltile | trtile | bltile | brtile; } static u_char CheckCollect2(u_char walldata, u_char* mappos, u_char heartcollect, u_char x, u_char y) { // Check single square pointed to by mappos to see if something should be collected. // heartcollect says wether a small heart should be collected if found. u_char *mapptr; int i; if (walldata & 2 && heartcollect) { // Small heart *(mappos) = 14; return 1; } if (walldata & 4) { // Large heart *(mappos) = 14; return 2; } if (walldata & 8) { if (screen==15) { // Jumping boots *(mappos) = 14; return 3; } if (screen==16) { // Switch 1 *(mappos) = 39; mapptr = (u_char*)mapaddr+300; *(mapptr+(6*20)+3) = 25; for (i=4;i<9;i++) *(mapptr+(6*20)+i) = 24; *(mapptr+(6*20)+9) = 26; *(mapptr+(7*20)+3) = 14; *(mapptr+(7*20)+9) = 14; *(mapptr+(8*20)+3) = 14; *(mapptr+(8*20)+9) = 14; for (i=3;i<10;i++) *(mapptr+(9*20)+i) = 14; shoogle = 64; } if (screen==24) { // Dynamite *(mappos) = 14; return 4; } if (screen==28) { // Switch 2 *(mappos) = 39; mapptr = (u_char*)mapaddr+(30*300); for (i=4;i<8;i++) *(mapptr+(i*20)+12) = 14; shoogle = 64; } if (screen==36) { // Switch 3 *(mappos) = 39; mapptr = (u_char*)mapaddr+(37*300); for (i=1;i<6;i++) *(mapptr+(8*20)+i) = 14; shoogle = 64; } if (screen==42) { // Diving mask *(mappos) = 14; return 5; } if (screen==51) { //Switch 4 *(mappos) = 39; mapptr = (u_char*)mapaddr+(15*300); *(mapptr+(10*20)+11) = 27; *(mapptr+(10*20)+15) = 27; *(mapptr+(11*20)+11) = 27; *(mapptr+(11*20)+15) = 27; *(mapptr+(12*20)+11) = 27; *(mapptr+(12*20)+15) = 27; *(mapptr+(11*20)+12) = 14; *(mapptr+(11*20)+13) = 14; *(mapptr+(11*20)+14) = 14; *(mapptr+(13*20)+11) = 28; *(mapptr+(13*20)+15) = 28; *(mapptr+(14*20)+11) = 25; *(mapptr+(14*20)+15) = 26; *(mapptr+(14*20)+12) = 24; *(mapptr+(14*20)+13) = 24; *(mapptr+(14*20)+14) = 24; shoogle = 64; } if (screen==58) { // Switch 5 *(mappos) = 39; mapptr = (u_char*)mapaddr+(54*300); *(mapptr+(6*20)+11) = 28; *(mapptr+(6*20)+15) = 28; *(mapptr+(7*20)+11) = 25; *(mapptr+(7*20)+15) = 26; *(mapptr+(7*20)+12) = 24; *(mapptr+(7*20)+13) = 24; *(mapptr+(7*20)+14) = 24; *(mapptr+(8*20)+11) = 14; *(mapptr+(8*20)+15) = 14; *(mapptr+(9*20)+11) = 14; *(mapptr+(9*20)+15) = 14; *(mapptr+(10*20)+11) = 14; *(mapptr+(10*20)+15) = 14; *(mapptr+(10*20)+12) = 14; *(mapptr+(10*20)+13) = 14; *(mapptr+(10*20)+14) = 14; shoogle = 64; } if (screen==75) GirderPuzzle(x, y); if (screen==87) { // Floating feather *(mappos) = 14; return 6; } if (screen==93) { // Switch 6 *(mappos) = 39; mapptr = (u_char*)mapaddr+(88*300); *(mapptr+(5*20)+1) = 27; *(mapptr+(5*20)+5) = 27; *(mapptr+(6*20)+1) = 28; *(mapptr+(6*20)+5) = 28; *(mapptr+(6*20)+2) = 14; *(mapptr+(6*20)+3) = 14; *(mapptr+(6*20)+4) = 14; *(mapptr+(7*20)+1) = 25; *(mapptr+(7*20)+5) = 26; *(mapptr+(7*20)+2) = 24; *(mapptr+(7*20)+3) = 24; *(mapptr+(7*20)+4) = 24; shoogle = 64; } if (screen==101) { // Switch 7 *(mappos) = 39; mapptr = (u_char*)mapaddr+(103*300); for (i=7;i<11;i++) *(mapptr+(i*20)) = 27; for (i=1;i<5;i++) *(mapptr+(11*20)+i) = 44; shoogle = 64; } if (screen==104) { // Bouncing bullets *(mappos) = 14; return 7; } if (screen==109) { // Switch 8 *(mappos) = 39; AddPlatform(109, 15, 7, 9, 7); } if (screen==113) { // Jetpack *(mappos) = 14; return 8; } } return 0; } static void GirderPuzzle(u_char x, u_char y) { u_char *mappos = (u_char*)mapaddr + (75*300); if (x<3 && y<3) { *(mappos+(2*20)+1) = 39; *(mappos+(3*20)+6) = 38; *(mappos+(6*20)+1) = 38; *(mappos+(7*20)+9) = 38; FlickGirder(2); FlickGirder(3); } else if (y<4) { *(mappos+(2*20)+1) = 38; *(mappos+(3*20)+6) = 39; *(mappos+(6*20)+1) = 38; *(mappos+(7*20)+9) = 38; FlickGirder(1); FlickGirder(3); } else if (x<3) { *(mappos+(2*20)+1) = 38; *(mappos+(3*20)+6) = 38; *(mappos+(6*20)+1) = 39; *(mappos+(7*20)+9) = 38; FlickGirder(2); FlickGirder(4); } else { *(mappos+(2*20)+1) = 38; *(mappos+(3*20)+6) = 38; *(mappos+(6*20)+1) = 38; *(mappos+(7*20)+9) = 39; FlickGirder(3); FlickGirder(4); } } static void FlickGirder(u_char no) { u_char *mappos = (u_char*)mapaddr + (75*300); u_char y = 2+no*2; int i; if (*(mappos+(y*20)+11)==53) { *(mappos+(y*20)+11) = 66; *(mappos+(y*20)+14) = 67; *(mappos+(y*20)+12) = 65; *(mappos+(y*20)+13) = 65; } else for (i=11;i<15;i++) *(mappos+(y*20)+i) = 53; }ZZR CP<`ϳtmap.cbug.tdtrmsix.harozentallerTEXTCWIE'"-3H Monaco4)4)a ZZRtX3jRMPSRMWBB*LR