player.c player.cNHhdB@LLLPTEXTCWIE#include #include #include #include #include "player.h" #include "map.h" #include "dynamite.h" #include "sprite.h" #include "bullet.h" #include "pad.h" #include "assert.h" #include "addrs.h" #include "global.h" static long plxpos = 128<<16, plypos = 128<<16; static long plxspeed = 0, plyspeed = 0; static u_char frame = 0, dirn = 0; static long framedel = 0; static u_char maxhearts = 10, hearts = 10; static u_char invulnerable = 0; static u_char firingdirn = 2; static u_char firedel = 0; // Delay until next shot can be fired static u_char items[6] = {0,0,0,0,0,0}; /* 0 - Shoes * 1 - Dynamite * 2 - Mask * 3 - Feather * 4 - Bouncing bullets * 5 - Jetpack */ extern u_char screen; static void LoseLife(void); void GetPlPos(long* x, long* y) { *(x) = plxpos; *(y) = plypos; } void PlotPlayer(GsOT* OT) { GsSPRITE playerspr, gunspr; if ((invulnerable & 8) == 0) { InitSpr(&playerspr); playerspr.w = playerspr.h = 16; playerspr.x = plxpos>>16; playerspr.y = plypos>>16; CalcSprPos(playerspr, 640 + (dirn*8*16) + (frame*16), 160); GsSortFastSprite(&playerspr, OT, 10); InitSpr(&gunspr); gunspr.w = gunspr.h = 16; gunspr.x = plxpos>>16; gunspr.y = plypos>>16; CalcSprPos(gunspr, 640 + (firingdirn*16), 128); GsSortFastSprite(&gunspr, OT, 9); } } static u_char firedirntable[16] = {0,0,2,1,4,0,3,2, 6,7,2,0,5,6,2,0}; u_char MovePlayer(long pad) { static u_char lastsolid = 0; u_char firingbuts = 0; short bulletdirn; u_char inwater = InWater(plxpos>>16, plypos>>16); // Deal with movement keypresses if (!inwater) { if (pad & PADLleft) { dirn = 1; if ((plxspeed-=16384) < -(4<<16)) plxspeed = -(4<<16); } if (pad & PADLright) { dirn = 0; if ((plxspeed+=16384) > (4<<16)) plxspeed = (4<<16); } } else { if (pad & PADLleft) { dirn = 1; if ((plxspeed-=8192) < -(3<<16)) plxspeed = -(3<<16); } if (pad & PADLright) { dirn = 0; if ((plxspeed+=8192) > (3<<16)) plxspeed = (3<<16); } } if (pad & PADL2 || pad & PADR2) { // Check if player has walked off edge. if (lastsolid==1 && !Solid(plxpos>>16, (plypos>>16)+1) && plypos>>16<220) { if (inwater) plyspeed = -(3<<16); else plyspeed = -((5<<16)+(items[0]<<16)); } } if (pad & PADLup || pad & PADR1) { if (items[5]) { if ((plyspeed-=(inwater ? 1<<14 : 1<<15)) < -(8<<16)) plyspeed = -(8<<16); AddBullet(plxpos+(8<<16), plypos+(14<<16), 2048 + ((rand() & 255) - 128), 2); } else if (plypos>>16 < 224) { // Try and jump if (Solid(plxpos>>16, (plypos>>16)+1)) { if (inwater) plyspeed = -(3<<16); else plyspeed = -((5<<16)+(items[0]<<16)); } } } if (pad & PADL1 && items[1]==1) DropDynamite(plxpos, plypos); // Find firing direction if (pad & PADRup) firingbuts |= 1; if (pad & PADRright) firingbuts |= 2; if (pad & PADRdown) firingbuts |= 4; if (pad & PADRleft) firingbuts |= 8; if (firingbuts==0) if (dirn==0) firingdirn = 2; else firingdirn = 6; else { firingdirn = firedirntable[firingbuts]; if (firedel^=1) { bulletdirn = firingdirn*512 + ((rand() & 255) - 128); if (bulletdirn>=4096) bulletdirn-=4096; if (bulletdirn<0) bulletdirn+=4096; AddBullet(plxpos+(8<<16), plypos+(9<<16), bulletdirn, 0); } } if (Solid(plxpos>>16, (plypos>>16)+1) && plypos>>16<220) lastsolid = 1; else lastsolid = 0; // Check if player gets hit by an enemy if (GetHit(plxpos>>16,plypos>>16) && invulnerable==0) LoseLife(); // Check if player is in water without mask if (inwater && items[2]==0 && invulnerable==0) LoseLife(); if (invulnerable>0) invulnerable--; // Move legs if ((framedel-=ABS(plxspeed)) < 0) { framedel = (4<<16); if (++frame == 8) frame = 0; } // Slow down if not pushing left or right if (!(pad & PADLleft) && !(pad & PADLright)) { if (dirn==0) { if ((plxspeed-=16384) < 0) plxspeed = 0; } else { if ((plxspeed+=16384) > 0) plxspeed = 0; } } // Check if moved off screen left or right plxpos+=plxspeed; if (plxpos>>16<0) { plxpos = (304<<16); screen = *((u_char*)maplinksaddr + screen*4 + 3); return 1; } if (plxpos>>16>304) { plxpos = 0; screen = *((u_char*)maplinksaddr + screen*4 + 1); return 1; } // Check if player ran into a wall if (Solid(plxpos>>16, plypos>>16) ) { if (plxspeed>0) { plxpos>>=20; plxpos<<=20; } else { plxpos>>=20; plxpos+=1; plxpos<<=20; } plxspeed = 0; } // Check if moved off screen up or down plypos+=plyspeed; if (plypos>>16<0) { plypos = (224<<16); screen = *((u_char*)maplinksaddr + screen*4); return 1; } if (plypos>>16>224) { plypos = 0; screen = *((u_char*)maplinksaddr + screen*4 + 2); return 1; } // Check if player landed on spikes if (Deadly(plxpos>>16, plypos>>16) && invulnerable==0) LoseLife(); // Check if player ran into a wall if (Solid(plxpos>>16, plypos>>16)) { if (plyspeed>0) { plypos>>=20; plypos<<=20; } else { plypos>>=20; plypos+=1; plypos<<=20; } plyspeed = 0; } if (items[3] && !items[5] && (pad & PADLup || pad & PADR1 || pad & PADL2 || pad & PADR2)) { if ((plyspeed+= (inwater ? 1<<12 : 1<<14) )>(1<<14)) plyspeed = (1<<14);// Float } else { if (!inwater) { if ((plyspeed+=1<<14)>(8<<16)) plyspeed = (8<<16); } else { if ((plyspeed+=1<<12)>(4<<16)) plyspeed = (4<<16); } } switch(CheckCollect(plxpos>>16, plypos>>16, maxhearts-hearts)) { case 1: hearts++; break; case 2: hearts++; maxhearts++; break; case 3: items[0] = 1; break; case 4: items[1] = 1; break; case 5: items[2] = 1; break; case 6: items[3] = 1; break; case 7: SetBounce(1); items[4] = 1; break; case 8: items[5] = 1; break; } if (hearts>128) return 255; return 0; } void PlotStatusBar(GsOT* OT) { GsSPRITE heartspr; u_char heartcount = hearts; u_char maxheartcount = maxhearts; InitSpr(&heartspr); heartspr.w = heartspr.h = 16; heartspr.x = heartspr.y = 0; CalcSprPos(heartspr, 640 + 8*16, 144); while (heartcount>0) { heartcount--; maxheartcount--; GsSortFastSprite(&heartspr, OT, 10); heartspr.x+=16; } CalcSprPos(heartspr, 640 + 9*16, 144); while (maxheartcount>0) { maxheartcount--; GsSortFastSprite(&heartspr, OT, 10); heartspr.x+=16; } } u_char ShotPlayer(long x, long y) { if (x+2>plxpos>>16 && x-14>16 && y+2>plypos>>16 && y-14>16 && !invulnerable) { LoseLife(); return 1; } return 0; } static void LoseLife() { hearts--; invulnerable = 192; } void GetAllItems() { int i; for (i=0;i<6;i++) items[i] = 1; }ZZR=?@Aplayer.ctererefix.harozentallerTEXTCWIE@ QH Monaco3DW3DW__ZZRfO0RMPSRMWBB*LR