From a75e84604caf756b9b5cbcca133e777fe3c03902 Mon Sep 17 00:00:00 2001 From: Paul Date: Tue, 3 Apr 2001 16:47:07 +0000 Subject: [PATCH] --- source/player/player.cpp | 42 -------------------- source/player/player.h | 1 - source/player/pmcoral.cpp | 52 ++++++++++++++++++++++++- source/player/pmcoral.h | 3 ++ source/player/pmodes.cpp | 80 +++++++++++++-------------------------- source/player/pmodes.h | 6 ++- source/player/psbutt.cpp | 5 +++ source/player/psbutt.h | 5 +++ source/player/psduck.cpp | 5 +++ source/player/psduck.h | 5 +++ source/player/psfall.cpp | 14 ++++++- source/player/psfall.h | 4 ++ source/player/psidle.cpp | 8 ++-- source/player/psidle.h | 5 +++ source/player/psjump.cpp | 3 ++ source/player/psjump.h | 3 ++ source/player/psrun.cpp | 36 +++++++++++------- source/player/psrun.h | 24 +++++++++++- 18 files changed, 183 insertions(+), 118 deletions(-) diff --git a/source/player/player.cpp b/source/player/player.cpp index 7b2b78727..0dfc1b01a 100644 --- a/source/player/player.cpp +++ b/source/player/player.cpp @@ -182,14 +182,6 @@ int MAP2D_CENTRE_X=-256; int MAP2D_CENTRE_Y=-136; int MAP2D_BLOCKSTEPSIZE=16; -int CAMERA_SCROLLLIMIT=3;//8; // SB is this many tiles off centre at most -int CAMERA_SCROLLTHRESHOLD=6; // If SB moves when more than this many tiles off-centre, the camera will *always* scroll -int CAMERA_STARTMOVETHRESHOLD=20; // If SB moves faster than this then the camera starts scrolling -int CAMERA_STOPMOVETHRESHOLD=10; // If SB moves slower than this then the camera stops scrolling -int CAMERA_SCROLLSPEED=60; // Speed of the scroll ( 60=1 tile scrolled every 4 and a bit frames ) - - - CPlayerModeBase PLAYERMODE; CPlayerModeChop PLAYERMODECHOP; CPlayerModeBalloon PLAYERMODEBALLOON; @@ -254,15 +246,11 @@ m_animFrame=0; m_cameraOffset.vx=0; m_cameraOffset.vy=0; - m_cameraScrollDir=0; m_lastPadInput=m_padInput=PI_NONE; s_screenPos=128; -//!! m_actorGfx.setAng(512); -//m_actorGfx.setAngInc(678); - setCollisionSize(25,50); setCollisionCentreOffset(0,-25); @@ -347,32 +335,6 @@ else if(Pos.vy>m_mapEdge.vy-64)Pos.vy=m_mapEdge.vy-64; // Look around int pad=getPadInputHeld(); - - // Camera scroll.. - if(m_cameraScrollDir==-1) - { - if(m_cameraScrollPos.vx>-CAMERA_SCROLLLIMIT<<8) - { - m_cameraScrollPos.vx-=CAMERA_SCROLLSPEED; - if(m_cameraScrollPos.vx<-CAMERA_SCROLLLIMIT<<8) - { - m_cameraScrollPos.vx=-CAMERA_SCROLLLIMIT<<8; - m_cameraScrollDir=0; - } - } - } - else if(m_cameraScrollDir==+1) - { - if(m_cameraScrollPos.vx<(CAMERA_SCROLLLIMIT<<8)) - { - m_cameraScrollPos.vx+=CAMERA_SCROLLSPEED; - if(m_cameraScrollPos.vx>CAMERA_SCROLLLIMIT<<8) - { - m_cameraScrollPos.vx=CAMERA_SCROLLLIMIT<<8; - m_cameraScrollDir=0; - } - } - } } @@ -393,25 +355,21 @@ else if(Pos.vy>m_mapEdge.vy-64)Pos.vy=m_mapEdge.vy-64; { m_playerScreenGeomPos.vx+=m_cameraPos.vx; m_cameraPos.vx=0; - m_cameraScrollDir=0; } else if(m_cameraPos.vx>m_mapCameraEdges.vx) { m_playerScreenGeomPos.vx-=m_mapCameraEdges.vx-m_cameraPos.vx; m_cameraPos.vx=m_mapCameraEdges.vx; - m_cameraScrollDir=0; } if(m_cameraPos.vy<0) { m_playerScreenGeomPos.vy+=m_cameraPos.vy; m_cameraPos.vy=0; - m_cameraScrollDir=0; } else if(m_cameraPos.vy>m_mapCameraEdges.vy) { m_playerScreenGeomPos.vy-=m_mapCameraEdges.vy-m_cameraPos.vy; m_cameraPos.vy=m_mapCameraEdges.vy; - m_cameraScrollDir=0; } CPlayerThing::think(_frames); diff --git a/source/player/player.h b/source/player/player.h index 9f0f50d0d..76f68746d 100644 --- a/source/player/player.h +++ b/source/player/player.h @@ -192,7 +192,6 @@ private: DVECTOR m_playerScreenGeomPos; DVECTOR m_cameraPos; - int m_cameraScrollDir; int m_facing; diff --git a/source/player/pmcoral.cpp b/source/player/pmcoral.cpp index 48e0dc2cf..13816c81c 100644 --- a/source/player/pmcoral.cpp +++ b/source/player/pmcoral.cpp @@ -21,6 +21,27 @@ #include "gfx\sprbank.h" #endif +// States +#ifndef __PLAYER__PSJUMP_H__ +#include "player\psjump.h" +#endif + +#ifndef __PLAYER__PSRUN_H__ +#include "player\psrun.h" +#endif + +#ifndef __PLAYER__PSFALL_H__ +#include "player\psfall.h" +#endif + +#ifndef __PLAYER__PSIDLE_H__ +#include "player\psidle.h" +#endif + +#ifndef __PLAYER__PSDUCK_H__ +#include "player\psduck.h" +#endif + /* Std Lib ------- */ @@ -53,7 +74,25 @@ Vars ---- */ -static PlayerMetrics s_playerMetrics= +static CPlayerState *s_stateTable[]= +{ + &s_stateCoralBlowerIdle, // STATE_IDLE + &s_stateCoralBlowerIdle, // STATE_IDLETEETER + &s_stateJump, // STATE_JUMP + &s_stateWalk, // STATE_RUN + &s_stateFall, // STATE_FALL + &s_stateFallFar, // STATE_FALLFAR + NULL, // STATE_BUTTBOUNCE + NULL, // STATE_BUTTFALL + NULL, // STATE_BUTTLAND + NULL, // STATE_DUCK + NULL, // STATE_SOAKUP + &s_stateGetUp, // STATE_GETUP +}; + + + +static PlayerMetrics s_playerMetrics= { { DEFAULT_PLAYER_JUMP_VELOCITY/2, // PM__JUMP_VELOCITY DEFAULT_PLAYER_MAX_JUMP_FRAMES/2, // PM__MAX_JUMP_FRAMES @@ -160,5 +199,16 @@ const struct PlayerMetrics *CPlayerModeCoralBlower::getPlayerMetrics() return &s_playerMetrics; } +/*---------------------------------------------------------------------- + Function: + Purpose: + Params: + Returns: + ---------------------------------------------------------------------- */ +CPlayerState **CPlayerModeCoralBlower::getStateTable() +{ + return s_stateTable; +} + /*=========================================================================== end */ diff --git a/source/player/pmcoral.h b/source/player/pmcoral.h index 0dfd58c95..3cebe1734 100644 --- a/source/player/pmcoral.h +++ b/source/player/pmcoral.h @@ -43,6 +43,9 @@ public: virtual const struct PlayerMetrics *getPlayerMetrics(); +protected: + virtual class CPlayerState **getStateTable(); + private: typedef enum { diff --git a/source/player/pmodes.cpp b/source/player/pmodes.cpp index 65a9b44ca..0ff16b849 100644 --- a/source/player/pmodes.cpp +++ b/source/player/pmodes.cpp @@ -82,36 +82,23 @@ Vars ---- */ -static CPlayerStateUnarmedIdle stateUnarmedIdle; -static CPlayerStateTeeterIdle stateTeeterIdle; -static CPlayerStateJump stateJump; -static CPlayerStateRun stateRun; -static CPlayerStateFall stateFall; -static CPlayerStateFallFar stateFallFar; -static CPlayerStateDuck stateDuck; -static CPlayerStateSoakUp stateSoakUp; -static CPlayerStateGetUp stateGetUp; -static CPlayerStateButtBounce stateButtBounce; -static CPlayerStateButtBounceFall stateButtBounceFall; -static CPlayerStateButtBounceLand stateButtBounceLand; - -CPlayerState *CPlayerModeBase::s_stateTable[]= +static CPlayerState *s_stateTable[]= { - &stateUnarmedIdle, // STATE_IDLE - &stateTeeterIdle, // STATE_IDLETEETER - &stateJump, // STATE_JUMP - &stateRun, // STATE_RUN - &stateFall, // STATE_FALL - &stateFallFar, // STATE_FALLFAR - &stateButtBounce, // STATE_BUTTBOUNCE - &stateButtBounceFall, // STATE_BUTTFALL - &stateButtBounceLand, // STATE_BUTTLAND - &stateDuck, // STATE_DUCK - &stateSoakUp, // STATE_SOAKUP - &stateGetUp, // STATE_GETUP + &s_stateUnarmedIdle, // STATE_IDLE + &s_stateTeeterIdle, // STATE_IDLETEETER + &s_stateJump, // STATE_JUMP + &s_stateRun, // STATE_RUN + &s_stateFall, // STATE_FALL + &s_stateFallFar, // STATE_FALLFAR + &s_stateButtBounce, // STATE_BUTTBOUNCE + &s_stateButtBounceFall, // STATE_BUTTFALL + &s_stateButtBounceLand, // STATE_BUTTLAND + &s_stateDuck, // STATE_DUCK + &s_stateSoakUp, // STATE_SOAKUP + &s_stateGetUp, // STATE_GETUP }; -static PlayerMetrics s_playerMetrics= +static PlayerMetrics s_playerMetrics= { { DEFAULT_PLAYER_JUMP_VELOCITY, // PM__JUMP_VELOCITY DEFAULT_PLAYER_MAX_JUMP_FRAMES, // PM__MAX_JUMP_FRAMES @@ -172,7 +159,7 @@ void CPlayerModeBase::enter() ---------------------------------------------------------------------- */ void CPlayerModeBase::think() { - s_stateTable[m_currentState]->think(this); + getStateTable()[m_currentState]->think(this); thinkVerticalMovement(); thinkHorizontalMovement(); @@ -274,7 +261,7 @@ void CPlayerModeBase::thinkVerticalMovement() else if(m_currentState==STATE_FALLFAR) { // Landed from a painfully long fall - setState(STATE_IDLE); + setState(STATE_GETUP); m_player->takeDamage(DAMAGE__FALL); m_moveVelocity.vx=0; CSoundMediator::playSfx(CSoundMediator::SFX_SPONGEBOB_LAND_AFTER_FALL); @@ -486,7 +473,7 @@ int CPlayerModeBase::setState(int _state) CPlayerState *nextState; int ret=false; - nextState=s_stateTable[_state]; + nextState=getStateTable()[_state]; if(nextState) { m_currentStateClass=nextState; @@ -618,17 +605,6 @@ void CPlayerModeBase::moveLeft() { m_moveVelocity.vx-=metrics->m_metric[PM__RUN_REVERSESLOWDOWN]; } - - /* - if(m_moveVelocity.vx<-CAMERA_STARTMOVETHRESHOLD||m_cameraScrollPos.vx<-CAMERA_SCROLLTHRESHOLD<<8) - { - m_cameraScrollDir=+1; - } - else if(m_moveVelocity.vx>-CAMERA_STOPMOVETHRESHOLD) - { - m_cameraScrollDir=0; - } - */ } void CPlayerModeBase::moveRight() @@ -649,17 +625,6 @@ void CPlayerModeBase::moveRight() { m_moveVelocity.vx+=metrics->m_metric[PM__RUN_REVERSESLOWDOWN]; } - - /* - if(m_moveVelocity.vx>CAMERA_STARTMOVETHRESHOLD||m_cameraScrollPos.vx>CAMERA_SCROLLTHRESHOLD<<8) - { - m_cameraScrollDir=-1; - } - else if(m_moveVelocity.vxgetAnimFrame(); + { + if(_playerMode->advanceAnimFrameAndCheckForEndOfAnim()) + { + _playerMode->setAnimFrame(frame); + } + } + controlHeld=_playerMode->getPadInputHeld(); - if(controlHeld&PI_LEFT) { _playerMode->moveLeft(); diff --git a/source/player/psfall.h b/source/player/psfall.h index 392043949..2ab9944f0 100644 --- a/source/player/psfall.h +++ b/source/player/psfall.h @@ -54,6 +54,10 @@ private: Globals ------- */ +extern CPlayerStateFall s_stateFall; +extern CPlayerStateFallFar s_stateFallFar; + + /*---------------------------------------------------------------------- Functions --------- */ diff --git a/source/player/psidle.cpp b/source/player/psidle.cpp index 462d776f7..1085f21ac 100644 --- a/source/player/psidle.cpp +++ b/source/player/psidle.cpp @@ -54,6 +54,10 @@ Vars ---- */ +CPlayerStateUnarmedIdle s_stateUnarmedIdle; +CPlayerStateTeeterIdle s_stateTeeterIdle; +CPlayerStateCoralBlowerIdle s_stateCoralBlowerIdle; + /*---------------------------------------------------------------------- Function: @@ -81,10 +85,6 @@ void CPlayerStateBaseIdle::thinkControl(CPlayerModeBase *_playerMode) if(_playerMode->canMoveRight()) _playerMode->setState(STATE_RUN); } - else if(controlDown&PI_ACTION) - { -// _playerMode->setState(STATE_ATTACK); - } else if(controlHeld&PI_DOWN) { _playerMode->setState(STATE_DUCK); diff --git a/source/player/psidle.h b/source/player/psidle.h index 84a0f26a3..4bafa173d 100644 --- a/source/player/psidle.h +++ b/source/player/psidle.h @@ -107,6 +107,11 @@ private: Globals ------- */ +extern CPlayerStateUnarmedIdle s_stateUnarmedIdle; +extern CPlayerStateTeeterIdle s_stateTeeterIdle; +extern CPlayerStateCoralBlowerIdle s_stateCoralBlowerIdle; + + /*---------------------------------------------------------------------- Functions --------- */ diff --git a/source/player/psjump.cpp b/source/player/psjump.cpp index 9a5002730..372717d29 100644 --- a/source/player/psjump.cpp +++ b/source/player/psjump.cpp @@ -59,6 +59,9 @@ Vars ---- */ +CPlayerStateJump s_stateJump; + + /*---------------------------------------------------------------------- Function: Purpose: diff --git a/source/player/psjump.h b/source/player/psjump.h index 49a058db6..51eebfbd0 100644 --- a/source/player/psjump.h +++ b/source/player/psjump.h @@ -48,6 +48,9 @@ private: Globals ------- */ +extern CPlayerStateJump s_stateJump; + + /*---------------------------------------------------------------------- Functions --------- */ diff --git a/source/player/psrun.cpp b/source/player/psrun.cpp index 7e60f66a7..cfe8e8db4 100644 --- a/source/player/psrun.cpp +++ b/source/player/psrun.cpp @@ -33,11 +33,6 @@ /* Data ---- */ -#ifndef __ANIM_SPONGEBOB_HEADER__ -#include -#endif - - /*---------------------------------------------------------------------- Tyepdefs && Defines ------------------- */ @@ -54,6 +49,10 @@ Vars ---- */ +CPlayerStateRun s_stateRun; +CPlayerStateWalk s_stateWalk; + + /*---------------------------------------------------------------------- Function: Purpose: @@ -67,12 +66,17 @@ void CPlayerStateRun::enter(CPlayerModeBase *_playerMode) if(_playerMode->getMoveVelocity().vx) { - _playerMode->setAnimNo(ANIM_SPONGEBOB_RUN); + _playerMode->setAnimNo(getLoopFrame()); } else { -//!! _playerMode->setAnimNo(ANIM_SPONGEBOB_RUNSTART); - _playerMode->setAnimNo(ANIM_SPONGEBOB_FIRE); + int frame; + frame=getStartFrame(); + if(frame==-1) + { + frame=getLoopFrame(); + } + _playerMode->setAnimNo(frame); } if(controlHeld&PI_LEFT) @@ -84,7 +88,7 @@ void CPlayerStateRun::enter(CPlayerModeBase *_playerMode) _playerMode->setFacing(FACING_RIGHT); } - m_numberOfTimeAnimHasLooped=0; + m_numberOfTimesAnimHasLooped=0; } @@ -125,10 +129,14 @@ void CPlayerStateRun::think(CPlayerModeBase *_playerMode) if(_playerMode->slowdown()) { _playerMode->setState(STATE_IDLE); - if(m_numberOfTimeAnimHasLooped>=4) + if(m_numberOfTimesAnimHasLooped>=4) { -//!! _playerMode->setAnimNo(ANIM_SPONGEBOB_RUNSTOP); - _playerMode->setAnimNo(ANIM_SPONGEBOB_FIRE); + int frame; + frame=getStartFrame(); + if(frame!=-1) + { + _playerMode->setAnimNo(getEndFrame()); + } } return; } @@ -137,8 +145,8 @@ void CPlayerStateRun::think(CPlayerModeBase *_playerMode) if(_playerMode->advanceAnimFrameAndCheckForEndOfAnim()) { - _playerMode->setAnimNo(ANIM_SPONGEBOB_RUN); - m_numberOfTimeAnimHasLooped++; + _playerMode->setAnimNo(getLoopFrame()); + m_numberOfTimesAnimHasLooped++; } } diff --git a/source/player/psrun.h b/source/player/psrun.h index 376b4b474..8c03a76ac 100644 --- a/source/player/psrun.h +++ b/source/player/psrun.h @@ -20,6 +20,10 @@ #include "player\pstates.h" +#ifndef __ANIM_SPONGEBOB_HEADER__ +#include +#endif + /* Std Lib ------- */ @@ -38,8 +42,22 @@ public: void enter(class CPlayerModeBase *_playerMode); void think(class CPlayerModeBase *_playerMode); +protected: + virtual int getStartFrame() {return ANIM_SPONGEBOB_FIRE;} + virtual int getLoopFrame() {return ANIM_SPONGEBOB_RUN;} + virtual int getEndFrame() {return ANIM_SPONGEBOB_FIRE;} + private: - int m_numberOfTimeAnimHasLooped; + int m_numberOfTimesAnimHasLooped; +}; + + +class CPlayerStateWalk : public CPlayerStateRun +{ +protected: + virtual int getStartFrame() {return -1;} + virtual int getLoopFrame() {return ANIM_SPONGEBOB_WALK;} + virtual int getEndFrame() {return -1;} }; @@ -47,6 +65,10 @@ private: Globals ------- */ +extern CPlayerStateRun s_stateRun; +extern CPlayerStateWalk s_stateWalk; + + /*---------------------------------------------------------------------- Functions --------- */