diff --git a/makefile.gaz b/makefile.gaz index f1f8d9a7a..be776ccda 100644 --- a/makefile.gaz +++ b/makefile.gaz @@ -146,6 +146,7 @@ player_src := panimsfx \ pmodes \ psbutt \ pschop \ + psdead \ psduck \ psfall \ psidle \ diff --git a/source/player/player.cpp b/source/player/player.cpp index 6d9ccfa42..fa7240ab1 100644 --- a/source/player/player.cpp +++ b/source/player/player.cpp @@ -68,6 +68,8 @@ Vars ---- */ +int s_health; + /*---------------------------------------------------------------------- Function: Purpose: @@ -113,6 +115,8 @@ m_animFrame=0; m_cameraLookTimer=0; m_lastPadInput=m_padInput=0; + + s_health=5; } /*---------------------------------------------------------------------- @@ -239,49 +243,38 @@ Pos.vy=((Pos.vy-16)&0xfffffff0)+colHeight; // Was falling.. so we've just hit the ground if(m_currentState==STATE_BUTTFALL) { + // landed from a btt bounce setState(STATE_BUTTLAND); } else if(m_currentState==STATE_FALLFAR) { + // Landed from a painful long fall setState(STATE_IDLE); + takeDamage(DAMAGE__FALL); m_moveVel.vx=0; + CSoundMediator::playSfx(CSoundMediator::SFX_SPONGEBOB_LAND_AFTER_FALL); } else if(m_moveVel.vx) { + // Landed from a jump with x movement setState(STATE_RUN); -// setAnimNo(ANIM_PLAYER_ANIM_RUNJUMPEND); } else { + // Landed from a standing jump setState(STATE_IDLE); setAnimNo(ANIM_PLAYER_ANIM_JUMPEND); } -// m_moveVel.vy=0; + m_moveVel.vy=0; m_fallFrames=0; } -m_moveVel.vy=0; } else { - if(m_currentState!=STATE_JUMP&&m_currentState!=STATE_BUTTBOUNCE) + if(m_currentState!=STATE_FALL&&m_currentState!=STATE_BUTTFALL&& + m_currentState!=STATE_JUMP&&m_currentState!=STATE_BUTTBOUNCE) { - // Fall - if(m_currentState!=STATE_FALL&&m_currentState!=STATE_BUTTFALL) - { - setState(STATE_FALL); - } - const PlayerMetrics *metrics; - metrics=getPlayerMetrics(); - m_moveVel.vy+=PLAYER_GRAVITY; - if(m_moveVel.vy>=PLAYER_TERMINAL_VELOCITY<metrics->m_metric[PM__MAX_SAFE_FALL_FRAMES]) - { - setState(STATE_FALLFAR); - } - } + setState(STATE_FALL); } } @@ -297,6 +290,7 @@ if(getPadInputDown()&PAD_CIRCLE) { m_skel.blink(); } +/* if(pad&CPadConfig::getButton(CPadConfig::PAD_CFG_UP)) { if(m_cameraLookTimer<=-LOOKAROUND_DELAY) @@ -347,6 +341,7 @@ if(getPadInputDown()&PAD_CIRCLE) } } } +*/ } @@ -722,6 +717,69 @@ void CPlayer::jump() } void CPlayer::fall() { + const PlayerMetrics *metrics; + metrics=getPlayerMetrics(); + m_moveVel.vy+=PLAYER_GRAVITY; + if(m_moveVel.vy>=PLAYER_TERMINAL_VELOCITY<metrics->m_metric[PM__MAX_SAFE_FALL_FRAMES]) + { + setState(STATE_FALLFAR); + } + } + } +} + + +/*---------------------------------------------------------------------- + Function: + Purpose: + Params: + Returns: + ---------------------------------------------------------------------- */ +#ifdef __VERSION_DEBUG__ +int invincibleSponge=false; // NB: This is for debugging purposes only +#endif +void CPlayer::takeDamage(DAMAGE_TYPE _damage) +{ + // Don't take damage if still recovering from the last hit + if(!m_invincibleFrameCount) + { + int ouchThatHurt=true; + + // Check if we are currently immune to this damage type + switch(_damage) + { + case DAMAGE__FALL: + case DAMAGE__LAVA: + break; + + case DAMAGE__ELECTROCUTION: + // if squeaky boots then ouchThatHurt=false; + break; + } + + if(ouchThatHurt) + { +#ifdef __VERSION_DEBUG__ + if(invincibleSponge){m_invincibleFrameCount=INVINCIBLE_FRAMES__HIT;return;} +#endif + if(s_health) + { + m_invincibleFrameCount=INVINCIBLE_FRAMES__HIT; + s_health--; + } + else + { + CSoundMediator::playSfx(CSoundMediator::SFX_SPONGEBOB_DEFEATED_JINGLE); + setState(STATE_DEAD); + } + } + } } diff --git a/source/player/player.h b/source/player/player.h index fa2e96a75..0374f8acf 100644 --- a/source/player/player.h +++ b/source/player/player.h @@ -63,7 +63,9 @@ typedef enum STATE_DUCK, STATE_SOAKUP, STATE_GETUP, - + + STATE_DEAD, + NUM_STATES, }PLAYER_STATE; @@ -95,6 +97,13 @@ typedef enum NUM_PLAYER_METRICS }PLAYER_METRIC; +typedef enum +{ + DAMAGE__FALL, + DAMAGE__ELECTROCUTION, + DAMAGE__LAVA, +}DAMAGE_TYPE; + /*---------------------------------------------------------------------- Structure defintions @@ -167,6 +176,8 @@ protected: void jump(); void fall(); + void takeDamage(DAMAGE_TYPE _damage); + friend class CPlayerState; @@ -203,7 +214,7 @@ private: enum { INVIBCIBLE_FRAMES__START=120, // Invincible for this many frames at start of life - INVINCIBLE_FRAMES__HIT=25, // Invincible for this many frames after taking damage + INVINCIBLE_FRAMES__HIT=50, // Invincible for this many frames after taking damage LOOKAROUND_DELAY=90, // Frames before look around starts LOOKAROUND_SCROLLSPEED=2, // Speed to scroll at @@ -230,7 +241,7 @@ private: int m_lastPadInput; // Last frames controls int m_padInputDown; // Controls that were pressed this frame - // Pointer to the collision layer for the current layer + // Pointer to the collision layer for the current map class CLayerCollision *m_layerCollision; }; diff --git a/source/player/pmodes.cpp b/source/player/pmodes.cpp index 67148ef15..47847122d 100644 --- a/source/player/pmodes.cpp +++ b/source/player/pmodes.cpp @@ -45,6 +45,10 @@ #include "player\psduck.h" #endif +#ifndef __PLAYER__PSDEAD_H__ +#include "player\psdead.h" +#endif + /* Std Lib ------- */ @@ -84,6 +88,7 @@ CPlayerStateAirChop stateAirChop; CPlayerStateDuck stateDuck; CPlayerStateSoakUp stateSoackUp; CPlayerStateGetUp stateGetup; +CPlayerStateDead stateDead; @@ -124,6 +129,7 @@ CPlayer::PlayerMode CPlayer::s_modes[NUM_PLAYERMODES]= &stateDuck, // STATE_DUCK &stateSoackUp, // STATE_SOAKUP &stateGetup, // STATE_GETUP + &stateDead, // STATE_DEAD } }, @@ -156,6 +162,7 @@ CPlayer::PlayerMode CPlayer::s_modes[NUM_PLAYERMODES]= &stateDuck, // STATE_DUCK &stateSoackUp, // STATE_SOAKUP &stateGetup, // STATE_GETUP + &stateDead, // STATE_DEAD } }, @@ -188,6 +195,7 @@ CPlayer::PlayerMode CPlayer::s_modes[NUM_PLAYERMODES]= NULL, // STATE_DUCK NULL, // STATE_SOAKUP NULL, // STATE_GETUP + &stateDead, // STATE_DEAD } }, }; diff --git a/source/player/psbutt.cpp b/source/player/psbutt.cpp index ed66c6a66..bec05d9c4 100644 --- a/source/player/psbutt.cpp +++ b/source/player/psbutt.cpp @@ -98,6 +98,18 @@ void CPlayerStateButtBounceFall::enter(CPlayer *_player) } +/*---------------------------------------------------------------------- + Function: + Purpose: + Params: + Returns: + ---------------------------------------------------------------------- */ +void CPlayerStateButtBounceFall::think(CPlayer *_player) +{ + fall(_player); +} + + /*---------------------------------------------------------------------- Function: Purpose: diff --git a/source/player/psbutt.h b/source/player/psbutt.h index 0fb6658cd..52dc83602 100644 --- a/source/player/psbutt.h +++ b/source/player/psbutt.h @@ -44,6 +44,7 @@ class CPlayerStateButtBounceFall : public CPlayerState { public: virtual void enter(class CPlayer *_player); + virtual void think(class CPlayer *_player); }; diff --git a/source/player/psfall.cpp b/source/player/psfall.cpp index 78daec84e..703b8849e 100644 --- a/source/player/psfall.cpp +++ b/source/player/psfall.cpp @@ -96,6 +96,8 @@ void CPlayerStateFall::think(CPlayer *_player) slowdown(_player); } + fall(_player); + if(controlHeld&CPadConfig::getButton(CPadConfig::PAD_CFG_ACTION)) { setState(_player,STATE_AIRATTACK); @@ -148,6 +150,8 @@ void CPlayerStateFallFar::think(CPlayer *_player) { slowdown(_player); } + + fall(_player); } diff --git a/users/paul/spongebob project/spongebob project.dsp b/users/paul/spongebob project/spongebob project.dsp index e73057c7d..a504b442d 100644 --- a/users/paul/spongebob project/spongebob project.dsp +++ b/users/paul/spongebob project/spongebob project.dsp @@ -701,6 +701,14 @@ SOURCE=..\..\..\source\player\pschop.h # End Source File # Begin Source File +SOURCE=..\..\..\source\player\psdead.cpp +# End Source File +# Begin Source File + +SOURCE=..\..\..\source\player\psdead.h +# End Source File +# Begin Source File + SOURCE=..\..\..\source\player\psduck.cpp # End Source File # Begin Source File