diff --git a/source/player/psfall.cpp b/source/player/psfall.cpp new file mode 100644 index 000000000..f674697e3 --- /dev/null +++ b/source/player/psfall.cpp @@ -0,0 +1,132 @@ + +/*========================================================================= + + psfall.cpp + + Author: PKG + Created: + Project: Spongebob + Purpose: + + Copyright (c) 2001 Climax Development Ltd + +===========================================================================*/ + + +/*---------------------------------------------------------------------- + Includes + -------- */ + +#include "player\psfall.h" + +#ifndef __PLAYER_PLAYER_H__ +#include "player\player.h" +#endif + +#ifndef __PAD_PADS_H__ +#include "pad\pads.h" +#endif + + + + +/* Std Lib + ------- */ + +/* Data + ---- */ + +#ifndef __ANIM_PLAYER_ANIM_HEADER__ +#include +#endif + + +/*---------------------------------------------------------------------- + Tyepdefs && Defines + ------------------- */ + +/*---------------------------------------------------------------------- + Structure defintions + -------------------- */ + +/*---------------------------------------------------------------------- + Function Prototypes + ------------------- */ + +/*---------------------------------------------------------------------- + Vars + ---- */ + +/*---------------------------------------------------------------------- + Function: + Purpose: + Params: + Returns: + ---------------------------------------------------------------------- */ +void CPlayerStateFall::enter(CPlayer *_player) +{ + setAnimNo(_player,ANIM_PLAYER_ANIM_JUMPSTART); + m_fallFrames=0; +} + + +/*---------------------------------------------------------------------- + Function: + Purpose: + Params: + Returns: + ---------------------------------------------------------------------- */ +void CPlayerStateFall::think(CPlayer *_player) +{ + int control; + DVECTOR move; + + control=getPadInput(_player); + + move=getMoveVelocity(_player); + move.vy+=GRAVITY_VALUE; + if(move.vy>=TERMINAL_VELOCITY<MAX_SAFE_FALL_FRAMES) + { + setState(_player,STATE_FALLFAR); + } + } + setMoveVelocity(_player,&move); + + if(control&PAD_LEFT) + { + moveLeft(_player); + } + else if(control&PAD_RIGHT) + { + moveRight(_player); + } + else + { + slowdown(_player); + } + +/* + if(isOnSolidGround(_player)) + { + move=getMoveVelocity(_player); +// if(move.vx) +// { +// setState(_player,STATE_RUN); +// } +// else + { + setState(_player,STATE_IDLE); + } + move.vy=0; + setMoveVelocity(_player,&move); + } +*/ +} + + +/*=========================================================================== + end */ diff --git a/source/player/psfall.h b/source/player/psfall.h new file mode 100644 index 000000000..ca54a6ea6 --- /dev/null +++ b/source/player/psfall.h @@ -0,0 +1,68 @@ +/*========================================================================= + + psfall.h + + Author: PKG + Created: + Project: Spongebob + Purpose: + + Copyright (c) 2001 Climax Development Ltd + +===========================================================================*/ + +#ifndef __PLAYER_PSFALL_H__ +#define __PLAYER_PSFALL_H__ + +/*---------------------------------------------------------------------- + Includes + -------- */ + +#include "player\pstates.h" + + +/* Std Lib + ------- */ + +/*---------------------------------------------------------------------- + Tyepdefs && Defines + ------------------- */ + +/*---------------------------------------------------------------------- + Structure defintions + -------------------- */ + +class CPlayerStateFall : public CPlayerState +{ +public: + void enter(class CPlayer *_player); + void think(class CPlayer *_player); + +private: + int m_fallFrames; + +}; + + +class CPlayerStateFallFar : public CPlayerStateFall +{ +}; + + +/*---------------------------------------------------------------------- + Globals + ------- */ + +/*---------------------------------------------------------------------- + Functions + --------- */ + +/*---------------------------------------------------------------------- */ + +#endif /* __PLAYER_PSFALL_H__ */ + +/*=========================================================================== + end */ + + + diff --git a/source/player/psjump.cpp b/source/player/psjump.cpp new file mode 100644 index 000000000..2819979c1 --- /dev/null +++ b/source/player/psjump.cpp @@ -0,0 +1,120 @@ + +/*========================================================================= + + psjump.cpp + + Author: PKG + Created: + Project: Spongebob + Purpose: + + Copyright (c) 2001 Climax Development Ltd + +===========================================================================*/ + + +/*---------------------------------------------------------------------- + Includes + -------- */ + +#include "player\psjump.h" + +#ifndef __PLAYER_PLAYER_H__ +#include "player\player.h" +#endif + +#ifndef __PAD_PADS_H__ +#include "pad\pads.h" +#endif + + +/* Std Lib + ------- */ + +/* Data + ---- */ + +#ifndef __ANIM_PLAYER_ANIM_HEADER__ +#include +#endif + + +/*---------------------------------------------------------------------- + Tyepdefs && Defines + ------------------- */ + +/*---------------------------------------------------------------------- + Structure defintions + -------------------- */ + +/*---------------------------------------------------------------------- + Function Prototypes + ------------------- */ + +/*---------------------------------------------------------------------- + Vars + ---- */ + +/*---------------------------------------------------------------------- + Function: + Purpose: + Params: + Returns: + ---------------------------------------------------------------------- */ +void CPlayerStateJump::enter(CPlayer *_player) +{ + setAnimNo(_player,ANIM_PLAYER_ANIM_JUMPSTART); + m_jumpFrames=0; + DVECTOR move=getMoveVelocity(_player); + move.vy=-JUMP_VELOCITY<=0) + { + setState(_player,STATE_FALL); + } + else + { + move.vy+=GRAVITY_VALUE; + } + setMoveVelocity(_player,&move); + } + + if(control&PAD_LEFT) + { + moveLeft(_player); + } + else if(control&PAD_RIGHT) + { + moveRight(_player); + } + else + { + slowdown(_player); + } +} + + +/*=========================================================================== + end */ diff --git a/source/player/psjump.h b/source/player/psjump.h new file mode 100644 index 000000000..174ea0252 --- /dev/null +++ b/source/player/psjump.h @@ -0,0 +1,63 @@ +/*========================================================================= + + psjump.h + + Author: PKG + Created: + Project: Spongebob + Purpose: + + Copyright (c) 2001 Climax Development Ltd + +===========================================================================*/ + +#ifndef __PLAYER_PSJUMP_H__ +#define __PLAYER_PSJUMP_H__ + +/*---------------------------------------------------------------------- + Includes + -------- */ + +#include "player\pstates.h" + + +/* Std Lib + ------- */ + +/*---------------------------------------------------------------------- + Tyepdefs && Defines + ------------------- */ + +/*---------------------------------------------------------------------- + Structure defintions + -------------------- */ + +class CPlayerStateJump : public CPlayerState +{ +public: + void enter(class CPlayer *_player); + void think(class CPlayer *_player); + +private: + int m_jumpFrames; + +}; + + +/*---------------------------------------------------------------------- + Globals + ------- */ + +/*---------------------------------------------------------------------- + Functions + --------- */ + +/*---------------------------------------------------------------------- */ + +#endif /* __PLAYER_PSJUMP_H__ */ + +/*=========================================================================== + end */ + + + diff --git a/source/player/psrun.cpp b/source/player/psrun.cpp new file mode 100644 index 000000000..e09bb0376 --- /dev/null +++ b/source/player/psrun.cpp @@ -0,0 +1,138 @@ +/*========================================================================= + + psrun.cpp + + Author: PKG + Created: + Project: Spongebob + Purpose: + + Copyright (c) 2001 Climax Development Ltd + +===========================================================================*/ + + +/*---------------------------------------------------------------------- + Includes + -------- */ + +#include "player\psrun.h" + +#ifndef __PLAYER_PLAYER_H__ +#include "player\player.h" +#endif + +#ifndef __UTILS_HEADER__ +#include "utils\utils.h" +#endif + +#ifndef __PAD_PADS_H__ +#include "pad\pads.h" +#endif + + +/* Std Lib + ------- */ + +/* Data + ---- */ + +#ifndef __ANIM_PLAYER_ANIM_HEADER__ +#include +#endif + + +/*---------------------------------------------------------------------- + Tyepdefs && Defines + ------------------- */ + +/*---------------------------------------------------------------------- + Structure defintions + -------------------- */ + +/*---------------------------------------------------------------------- + Function Prototypes + ------------------- */ + +/*---------------------------------------------------------------------- + Vars + ---- */ + +/*---------------------------------------------------------------------- + Function: + Purpose: + Params: + Returns: + ---------------------------------------------------------------------- */ +void CPlayerStateRun::enter(CPlayer *_player) +{ + int control; + control=getPadInput(_player); + + if(getMoveVelocity(_player).vx) + { + setAnimNo(_player,ANIM_PLAYER_ANIM_RUN); + } + else + { + setAnimNo(_player,ANIM_PLAYER_ANIM_RUNSTART); + } + + if(control&PAD_LEFT) + { + setFacing(_player,FACING_LEFT); + } + else if(control&PAD_RIGHT) + { + setFacing(_player,FACING_RIGHT); + } +} + + +/*---------------------------------------------------------------------- + Function: + Purpose: + Params: + Returns: +---------------------------------------------------------------------- */ +void CPlayerStateRun::think(CPlayer *_player) +{ + int control; + control=getPadInput(_player); + + if(control&PAD_CROSS) + { + setState(_player,STATE_JUMP); + } + if(control&PAD_LEFT) + { + moveLeft(_player); + } + else if(control&PAD_RIGHT) + { + moveRight(_player); + } + else + { + DVECTOR move; + move=getMoveVelocity(_player); + if(move.vx==0) + { + setState(_player,STATE_IDLE); + setAnimNo(_player,ANIM_PLAYER_ANIM_RUNSTOP); + } + else + { + slowdown(_player); + } + } + + if(advanceAnimFrameAndCheckForEndOfAnim(_player)) + { + setAnimNo(_player,ANIM_PLAYER_ANIM_RUN); + } +} + + +/*=========================================================================== + end */ diff --git a/source/player/psrun.h b/source/player/psrun.h new file mode 100644 index 000000000..096f8bdef --- /dev/null +++ b/source/player/psrun.h @@ -0,0 +1,59 @@ +/*========================================================================= + + psjump.h + + Author: PKG + Created: + Project: Spongebob + Purpose: + + Copyright (c) 2001 Climax Development Ltd + +===========================================================================*/ + +#ifndef __PLAYER_PSRUN_H__ +#define __PLAYER_PSRUN_H__ + +/*---------------------------------------------------------------------- + Includes + -------- */ + +#include "player\pstates.h" + + +/* Std Lib + ------- */ + +/*---------------------------------------------------------------------- + Tyepdefs && Defines + ------------------- */ + +/*---------------------------------------------------------------------- + Structure defintions + -------------------- */ + +class CPlayerStateRun : public CPlayerState +{ +public: + void enter(class CPlayer *_player); + void think(class CPlayer *_player); +}; + + +/*---------------------------------------------------------------------- + Globals + ------- */ + +/*---------------------------------------------------------------------- + Functions + --------- */ + +/*---------------------------------------------------------------------- */ + +#endif /* __PLAYER_PSRUN_H__ */ + +/*=========================================================================== + end */ + + + diff --git a/source/player/pstates.cpp b/source/player/pstates.cpp new file mode 100644 index 000000000..3bdf2090e --- /dev/null +++ b/source/player/pstates.cpp @@ -0,0 +1,135 @@ +#include "player\pstates.h" + +#ifndef __PLAYER_PLAYER_H__ +#include "player\player.h" +#endif + +#ifndef __UTILS_HEADER__ +#include "utils\utils.h" +#endif + +#ifndef __PAD_PADS_H__ +#include "pad\pads.h" +#endif + + + + +#ifndef __ANIM_PLAYER_ANIM_HEADER__ +#include +#endif + + + + + +/*----------------------------------------------------------------------*/ +void CPlayerState::setState(CPlayer *_player,int _state) +{ + _player->setState((PLAYER_STATE)_state); +} +int CPlayerState::getFacing(CPlayer *_player) +{ + return _player->getFacing(); +} +void CPlayerState::setFacing(CPlayer *_player,int _facing) +{ + _player->setFacing(_facing); +} +int CPlayerState::getAnimNo(CPlayer *_player) +{ + return _player->getAnimNo(); +} +void CPlayerState::setAnimNo(CPlayer *_player,int _animNo) +{ + _player->setAnimNo(_animNo); +} +void CPlayerState::setAnimFrame(CPlayer *_player,int _animFrame) +{ + _player->setAnimFrame(_animFrame); +} +int CPlayerState::advanceAnimFrameAndCheckForEndOfAnim(class CPlayer *_player) +{ + int animFrame,frameCount; + int looped; + animFrame=_player->getAnimFrame()+1; + frameCount=_player->getAnimFrameCount(); + looped=false; + if(animFrame>=frameCount) + { + looped=true; + animFrame=0; + } + _player->setAnimFrame(animFrame); + return looped; +} +DVECTOR CPlayerState::getMoveVelocity(CPlayer *_player) +{ + return _player->getMoveVelocity(); +} +void CPlayerState::setMoveVelocity(CPlayer *_player,DVECTOR *_moveVel) +{ + _player->setMoveVelocity(_moveVel); +} +int CPlayerState::getPadInput(CPlayer *_player) +{ + return _player->getPadInput(); +} +int CPlayerState::isOnSolidGround(CPlayer *_player) +{ + return _player->isOnSolidGround(); +} +void CPlayerState::moveLeft(CPlayer *_player) +{ + _player->moveLeft(); +} +void CPlayerState::moveRight(CPlayer *_player) +{ + _player->moveRight(); +} +void CPlayerState::slowdown(CPlayer *_player) +{ + _player->slowdown(); +} +void CPlayerState::jump(CPlayer *_player) +{ + _player->jump(); +} +void CPlayerState::fall(CPlayer *_player) +{ + _player->fall(); +} + + + + + + + + +/*----------------------------------------------------------------------*/ +void CPlayerStateIdle::enter(CPlayer *_player) +{ + setAnimNo(_player,ANIM_PLAYER_ANIM_IDLEGENERIC04); +} +void CPlayerStateIdle::think(CPlayer *_player) +{ + int control; + control=getPadInput(_player); + + if(control&PAD_CROSS) + { + setState(_player,STATE_JUMP); + } + else if(control&(PAD_LEFT|PAD_RIGHT)) + { + setState(_player,STATE_RUN); + } + else if(advanceAnimFrameAndCheckForEndOfAnim(_player)) + { + if(getRndRange(100)<95) + setAnimNo(_player,ANIM_PLAYER_ANIM_IDLEGENERIC04); + else + setAnimNo(_player,ANIM_PLAYER_ANIM_IDLEGENERIC03); + } +} diff --git a/source/player/pstates.h b/source/player/pstates.h new file mode 100644 index 000000000..2d1a38e40 --- /dev/null +++ b/source/player/pstates.h @@ -0,0 +1,93 @@ +/*========================================================================= + + pstates.h + + Author: PKG + Created: + Project: Spongebob + Purpose: + + Copyright (c) 2001 Climax Development Ltd + +===========================================================================*/ + +#ifndef __PLAYER_PSTATES_H__ +#define __PLAYER_PSTATES_H__ + +/*---------------------------------------------------------------------- + Includes + -------- */ + +#ifndef _GLOBAL_HEADER_ +#include "system\global.h" +#endif + + +/* Std Lib + ------- */ + +/*---------------------------------------------------------------------- + Tyepdefs && Defines + ------------------- */ + +/*---------------------------------------------------------------------- + Structure defintions + -------------------- */ + +class CPlayerState +{ +public: + virtual void enter(class CPlayer *_player)=0; + virtual void think(class CPlayer *_player)=0; + + +protected: + void setState(class CPlayer *_player,int _state); + int getFacing(class CPlayer *_player); + void setFacing(class CPlayer *_player,int _facing); + int getAnimNo(class CPlayer *_player); + void setAnimNo(class CPlayer *_player,int _animNo); + void setAnimFrame(class CPlayer *_player,int _animFrame); + int advanceAnimFrameAndCheckForEndOfAnim(class CPlayer *_player); + DVECTOR getMoveVelocity(class CPlayer *_player); + void setMoveVelocity(class CPlayer *_player,DVECTOR *_moveVel); + int getPadInput(class CPlayer *_player); + + int isOnSolidGround(class CPlayer *_player); + + void moveLeft(class CPlayer *_player); + void moveRight(class CPlayer *_player); + void slowdown(class CPlayer *_player); + void jump(class CPlayer *_player); + void fall(class CPlayer *_player); + + +}; + + + +class CPlayerStateIdle : public CPlayerState +{ +public: + void enter(class CPlayer *_player); + void think(class CPlayer *_player); +}; + + +/*---------------------------------------------------------------------- + Globals + ------- */ + +/*---------------------------------------------------------------------- + Functions + --------- */ + +/*---------------------------------------------------------------------- */ + +#endif /* __PLAYER_PSTATES_H__ */ + +/*=========================================================================== + end */ + + +