This commit is contained in:
Paul 2001-03-23 20:09:14 +00:00
parent 13b2fbf0a8
commit c59ef39aa0
17 changed files with 366 additions and 910 deletions

View File

@ -25,18 +25,18 @@
#include "game\gameslot.h"
#endif
#ifndef __GAME_GAME_H__
#include "game\game.h"
#endif
#ifndef __LAYER_COLLISION_H__
#include "level\collision.h"
#include "level\layercollision.h"
#endif
#ifndef __PLAYER_PMODES_H__
#include "player\pmodes.h"
#endif
#ifndef __PLAYER_PMFLY_H__
#include "player\pmfly.h"
#endif
// to be removed
#include "gfx\tpage.h"
@ -47,11 +47,6 @@
/* Data
---- */
#ifndef __ANIM_SPONGEBOB_HEADER__
#include <ACTOR_SPONGEBOB_ANIM.h>
#endif
/*----------------------------------------------------------------------
Tyepdefs && Defines
------------------- */
@ -88,16 +83,6 @@ POWER-UPS
mm & bb ring timed
*/
// mode:
// enter
// think
// render
// states setState()
// metrics getMetrics()
// override setAnimNo,setAnimFrame?
/*----------------------------------------------------------------------
Function Prototypes
------------------- */
@ -138,32 +123,14 @@ static void writeDemoControls()
#ifdef _STATE_DEBUG_
static const char *s_stateText[NUM_STATES]=
{
"IDLE",
"IDLETEETER",
"JUMP",
"RUN",
"FALL",
"FALLFAR",
"BUTTBOUNCE",
"BUTTFALL",
"BUTTLAND",
"ATTACK",
"RUNATTACK",
"AIRATTACK",
"DUCK",
"SOAKUP",
"GETUP",
"DEAD",
};
static const char *s_modeText[NUM_PLAYERMODES]=
{
"BASICUNARMED",
"FULLUNARMED",
"BALLOON",
"NET",
"CORALBLOWER",
// "FULLUNARMED",
// "BALLOON",
// "NET",
// "CORALBLOWER",
"FLY",
};
#include "gfx\font.h"
FontBank s_debugFont;
@ -191,6 +158,14 @@ int CAMERA_SCROLLSPEED=60; // Speed of the scroll ( 60=1 tile scrolled every
CPlayerModeBasic PLAYERMODE;
CPlayerModeFly PLAYERMODEFLY;
CPlayerMode *CPlayer::s_playerModes[NUM_PLAYERMODES]=
{
&PLAYERMODE, // PLAYER_MODE_BASICUNARMED
&PLAYERMODEFLY, // PLAYER_MODE_FLY
};
/*----------------------------------------------------------------------
@ -205,15 +180,21 @@ void CPlayer::init()
m_layerCollision=NULL;
m_onPlatform = false;
m_prevOnPlatform = false;
// m_onPlatform = false;
// m_prevOnPlatform = false;
m_skel.Init(ACTORS_SPONGEBOB_A3D);
TPLoadTex(ACTORS_ACTOR_SPONGEBOB_TEX);
for(int i=0;i<NUM_PLAYERMODES;i++)
{
s_playerModes[i]->initialise(this);
}
m_currentPlayerModeClass=NULL;
setMode(PLAYER_MODE_BASICUNARMED);
m_animNo=0;
m_animFrame=0;
m_currentMode=PLAYER_MODE_BASICUNARMED;
setFacing(FACING_RIGHT);
respawn();
@ -289,9 +270,9 @@ if(newmode!=-1)
{
// Think
updatePadInput();
m_currentStateClass->think(this);
thinkVerticalMovement();
thinkHorizontalMovement();
// s_modes[m_currentMode].m_modeControl->think();
// m_currentStateClass->think(this);
m_currentPlayerModeClass->think();
// Powerups
if(m_squeakyBootsTimer)
@ -310,21 +291,11 @@ if(newmode!=-1)
}
#ifdef _STATE_DEBUG_
sprintf(posBuf,"%03d (%02d) ,%03d (%02d) = dfg:%+02d",Pos.vx,Pos.vx&0x0f,Pos.vy,Pos.vy&0x0f,m_layerCollision->getHeightFromGround(Pos.vx,Pos.vy));
#endif
if(Pos.vx<64)Pos.vx=64;
else if(Pos.vx>m_mapEdge.vx-64)Pos.vx=m_mapEdge.vx-64;
if(Pos.vy<64)Pos.vy=64;
else if(Pos.vy>m_mapEdge.vy-64)Pos.vy=m_mapEdge.vy-64;
// Teeter if on an edge
if(m_currentState==STATE_IDLE&&isOnEdge())
{
setState(STATE_IDLETEETER);
}
// Look around
int pad=getPadInputHeld();
@ -359,8 +330,6 @@ if(PadGetDown(0)&PAD_CIRCLE)
}
}
}
s_modes[m_currentMode].m_modeControl->think(this);
}
@ -404,206 +373,6 @@ if(PadGetDown(0)&PAD_CIRCLE)
}
/*----------------------------------------------------------------------
Function:
Purpose:
Params:
Returns:
---------------------------------------------------------------------- */
void CPlayer::thinkVerticalMovement()
{
int colHeight;
colHeight=m_layerCollision->getHeightFromGround(Pos.vx,Pos.vy,1);
//New collision stuff (pkg)
//if(m_layerCollision->getCollisionType(Pos.vx,Pos.vy+(m_moveVel.vy>>VELOCITY_SHIFT))&COLLISION_TYPE_MASK)
//{
// m_moveVel.vy=0;
// return;
//}
if(colHeight>=0)
{
// Above or on the ground
// Are we falling?
if(m_moveVel.vy>0)
{
// Yes.. Check to see if we're about to hit/go through the ground
colHeight=m_layerCollision->getHeightFromGround(Pos.vx,Pos.vy+(m_moveVel.vy>>VELOCITY_SHIFT),PLAYER_TERMINAL_VELOCITY+1);
if(colHeight<=0)
{
// Just hit the ground
// Stick at ground level
Pos.vy+=(m_moveVel.vy>>VELOCITY_SHIFT)+colHeight;
m_moveVel.vy=0;
m_fallFrames=0;
if(m_currentMode!=PLAYER_MODE_BALLOON)
{
if(m_currentState==STATE_BUTTFALL)
{
// Landed from a butt bounce
setState(STATE_BUTTLAND);
}
else if(m_currentState==STATE_FALLFAR)
{
// Landed from a painfully 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);
}
else
{
// Landed from a jump with no x movement
setState(STATE_IDLE);
setAnimNo(ANIM_SPONGEBOB_JUMPEND);
}
}
}
}
else if(colHeight)
{
if(m_currentState!=STATE_FALL&&m_currentState!=STATE_FALLFAR&&
m_currentState!=STATE_BUTTFALL&&m_currentState!=STATE_BUTTBOUNCE&&
m_currentState!=STATE_JUMP)
{
// Was floating in the air.. fall!
if ( !m_onPlatform )
{
setState(STATE_FALL);
}
}
}
}
else
{
/*
// Below ground
// Perhaps we should be falling?
if(m_currentState!=STATE_FALL&&m_currentState!=STATE_FALLFAR&&
m_currentState!=STATE_BUTTFALL&&m_currentState!=STATE_BUTTBOUNCE&&
m_currentState!=STATE_JUMP)
{
setState(STATE_FALL);
}
*/
}
Pos.vy+=m_moveVel.vy>>VELOCITY_SHIFT;
}
/*----------------------------------------------------------------------
Function:
Purpose:
Params:
Returns:
---------------------------------------------------------------------- */
void CPlayer::thinkHorizontalMovement()
{
if(m_moveVel.vx)
{
//New collision stuff (pkg)
//if(m_layerCollision->getCollisionType(Pos.vx+(m_moveVel.vx>>VELOCITY_SHIFT),Pos.vy)&COLLISION_TYPE_MASK)
//{
// m_moveVel.vx=0;
// return;
//}
int colHeight;
colHeight=m_layerCollision->getHeightFromGround(Pos.vx,Pos.vy,5);
if(colHeight==0)
{
// Ok.. we're on the ground. What happens if we move left/right
colHeight=m_layerCollision->getHeightFromGround(Pos.vx+(m_moveVel.vx>>VELOCITY_SHIFT),Pos.vy);
if(colHeight<-8)
{
// Big step up. Stop at the edge of the obstruction
int dir,vx,cx,i;
if(m_moveVel.vx<0)
{
dir=-1;
vx=-m_moveVel.vx>>VELOCITY_SHIFT;
}
else
{
dir=+1;
vx=m_moveVel.vx>>VELOCITY_SHIFT;
}
cx=Pos.vx;
for(i=0;i<vx;i++)
{
if(m_layerCollision->getHeightFromGround(cx,Pos.vy)<-8)
{
break;
}
cx+=dir;
}
Pos.vx=cx-dir;
// If running then go to idle, otherwise leave in same state
if(m_currentState==STATE_RUN)
{
setState(STATE_IDLE);
}
m_moveVel.vx=0;
// Get the height at this new position and then try the step-up code below.
// Without this, there are problems when you run up a slope and hit a wall at the same time
colHeight=m_layerCollision->getHeightFromGround(Pos.vx,Pos.vy);
}
if(colHeight&&colHeight>=-8&&colHeight<=8)
{
// Small step up/down. Follow the contour of the level
Pos.vy+=colHeight;
}
}
else
{
// In the air
// if(!(colHeight<0&&m_currentState==STATE_JUMP)) // Lets you jump through platforms from below
if(colHeight>=0) // Lets you jump through platforms from below
{
colHeight=m_layerCollision->getHeightFromGround(Pos.vx+(m_moveVel.vx>>VELOCITY_SHIFT),Pos.vy,5);
if(colHeight<0)
{
// Stop at the edge of the obstruction
int dir,vx,cx,i;
if(m_moveVel.vx<0)
{
dir=-1;
vx=-m_moveVel.vx>>VELOCITY_SHIFT;
}
else
{
dir=+1;
vx=m_moveVel.vx>>VELOCITY_SHIFT;
}
cx=Pos.vx;
for(i=0;i<vx;i++)
{
if(m_layerCollision->getHeightFromGround(cx,Pos.vy)<0)
{
break;
}
cx+=dir;
}
Pos.vx=cx-dir;
m_moveVel.vx=0;
}
}
}
Pos.vx+=m_moveVel.vx>>VELOCITY_SHIFT;
}
}
/*----------------------------------------------------------------------
Function:
Purpose:
@ -629,6 +398,7 @@ void CPlayer::render()
CPlayerThing::render();
#ifdef _STATE_DEBUG_
sprintf(posBuf,"%03d (%02d) ,%03d (%02d) = dfg:%+02d",Pos.vx,Pos.vx&0x0f,Pos.vy,Pos.vy&0x0f,m_layerCollision->getHeightFromGround(Pos.vx,Pos.vy));
s_debugFont.print(40,40,posBuf);
#endif
@ -666,8 +436,6 @@ if(eyes!=-1)
#ifdef _STATE_DEBUG_
char buf[128];
sprintf(buf,"STATE: %s",s_stateText[m_currentState]);
s_debugFont.print(40,200,buf);
sprintf(buf,"MODE: %s",s_modeText[m_currentMode]);
s_debugFont.print(40,210,buf);
#endif
@ -708,19 +476,6 @@ if(eyes!=-1)
}
/*----------------------------------------------------------------------
Function:
Purpose:
Params:
Returns:
---------------------------------------------------------------------- */
DVECTOR CPlayer::getCameraPos()
{
return m_cameraPos;
}
/*----------------------------------------------------------------------
Function:
Purpose: Pre-calcs the visible edges of the map ( ie: the hard limits
@ -766,43 +521,6 @@ void CPlayer::addLife()
}
}
/*----------------------------------------------------------------------
Function:
Purpose:
Params:
Returns:
---------------------------------------------------------------------- */
const PlayerMetrics *CPlayer::getPlayerMetrics()
{
return &s_modes[m_currentMode].m_metrics;
}
/*----------------------------------------------------------------------
Function:
Purpose:
Params:
Returns:
---------------------------------------------------------------------- */
int CPlayer::setState(PLAYER_STATE _state)
{
CPlayerState *nextState;
int ret=false;
nextState=s_modes[m_currentMode].m_states[_state];
if(nextState)
{
m_currentStateClass=nextState;
m_currentStateClass->enter(this);
m_currentState=_state;
ret=true;
}
return ret;
}
/*----------------------------------------------------------------------
Function:
@ -813,14 +531,8 @@ int CPlayer::setState(PLAYER_STATE _state)
void CPlayer::setMode(PLAYER_MODE _mode)
{
m_currentMode=_mode;
// Need to do something about this setState() for when the new mode doesn't have that state (pkg)
if(!setState(m_currentState))
{
m_moveVel.vx=0;
m_moveVel.vy=0;
setState(STATE_IDLE);
}
s_modes[m_currentMode].m_modeControl->enter(this);
m_currentPlayerModeClass=s_playerModes[_mode];
m_currentPlayerModeClass->enter();
}
@ -905,245 +617,6 @@ void CPlayer::setAnimNo(int _animNo)
}
/*----------------------------------------------------------------------
Function:
Purpose:
Params:
Returns:
---------------------------------------------------------------------- */
DVECTOR CPlayer::getMoveVelocity()
{
return m_moveVel;
}
void CPlayer::setMoveVelocity(DVECTOR *_moveVel)
{
m_moveVel=*_moveVel;
}
DVECTOR CPlayer::getPlayerPos()
{
return Pos;
}
void CPlayer::setPlayerPos(DVECTOR *_pos)
{
Pos=*_pos;
}
/*----------------------------------------------------------------------
Function:
Purpose:
Params:
Returns:
---------------------------------------------------------------------- */
PLAYERINPUT CPlayer::getPadInputHeld()
{
return m_padInput;
}
PLAYERINPUT CPlayer::getPadInputDown()
{
return m_padInputDown;
}
/*----------------------------------------------------------------------
Function:
Purpose:
Params:
Returns:
---------------------------------------------------------------------- */
int CPlayer::isOnSlippySurface()
{
return false;
/* (pkg)
int ret=false;
if(m_layerCollision->getHeightFromGround(Pos.vx,Pos.vy,5)==0&&
m_layerCollision->getCollisionType(Pos.vx,Pos.vy)&COLLISION_TYPE_FLAG_SLIPPERY)
{
ret=true;
}
return ret;
*/
}
/*----------------------------------------------------------------------
Function:
Purpose:
Params:
Returns: FACING_LEFT if left half of player is hanging, FACING_RIGHT
if right half of player is hanging or 0 if no part of the
player is hanging
---------------------------------------------------------------------- */
int csize=5;
int cheight=15;
int CPlayer::isOnEdge()
{
int ret=0;
if(m_layerCollision->getHeightFromGround(Pos.vx-csize,Pos.vy,cheight+1)>cheight)
{
ret=FACING_LEFT;
}
else if(m_layerCollision->getHeightFromGround(Pos.vx+csize,Pos.vy,cheight+1)>cheight)
{
ret=FACING_RIGHT;
}
return ret;
}
/*----------------------------------------------------------------------
Function:
Purpose:
Params:
Returns:
---------------------------------------------------------------------- */
int CPlayer::canMoveLeft()
{
return m_layerCollision->getHeightFromGround(Pos.vx-1,Pos.vy,16)>-8?true:false;
}
int CPlayer::canMoveRight()
{
return m_layerCollision->getHeightFromGround(Pos.vx+1,Pos.vy,16)>-8?true:false;
}
/*----------------------------------------------------------------------
Function:
Purpose:
Params:
Returns:
---------------------------------------------------------------------- */
void CPlayer::moveLeft()
{
const PlayerMetrics *metrics;
metrics=getPlayerMetrics();
setFacing(FACING_LEFT);
if(m_moveVel.vx<=0)
{
m_moveVel.vx-=metrics->m_metric[PM__RUN_SPEEDUP];
if(m_moveVel.vx<-metrics->m_metric[PM__MAX_RUN_VELOCITY]<<VELOCITY_SHIFT)
{
m_moveVel.vx=-metrics->m_metric[PM__MAX_RUN_VELOCITY]<<VELOCITY_SHIFT;
}
}
else
{
m_moveVel.vx-=metrics->m_metric[PM__RUN_REVERSESLOWDOWN];
}
if(m_moveVel.vx<-CAMERA_STARTMOVETHRESHOLD||m_cameraScrollPos.vx<-CAMERA_SCROLLTHRESHOLD<<8)
{
m_cameraScrollDir=+1;
}
else if(m_moveVel.vx>-CAMERA_STOPMOVETHRESHOLD)
{
m_cameraScrollDir=0;
}
}
void CPlayer::moveRight()
{
const PlayerMetrics *metrics;
metrics=getPlayerMetrics();
setFacing(FACING_RIGHT);
if(m_moveVel.vx>=0)
{
m_moveVel.vx+=metrics->m_metric[PM__RUN_SPEEDUP];
if(m_moveVel.vx>metrics->m_metric[PM__MAX_RUN_VELOCITY]<<VELOCITY_SHIFT)
{
m_moveVel.vx=metrics->m_metric[PM__MAX_RUN_VELOCITY]<<VELOCITY_SHIFT;
}
}
else
{
m_moveVel.vx+=metrics->m_metric[PM__RUN_REVERSESLOWDOWN];
}
if(m_moveVel.vx>CAMERA_STARTMOVETHRESHOLD||m_cameraScrollPos.vx>CAMERA_SCROLLTHRESHOLD<<8)
{
m_cameraScrollDir=-1;
}
else if(m_moveVel.vx<CAMERA_STOPMOVETHRESHOLD)
{
m_cameraScrollDir=0;
}
}
void CPlayer::slowdown()
{
const PlayerMetrics *metrics;
int stopSpeed;
metrics=getPlayerMetrics();
if(isOnSlippySurface())
{
stopSpeed=SLIPSPEED;
}
else
{
stopSpeed=0;
}
if(m_moveVel.vx<0)
{
if(-stopSpeed<m_moveVel.vx)
{
stopSpeed=-m_moveVel.vx;
}
m_moveVel.vx+=metrics->m_metric[PM__RUN_SLOWDOWN];
if(m_moveVel.vx>-stopSpeed)
{
m_moveVel.vx=-stopSpeed;
if(m_currentState==STATE_RUN)
{
setState(STATE_IDLE);
}
}
}
else if(m_moveVel.vx>0)
{
if(stopSpeed>m_moveVel.vx)
{
stopSpeed=m_moveVel.vx;
}
m_moveVel.vx-=metrics->m_metric[PM__RUN_SLOWDOWN];
if(m_moveVel.vx<stopSpeed)
{
m_moveVel.vx=stopSpeed;
if(m_currentState==STATE_RUN)
{
setState(STATE_IDLE);
}
}
}
}
void CPlayer::jump()
{
}
void CPlayer::fall()
{
const PlayerMetrics *metrics;
metrics=getPlayerMetrics();
m_moveVel.vy+=PLAYER_GRAVITY;
if(m_moveVel.vy>=PLAYER_TERMINAL_VELOCITY<<VELOCITY_SHIFT)
{
m_moveVel.vy=PLAYER_TERMINAL_VELOCITY<<VELOCITY_SHIFT;
m_fallFrames++;
if(m_currentState!=STATE_BUTTFALL)
{
if(m_fallFrames>metrics->m_metric[PM__MAX_SAFE_FALL_FRAMES])
{
setState(STATE_FALLFAR);
}
}
}
}
/*----------------------------------------------------------------------
Function:
Purpose:
@ -1152,27 +625,23 @@ void CPlayer::fall()
---------------------------------------------------------------------- */
void CPlayer::respawn()
{
setState(STATE_IDLE);
// setState(STATE_IDLE);
// Strip any items that the player might be holding
if(m_currentMode!=PLAYER_MODE_BASICUNARMED)
{
setMode(PLAYER_MODE_FULLUNARMED);
}
else
{
// if(m_currentMode!=PLAYER_MODE_BASICUNARMED)
// {
// setMode(PLAYER_MODE_FULLUNARMED);
// }
// else
// {
setMode(PLAYER_MODE_BASICUNARMED);
}
// }
s_health=MAX_HEALTH;
m_invincibleFrameCount=INVIBCIBLE_FRAMES__START;
Pos=m_respawnPos;
m_moveVel.vx=0;
m_moveVel.vy=0;
m_fallFrames=0;
}
/*----------------------------------------------------------------------
Function:
Purpose:
@ -1229,7 +698,7 @@ void CPlayer::takeDamage(DAMAGE_TYPE _damage)
else
{
CSoundMediator::playSfx(CSoundMediator::SFX_SPONGEBOB_DEFEATED_JINGLE);
setState(STATE_DEAD);
// setState(STATE_DEAD);
}
}
}
@ -1332,11 +801,13 @@ PLAYERINPUT CPlayer::readPadInput()
Params:
Returns:
---------------------------------------------------------------------- */
/*
void CPlayer::clearPlatform()
{
m_prevOnPlatform = m_onPlatform;
m_onPlatform = false;
}
*/
/*----------------------------------------------------------------------
Function:
@ -1344,6 +815,7 @@ void CPlayer::clearPlatform()
Params:
Returns:
---------------------------------------------------------------------- */
/*
void CPlayer::setPlatform( CThing *newPlatform )
{
int colHeight;
@ -1381,7 +853,7 @@ void CPlayer::setPlatform( CThing *newPlatform )
if ( !m_prevOnPlatform )
{
if( m_currentMode != PLAYER_MODE_BALLOON )
// if( m_currentMode != PLAYER_MODE_BALLOON )
{
m_fallFrames=0;
@ -1462,6 +934,7 @@ void CPlayer::setPlatform( CThing *newPlatform )
newPlatform->removeChild( this );
}
}
*/
/*----------------------------------------------------------------------
Function:
@ -1469,6 +942,7 @@ void CPlayer::setPlatform( CThing *newPlatform )
Params:
Returns:
---------------------------------------------------------------------- */
/*
void CPlayer::shove( DVECTOR move )
{
DVECTOR newPos;
@ -1490,6 +964,7 @@ void CPlayer::shove( DVECTOR move )
Pos.vy = newPos.vy;
}
}
*/
/*===========================================================================
end */

View File

@ -49,12 +49,12 @@
typedef enum
{
PLAYER_MODE_BASICUNARMED,
PLAYER_MODE_FULLUNARMED,
PLAYER_MODE_BALLOON,
// PLAYER_MODE_FULLUNARMED,
// PLAYER_MODE_BALLOON,
//PLAYER_MODE_BUBBLE_MIXTURE,
//PLAYER_MODE_HELMET,
PLAYER_MODE_NET,
PLAYER_MODE_CORALBLOWER,
// PLAYER_MODE_NET,
// PLAYER_MODE_CORALBLOWER,
//PLAYER_MODE_JELLY_LAUNCHER,
PLAYER_MODE_FLY,
@ -73,15 +73,10 @@ typedef enum
STATE_BUTTBOUNCE,
STATE_BUTTFALL,
STATE_BUTTLAND,
STATE_ATTACK,
STATE_RUNATTACK,
STATE_AIRATTACK,
STATE_DUCK,
STATE_SOAKUP,
STATE_GETUP,
STATE_DEAD,
NUM_STATES,
}PLAYER_STATE;
@ -91,19 +86,6 @@ enum
FACING_RIGHT=-1,
};
typedef enum
{
PM__JUMP_VELOCITY,
PM__MAX_JUMP_FRAMES,
PM__MAX_SAFE_FALL_FRAMES,
PM__MAX_RUN_VELOCITY,
PM__RUN_SPEEDUP,
PM__RUN_REVERSESLOWDOWN,
PM__RUN_SLOWDOWN,
NUM_PLAYER_METRICS
}PLAYER_METRIC;
typedef enum
{
DAMAGE__NONE, // put in so that an item can push the user but not damage them
@ -142,60 +124,32 @@ typedef enum
Structure defintions
-------------------- */
struct PlayerMetrics
{
s16 m_metric[NUM_PLAYER_METRICS];
};
class CPlayer : public CPlayerThing
{
public:
enum
{
VELOCITY_SHIFT=4,
MAX_HEALTH=5,
MAX_LIVES=99,
};
virtual void init();
virtual void shutdown();
virtual void think(int _frames);
virtual void render();
virtual void shove(DVECTOR move);
// virtual void shove(DVECTOR move);
DVECTOR getCameraPos();
DVECTOR getCameraPos() {return m_cameraPos;}
void setLayerCollision(class CLayerCollision *_layer) {m_layerCollision=_layer;}
void setLayerCollision(class CLayerCollision *_layer) {m_layerCollision=_layer;}
void setMapSize(DVECTOR _mapSize);
void setRespawnPos(DVECTOR _respawn) {m_respawnPos=_respawn;}
void setRespawnPos(DVECTOR _respawn) {m_respawnPos=_respawn;}
enum
{
MAX_HEALTH=5,
MAX_LIVES=99,
};
void addHealth(int _health);
void addLife();
protected:
enum
{
DEFAULT_PLAYER_JUMP_VELOCITY=4,
DEFAULT_PLAYER_MAX_JUMP_FRAMES=12,
DEFAULT_PLAYER_MAX_SAFE_FALL_FRAMES=30,
DEFAULT_PLAYER_MAX_RUN_VELOCITY=8,
DEFAULT_PLAYER_RUN_SPEEDUP=4<<2,
DEFAULT_PLAYER_RUN_REVERSESLOWDOWN=3<<2,
DEFAULT_PLAYER_RUN_SLOWDOWN=2<<2,
PLAYER_GRAVITY=4<<2,
PLAYER_TERMINAL_VELOCITY=8,
};
const PlayerMetrics *getPlayerMetrics();
// State
int setState(PLAYER_STATE _state);
public:
void setMode(PLAYER_MODE _mode);
private:
int getFacing();
void setFacing(int _facing);
int getAnimFrame();
@ -203,41 +157,18 @@ private:
int getAnimFrameCount();
int getAnimNo();
void setAnimNo(int _animNo);
DVECTOR getMoveVelocity();
void setMoveVelocity(DVECTOR *_moveVel);
DVECTOR getPlayerPos();
void setPlayerPos(DVECTOR *_pos);
PLAYERINPUT getPadInputHeld();
PLAYERINPUT getPadInputDown();
DVECTOR getPlayerPos() {return Pos;}
void setPlayerPos(DVECTOR *_pos) {Pos=*_pos;}
PLAYERINPUT getPadInputHeld() {return m_padInput;}
PLAYERINPUT getPadInputDown() {return m_padInputDown;}
class CLayerCollision *getLayerCollision() {return m_layerCollision;}
// Collision
int isOnSlippySurface();
int isOnEdge();
int canMoveLeft();
int canMoveRight();
// Movement
void moveLeft();
void moveRight();
void slowdown();
void jump();
void fall();
void respawn();
void takeDamage(DAMAGE_TYPE _damage);
friend class CPlayerState;
private:
typedef struct
{
PlayerMetrics m_metrics;
class CPlayerMode *m_modeControl;
class CPlayerState *m_states[NUM_STATES];
}PlayerMode;
void respawn();
public:
@ -261,9 +192,7 @@ private:
DVECTOR m_cameraPos;
int m_cameraScrollDir;
DVECTOR m_moveVel;
int m_facing;
int m_fallFrames;
enum
{
@ -277,13 +206,9 @@ private:
};
int m_invincibleFrameCount; // Initial invincibility and also invincibility after taking damage
void thinkVerticalMovement();
void thinkHorizontalMovement();
static PlayerMode s_modes[NUM_PLAYERMODES];
int m_currentMode;
class CPlayerState *m_currentStateClass;
PLAYER_STATE m_currentState;
static class CPlayerMode *s_playerModes[NUM_PLAYERMODES];
class CPlayerMode *m_currentPlayerModeClass;
int m_currentMode;
int m_lives;
@ -324,13 +249,17 @@ private:
// Platforms
public:
void setPlatform( CThing *newPlatform );
void clearPlatform();
void setPlatform( CThing *newPlatform ) {;}
void clearPlatform() {;}
/*
private:
CThing *m_platform;
bool m_onPlatform;
bool m_prevOnPlatform;
DVECTOR m_prevPlatformPos;
*/
};

View File

@ -50,18 +50,10 @@
#include "player\psbutt.h"
#endif
#ifndef __PLAYER__PSCHOP_H__
#include "player\pschop.h"
#endif
#ifndef __PLAYER__PSDUCK_H__
#include "player\psduck.h"
#endif
#ifndef __PLAYER__PSDEAD_H__
#include "player\psdead.h"
#endif
/* Std Lib
------- */

View File

@ -18,6 +18,15 @@
Includes
-------- */
#ifndef _GLOBAL_HEADER_
#include "system\global.h"
#endif
#ifndef __PLAYER_PLAYER_H__
#include "player\player.h"
#endif
/* Std Lib
------- */
@ -29,12 +38,116 @@
Structure defintions
-------------------- */
typedef enum
{
PM__JUMP_VELOCITY,
PM__MAX_JUMP_FRAMES,
PM__MAX_SAFE_FALL_FRAMES,
PM__MAX_RUN_VELOCITY,
PM__RUN_SPEEDUP,
PM__RUN_REVERSESLOWDOWN,
PM__RUN_SLOWDOWN,
NUM_PLAYER_METRICS
}PLAYER_METRIC;
struct PlayerMetrics
{
s16 m_metric[NUM_PLAYER_METRICS];
};
class CPlayerMode
{
public:
virtual void enter(class CPlayer *_player) {;}
virtual void think(class CPlayer *_player) {;}
virtual void initialise(class CPlayer *_player) {m_player=_player;}
virtual void enter() {;}
virtual void think() {;}
virtual void render() {;}
int getPadInputHeld();
int getPadInputDown();
protected:
DVECTOR getPlayerPos();
void setPlayerPos(DVECTOR *_pos);
class CPlayer *m_player;
};
class CPlayerModeBasic : public CPlayerMode
{
public:
enum
{
VELOCITY_SHIFT=4,
};
virtual void enter();
virtual void think();
virtual void render();
//protected:
int canTeeter() {return m_currentState==STATE_IDLE;}
int canFallForever() {return m_currentState==STATE_BUTTFALL;}
void thinkVerticalMovement();
void thinkHorizontalMovement();
const struct PlayerMetrics *getPlayerMetrics();
int setState(int _state);
// virtual void setMode(class CPlayer *_player,int _mode);
int getFacing();
void setFacing(int _facing);
// virtual int getAnimNo(class CPlayer *_player);
void setAnimNo(int _animNo);
void setAnimFrame(int _animFrame);
int advanceAnimFrameAndCheckForEndOfAnim();
// virtual int retreatAnimFrameAndCheckForEndOfAnim(class CPlayer *_player);
DVECTOR getMoveVelocity();
void zeroMoveVelocity();
void setMoveVelocity(DVECTOR *_moveVel);
int isOnEdge();
int canMoveLeft();
int canMoveRight();
void moveLeft();
void moveRight();
int slowdown();
void jump();
void fall();
// virtual void respawn(class CPlayer *_player);
protected:
enum
{
DEFAULT_PLAYER_JUMP_VELOCITY=4,
DEFAULT_PLAYER_MAX_JUMP_FRAMES=12,
DEFAULT_PLAYER_MAX_SAFE_FALL_FRAMES=30,
DEFAULT_PLAYER_MAX_RUN_VELOCITY=6, //8
DEFAULT_PLAYER_RUN_SPEEDUP=2<<2, //4
DEFAULT_PLAYER_RUN_REVERSESLOWDOWN=4<<2, //3
DEFAULT_PLAYER_RUN_SLOWDOWN=3<<2, //2
PLAYER_GRAVITY=4<<2,
PLAYER_TERMINAL_VELOCITY=8,
};
private:
int m_fallFrames;
DVECTOR m_moveVelocity;
static class CPlayerState *s_stateTable[];
class CPlayerState *m_currentStateClass;
PLAYER_STATE m_currentState;
static PlayerMetrics s_playerMetrics;
};

View File

@ -23,6 +23,10 @@
#include "player\player.h"
#endif
#ifndef __PLAYER_PMODES_H__
#include "player\pmodes.h"
#endif
#ifndef __GAME_GAMEBUBS_H__
#include "game\gamebubs.h"
#endif
@ -61,9 +65,10 @@
Params:
Returns:
---------------------------------------------------------------------- */
void CPlayerStateButtBounce::enter(CPlayer *_player)
void CPlayerStateButtBounce::enter(CPlayerModeBasic *_playerMode)
{
setAnimNo(_player,ANIM_SPONGEBOB_BUTTBOUNCESTART);
_playerMode->zeroMoveVelocity();
_playerMode->setAnimNo(ANIM_SPONGEBOB_BUTTBOUNCESTART);
}
@ -73,11 +78,11 @@ void CPlayerStateButtBounce::enter(CPlayer *_player)
Params:
Returns:
---------------------------------------------------------------------- */
void CPlayerStateButtBounce::think(CPlayer *_player)
void CPlayerStateButtBounce::think(CPlayerModeBasic *_playerMode)
{
if(advanceAnimFrameAndCheckForEndOfAnim(_player))
if(_playerMode->advanceAnimFrameAndCheckForEndOfAnim())
{
setState(_player,STATE_BUTTFALL);
_playerMode->setState(STATE_BUTTFALL);
}
}
@ -88,9 +93,9 @@ void CPlayerStateButtBounce::think(CPlayer *_player)
Params:
Returns:
---------------------------------------------------------------------- */
void CPlayerStateButtBounceFall::enter(CPlayer *_player)
void CPlayerStateButtBounceFall::enter(CPlayerModeBasic *_playerMode)
{
setAnimNo(_player,ANIM_SPONGEBOB_BUTTBOUNCEEND);
_playerMode->setAnimNo(ANIM_SPONGEBOB_BUTTBOUNCEEND);
}
@ -100,9 +105,9 @@ void CPlayerStateButtBounceFall::enter(CPlayer *_player)
Params:
Returns:
---------------------------------------------------------------------- */
void CPlayerStateButtBounceFall::think(CPlayer *_player)
void CPlayerStateButtBounceFall::think(CPlayerModeBasic *_playerMode)
{
fall(_player);
_playerMode->fall();
}
@ -112,12 +117,12 @@ void CPlayerStateButtBounceFall::think(CPlayer *_player)
Params:
Returns:
---------------------------------------------------------------------- */
void CPlayerStateButtBounceLand::enter(CPlayer *_player)
void CPlayerStateButtBounceLand::enter(CPlayerModeBasic *_playerMode)
{
DVECTOR pos;
pos=getPlayerPos(_player);
CGameBubicleFactory::spawnBubicles(pos.vx,pos.vy,40,10,CGameBubicleFactory::TYPE_MEDIUM);
// DVECTOR pos;
//
// pos=_playerMode->getPlayerPos();
// CGameBubicleFactory::spawnBubicles(pos.vx,pos.vy,40,10,CGameBubicleFactory::TYPE_MEDIUM);
}
@ -127,11 +132,11 @@ void CPlayerStateButtBounceLand::enter(CPlayer *_player)
Params:
Returns:
---------------------------------------------------------------------- */
void CPlayerStateButtBounceLand::think(CPlayer *_player)
void CPlayerStateButtBounceLand::think(CPlayerModeBasic *_playerMode)
{
if(advanceAnimFrameAndCheckForEndOfAnim(_player))
if(_playerMode->advanceAnimFrameAndCheckForEndOfAnim())
{
setState(_player,STATE_IDLE);
_playerMode->setState(STATE_IDLE);
}
}

View File

@ -35,24 +35,24 @@
class CPlayerStateButtBounce : public CPlayerState
{
public:
virtual void enter(class CPlayer *_player);
virtual void think(class CPlayer *_player);
virtual void enter(class CPlayerModeBasic *_playerMode);
virtual void think(class CPlayerModeBasic *_playerMode);
};
class CPlayerStateButtBounceFall : public CPlayerState
{
public:
virtual void enter(class CPlayer *_player);
virtual void think(class CPlayer *_player);
virtual void enter(class CPlayerModeBasic *_playerMode);
virtual void think(class CPlayerModeBasic *_playerMode);
};
class CPlayerStateButtBounceLand : public CPlayerState
{
public:
virtual void enter(class CPlayer *_player);
virtual void think(class CPlayer *_player);
virtual void enter(class CPlayerModeBasic *_playerMode);
virtual void think(class CPlayerModeBasic *_playerMode);
private:

View File

@ -23,6 +23,10 @@
#include "player\player.h"
#endif
#ifndef __PLAYER_PMODES_H__
#include "player\pmodes.h"
#endif
/* Std Lib
------- */
@ -57,9 +61,9 @@
Params:
Returns:
---------------------------------------------------------------------- */
void CPlayerStateDuck::enter(CPlayer *_player)
void CPlayerStateDuck::enter(CPlayerModeBasic *_playerMode)
{
setAnimNo(_player,ANIM_SPONGEBOB_SOAKUP);
_playerMode->setAnimNo(ANIM_SPONGEBOB_SOAKUP);
}
@ -69,12 +73,12 @@ void CPlayerStateDuck::enter(CPlayer *_player)
Params:
Returns:
---------------------------------------------------------------------- */
void CPlayerStateDuck::think(CPlayer *_player)
void CPlayerStateDuck::think(CPlayerModeBasic *_playerMode)
{
slowdown(_player);
if(advanceAnimFrameAndCheckForEndOfAnim(_player))
_playerMode->slowdown();
if(_playerMode->advanceAnimFrameAndCheckForEndOfAnim())
{
setState(_player,STATE_SOAKUP);
_playerMode->setState(STATE_SOAKUP);
}
}
@ -85,15 +89,10 @@ void CPlayerStateDuck::think(CPlayer *_player)
Params:
Returns:
---------------------------------------------------------------------- */
void CPlayerStateSoakUp::enter(CPlayer *_player)
void CPlayerStateSoakUp::enter(CPlayerModeBasic *_playerMode)
{
DVECTOR move;
move=getMoveVelocity(_player);
move.vx=0;
setMoveVelocity(_player,&move);
setAnimNo(_player,ANIM_SPONGEBOB_GETUP);
_playerMode->zeroMoveVelocity();
_playerMode->setAnimNo(ANIM_SPONGEBOB_GETUP);
}
@ -103,14 +102,14 @@ void CPlayerStateSoakUp::enter(CPlayer *_player)
Params:
Returns:
---------------------------------------------------------------------- */
void CPlayerStateSoakUp::think(CPlayer *_player)
void CPlayerStateSoakUp::think(CPlayerModeBasic *_playerMode)
{
int controlHeld;
controlHeld=getPadInputHeld(_player);
controlHeld=_playerMode->getPadInputHeld();
if(!(controlHeld&PI_DOWN))
{
setState(_player,STATE_GETUP);
_playerMode->setState(STATE_GETUP);
}
}
@ -121,9 +120,9 @@ void CPlayerStateSoakUp::think(CPlayer *_player)
Params:
Returns:
---------------------------------------------------------------------- */
void CPlayerStateGetUp::enter(CPlayer *_player)
void CPlayerStateGetUp::enter(CPlayerModeBasic *_playerMode)
{
setAnimNo(_player,ANIM_SPONGEBOB_GETUP);
_playerMode->setAnimNo(ANIM_SPONGEBOB_GETUP);
}
@ -133,11 +132,11 @@ void CPlayerStateGetUp::enter(CPlayer *_player)
Params:
Returns:
---------------------------------------------------------------------- */
void CPlayerStateGetUp::think(CPlayer *_player)
void CPlayerStateGetUp::think(CPlayerModeBasic *_playerMode)
{
if(advanceAnimFrameAndCheckForEndOfAnim(_player))
if(_playerMode->advanceAnimFrameAndCheckForEndOfAnim())
{
setState(_player,STATE_IDLE);
_playerMode->setState(STATE_IDLE);
}
}

View File

@ -35,8 +35,8 @@
class CPlayerStateDuck : public CPlayerState
{
public:
void enter(class CPlayer *_player);
void think(class CPlayer *_player);
void enter(class CPlayerModeBasic *_playerMode);
void think(class CPlayerModeBasic *_playerMode);
};
@ -44,8 +44,8 @@ public:
class CPlayerStateSoakUp : public CPlayerState
{
public:
void enter(class CPlayer *_player);
void think(class CPlayer *_player);
void enter(class CPlayerModeBasic *_playerMode);
void think(class CPlayerModeBasic *_playerMode);
};
@ -53,8 +53,8 @@ public:
class CPlayerStateGetUp : public CPlayerState
{
public:
void enter(class CPlayer *_player);
void think(class CPlayer *_player);
void enter(class CPlayerModeBasic *_playerMode);
void think(class CPlayerModeBasic *_playerMode);
};

View File

@ -22,6 +22,10 @@
#include "player\player.h"
#endif
#ifndef __PLAYER_PMODES_H__
#include "player\pmodes.h"
#endif
/* Std Lib
------- */
@ -56,9 +60,9 @@
Params:
Returns:
---------------------------------------------------------------------- */
void CPlayerStateFall::enter(CPlayer *_player)
void CPlayerStateFall::enter(CPlayerModeBasic *_playerMode)
{
setAnimNo(_player,ANIM_SPONGEBOB_HOVER);
_playerMode->setAnimNo(ANIM_SPONGEBOB_HOVER);
}
@ -68,47 +72,34 @@ void CPlayerStateFall::enter(CPlayer *_player)
Params:
Returns:
---------------------------------------------------------------------- */
void CPlayerStateFall::think(CPlayer *_player)
void CPlayerStateFall::think(CPlayerModeBasic *_playerMode)
{
const PlayerMetrics *metrics;
int controlHeld,controlDown;
DVECTOR move;
metrics=getPlayerMetrics(_player);
controlHeld=getPadInputHeld(_player);
controlDown=getPadInputDown(_player);
metrics=_playerMode->getPlayerMetrics();
controlHeld=_playerMode->getPadInputHeld();
controlDown=_playerMode->getPadInputDown();
if(controlHeld&PI_LEFT)
{
moveLeft(_player);
_playerMode->moveLeft();
}
else if(controlHeld&PI_RIGHT)
{
moveRight(_player);
_playerMode->moveRight();
}
else
{
slowdown(_player);
_playerMode->slowdown();
}
_playerMode->fall();
fall(_player);
if(controlDown&PI_ACTION)
if(controlHeld&PI_DOWN)
{
setState(_player,STATE_AIRATTACK);
_playerMode->setState(STATE_BUTTBOUNCE);
}
else if(controlHeld&PI_DOWN)
{
if(setState(_player,STATE_BUTTBOUNCE))
{
// Only do this if this mode allows us to go into butt bounce, otherwise
// SB just floats in the air :)
move.vx=0;
move.vy=0;
setMoveVelocity(_player,&move);
}
}
// advanceAnimFrameAndCheckForEndOfAnim(_player);
}
@ -118,9 +109,9 @@ void CPlayerStateFall::think(CPlayer *_player)
Params:
Returns:
---------------------------------------------------------------------- */
void CPlayerStateFallFar::enter(CPlayer *_player)
void CPlayerStateFallFar::enter(CPlayerModeBasic *_playerMode)
{
setAnimNo(_player,ANIM_SPONGEBOB_FALL);
_playerMode->setAnimNo(ANIM_SPONGEBOB_FALL);
}
@ -130,27 +121,26 @@ void CPlayerStateFallFar::enter(CPlayer *_player)
Params:
Returns:
---------------------------------------------------------------------- */
void CPlayerStateFallFar::think(CPlayer *_player)
void CPlayerStateFallFar::think(CPlayerModeBasic *_playerMode)
{
int controlHeld;
DVECTOR move;
controlHeld=getPadInputHeld(_player);
controlHeld=_playerMode->getPadInputHeld();
if(controlHeld&PI_LEFT)
{
moveLeft(_player);
_playerMode->moveLeft();
}
else if(controlHeld&PI_RIGHT)
{
moveRight(_player);
_playerMode->moveRight();
}
else
{
slowdown(_player);
_playerMode->slowdown();
}
fall(_player);
_playerMode->fall();
}

View File

@ -35,8 +35,8 @@
class CPlayerStateFall : public CPlayerState
{
public:
void enter(class CPlayer *_player);
void think(class CPlayer *_player);
void enter(class CPlayerModeBasic *_playerMode);
void think(class CPlayerModeBasic *_playerMode);
};
@ -44,8 +44,8 @@ public:
class CPlayerStateFallFar : public CPlayerStateFall
{
private:
void enter(class CPlayer *_player);
void think(class CPlayer *_player);
void enter(class CPlayerModeBasic *_playerMode);
void think(class CPlayerModeBasic *_playerMode);
};

View File

@ -18,8 +18,8 @@
#include "player\psidle.h"
#ifndef __PLAYER_PLAYER_H__
#include "player\player.h"
#ifndef __PLAYER_PMODES_H__
#include "player\pmodes.h"
#endif
#ifndef __UTILS_HEADER__
@ -61,33 +61,33 @@
Params:
Returns:
---------------------------------------------------------------------- */
void CPlayerStateBaseIdle::thinkControl(CPlayer *_player)
void CPlayerStateBaseIdle::thinkControl(CPlayerModeBasic *_playerMode)
{
int controlDown,controlHeld;
controlDown=getPadInputDown(_player);
controlHeld=getPadInputHeld(_player);
controlDown=_playerMode->getPadInputDown();
controlHeld=_playerMode->getPadInputHeld();
if(controlDown&PI_JUMP)
{
setState(_player,STATE_JUMP);
_playerMode->setState(STATE_JUMP);
}
else if(controlHeld&PI_LEFT)
{
if(canMoveLeft(_player))
setState(_player,STATE_RUN);
if(_playerMode->canMoveLeft())
_playerMode->setState(STATE_RUN);
}
else if(controlHeld&PI_RIGHT)
{
if(canMoveRight(_player))
setState(_player,STATE_RUN);
if(_playerMode->canMoveRight())
_playerMode->setState(STATE_RUN);
}
else if(controlDown&PI_ACTION)
{
setState(_player,STATE_ATTACK);
// _playerMode->setState(STATE_ATTACK);
}
else if(controlHeld&PI_DOWN)
{
setState(_player,STATE_DUCK);
_playerMode->setState(STATE_DUCK);
}
}
@ -98,13 +98,13 @@ void CPlayerStateBaseIdle::thinkControl(CPlayer *_player)
Params:
Returns:
---------------------------------------------------------------------- */
void CPlayerStateTeeterIdle::enter(CPlayer *_player)
void CPlayerStateTeeterIdle::enter(CPlayerModeBasic *_playerMode)
{
int edgeType,dir;
int anim;
edgeType=isOnEdge(_player);
dir=getFacing(_player);
edgeType=_playerMode->isOnEdge();
dir=_playerMode->getFacing();
if(edgeType==FACING_LEFT)
{
anim=dir==FACING_LEFT?ANIM_SPONGEBOB_TEETERFRONT:ANIM_SPONGEBOB_TEETERBACK;
@ -114,7 +114,7 @@ void CPlayerStateTeeterIdle::enter(CPlayer *_player)
anim=dir==FACING_RIGHT?ANIM_SPONGEBOB_TEETERFRONT:ANIM_SPONGEBOB_TEETERBACK;
}
setAnimNo(_player,anim);
_playerMode->setAnimNo(anim);
}
@ -124,10 +124,10 @@ void CPlayerStateTeeterIdle::enter(CPlayer *_player)
Params:
Returns:
---------------------------------------------------------------------- */
void CPlayerStateTeeterIdle::think(CPlayer *_player)
void CPlayerStateTeeterIdle::think(CPlayerModeBasic *_playerMode)
{
advanceAnimFrameAndCheckForEndOfAnim(_player);
thinkControl(_player);
_playerMode->advanceAnimFrameAndCheckForEndOfAnim();
thinkControl(_playerMode);
}
@ -137,13 +137,13 @@ void CPlayerStateTeeterIdle::think(CPlayer *_player)
Params:
Returns:
---------------------------------------------------------------------- */
void CPlayerStateIdle::enter(CPlayer *_player)
void CPlayerStateIdle::enter(CPlayerModeBasic *_playerMode)
{
m_idleTime=0;
m_currentIdleAnim=0;
m_animState=ANIMSTATE_END;
setNextIdleAnim(_player);
setNextIdleAnim(_playerMode);
}
@ -153,14 +153,13 @@ void CPlayerStateIdle::enter(CPlayer *_player)
Params:
Returns:
---------------------------------------------------------------------- */
void CPlayerStateIdle::think(CPlayer *_player)
void CPlayerStateIdle::think(CPlayerModeBasic *_playerMode)
{
thinkControl(_player);
if(advanceAnimFrameAndCheckForEndOfAnim(_player))
if(_playerMode->advanceAnimFrameAndCheckForEndOfAnim())
{
setNextIdleAnim(_player);
setNextIdleAnim(_playerMode);
}
thinkControl(_playerMode);
}
@ -170,7 +169,7 @@ void CPlayerStateIdle::think(CPlayer *_player)
Params:
Returns:
---------------------------------------------------------------------- */
void CPlayerStateIdle::setNextIdleAnim(CPlayer *_player)
void CPlayerStateIdle::setNextIdleAnim(CPlayerModeBasic *_playerMode)
{
IdleAnims *anims;
int finished=false;
@ -180,7 +179,7 @@ void CPlayerStateIdle::setNextIdleAnim(CPlayer *_player)
{
case ANIMSTATE_START:
m_animState=ANIMSTATE_LOOP;
setAnimNo(_player,anims->m_loopFrame);
_playerMode->setAnimNo(anims->m_loopFrame);
break;
case ANIMSTATE_LOOP:
if(--m_loopCount<=0)
@ -192,12 +191,12 @@ void CPlayerStateIdle::setNextIdleAnim(CPlayer *_player)
else
{
m_animState=ANIMSTATE_END;
setAnimNo(_player,anims->m_endFrame);
_playerMode->setAnimNo(anims->m_endFrame);
}
}
else
{
setAnimNo(_player,anims->m_loopFrame);
_playerMode->setAnimNo(anims->m_loopFrame);
}
break;
case ANIMSTATE_END:
@ -242,7 +241,7 @@ void CPlayerStateIdle::setNextIdleAnim(CPlayer *_player)
m_animState=ANIMSTATE_START;
}
m_loopCount=anims->m_loopCount;
setAnimNo(_player,animNo);
_playerMode->setAnimNo(animNo);
m_idleTime++;
}
@ -258,18 +257,13 @@ void CPlayerStateIdle::setNextIdleAnim(CPlayer *_player)
static IdleAnims s_unarmedIdleAnims[]=
{
// start frame loop frame end frame loop count
{ -1, ANIM_SPONGEBOB_IDLEBREATHE, -1, 4 }, // default
{ -1, ANIM_SPONGEBOB_IDLEBREATHE, -1, 10 },
{ -1, ANIM_SPONGEBOB_IDLEBREATHE, -1, 4 }, // default
{ -1, ANIM_SPONGEBOB_IDLEBREATHE, -1, 10 },
{ ANIM_SPONGEBOB_FACEFRONT, ANIM_SPONGEBOB_IDLEHOOLA, ANIM_SPONGEBOB_FACEBACK, 5 },
{ ANIM_SPONGEBOB_FACEFRONT, ANIM_SPONGEBOB_IDLEWIGGLEARM, ANIM_SPONGEBOB_FACEBACK, 5 },
{ -1, ANIM_SPONGEBOB_IDLELOOK, -1, 1 },
{ -1, ANIM_SPONGEBOB_IDLEWIND, -1, 1 },
};
//idlekick
//idlescratch
//? - idlesleep* - wakeup
//idlestretch
//idlewind
static int s_numUnarmedIdleAnims=sizeof(s_unarmedIdleAnims)/sizeof(IdleAnims);
IdleAnims *CPlayerStateUnarmedIdle::getIdleAnimsDb(int _animNo)
{
@ -291,8 +285,8 @@ int CPlayerStateUnarmedIdle::getNumIdleAnims()
static IdleAnims s_coralBlowerIdleAnims[]=
{
// start frame loop frame end frame loop count
{ -1, ANIM_SPONGEBOB_IDLEBREATHE, -1, 4 }, // default
{ -1, ANIM_SPONGEBOB_IDLEBREATHE, -1, 10 },
{ -1, ANIM_SPONGEBOB_IDLEBREATHE, -1, 4 }, // default
{ -1, ANIM_SPONGEBOB_IDLEBREATHE, -1, 10 },
{ -1, ANIM_SPONGEBOB_IDLELOOK, -1, 1 },
};
static int s_numCoralBlowerIdleAnims=sizeof(s_coralBlowerIdleAnims)/sizeof(IdleAnims);

View File

@ -36,7 +36,7 @@
class CPlayerStateBaseIdle : public CPlayerState
{
public:
void thinkControl(class CPlayer *_player);
void thinkControl(class CPlayerModeBasic *CPlayerMode);
};
@ -44,8 +44,8 @@ public:
class CPlayerStateTeeterIdle : public CPlayerStateBaseIdle
{
public:
virtual void enter(class CPlayer *_player);
virtual void think(class CPlayer *_player);
virtual void enter(class CPlayerModeBasic *_playerMode);
virtual void think(class CPlayerModeBasic *_playerMode);
};
@ -62,8 +62,8 @@ typedef struct
class CPlayerStateIdle : public CPlayerStateBaseIdle
{
public:
virtual void enter(class CPlayer *_player);
virtual void think(class CPlayer *_player);
virtual void enter(class CPlayerModeBasic *_playerMode);
virtual void think(class CPlayerModeBasic *_playerMode);
private:
typedef enum
@ -73,7 +73,7 @@ private:
ANIMSTATE_END,
} ANIMSTATE;
void setNextIdleAnim(class CPlayer *_player);
void setNextIdleAnim(class CPlayerModeBasic *_playerMode);
virtual IdleAnims *getIdleAnimsDb(int _animNo)=0;
virtual int getNumIdleAnims()=0;

View File

@ -23,6 +23,10 @@
#include "player\player.h"
#endif
#ifndef __PLAYER_PMODES_H__
#include "player\pmodes.h"
#endif
#ifndef __SOUND_SOUND_H__
#include "sound\sound.h"
#endif
@ -61,17 +65,12 @@
Params:
Returns:
---------------------------------------------------------------------- */
void CPlayerStateJump::enter(CPlayer *_player)
void CPlayerStateJump::enter(CPlayerModeBasic *_playerMode)
{
const PlayerMetrics *metrics;
metrics=getPlayerMetrics(_player);
setAnimNo(_player,ANIM_SPONGEBOB_HOVER);
_playerMode->setAnimNo(ANIM_SPONGEBOB_HOVER);
m_jumpFrames=0;
DVECTOR move=getMoveVelocity(_player);
move.vy=-metrics->m_metric[PM__JUMP_VELOCITY]<<CPlayer::VELOCITY_SHIFT;
setMoveVelocity(_player,&move);
_playerMode->jump();
CSoundMediator::playSfx(CSoundMediator::SFX_SPONGEBOB_JUMP);
}
@ -83,14 +82,14 @@ void CPlayerStateJump::enter(CPlayer *_player)
Params:
Returns:
---------------------------------------------------------------------- */
void CPlayerStateJump::think(CPlayer *_player)
void CPlayerStateJump::think(CPlayerModeBasic *_playerMode)
{
const PlayerMetrics *metrics;
int controlHeld,controlDown;
metrics=getPlayerMetrics(_player);
controlHeld=getPadInputHeld(_player);
controlDown=getPadInputDown(_player);
metrics=_playerMode->getPlayerMetrics();
controlHeld=_playerMode->getPadInputHeld();
controlDown=_playerMode->getPadInputDown();
if(m_jumpFrames<=metrics->m_metric[PM__MAX_JUMP_FRAMES]&&controlHeld&PI_JUMP)
{
@ -98,24 +97,25 @@ void CPlayerStateJump::think(CPlayer *_player)
}
else
{
setState(_player,STATE_FALL);
_playerMode->setState(STATE_FALL);
}
if(controlDown&PI_ACTION)
{
setState(_player,STATE_AIRATTACK);
}
if(controlHeld&PI_LEFT)
{
moveLeft(_player);
_playerMode->moveLeft();
}
else if(controlHeld&PI_RIGHT)
{
moveRight(_player);
_playerMode->moveRight();
}
else
{
slowdown(_player);
_playerMode->slowdown();
}
if(controlHeld&PI_DOWN)
{
_playerMode->setState(STATE_BUTTBOUNCE);
}
// advanceAnimFrameAndCheckForEndOfAnim(_player);
}

View File

@ -35,8 +35,8 @@
class CPlayerStateJump : public CPlayerState
{
public:
void enter(class CPlayer *_player);
void think(class CPlayer *_player);
void enter(class CPlayerModeBasic *_playerMode);
void think(class CPlayerModeBasic *_playerMode);
private:
int m_jumpFrames;

View File

@ -22,6 +22,10 @@
#include "player\player.h"
#endif
#ifndef __PLAYER_PMODES_H__
#include "player\pmodes.h"
#endif
/* Std Lib
------- */
@ -56,27 +60,27 @@
Params:
Returns:
---------------------------------------------------------------------- */
void CPlayerStateRun::enter(CPlayer *_player)
void CPlayerStateRun::enter(CPlayerModeBasic *_playerMode)
{
int controlHeld;
controlHeld=getPadInputHeld(_player);
controlHeld=_playerMode->getPadInputHeld();
if(getMoveVelocity(_player).vx)
if(_playerMode->getMoveVelocity().vx)
{
setAnimNo(_player,ANIM_SPONGEBOB_RUN);
_playerMode->setAnimNo(ANIM_SPONGEBOB_RUN);
}
else
{
setAnimNo(_player,ANIM_SPONGEBOB_RUNSTART);
_playerMode->setAnimNo(ANIM_SPONGEBOB_RUNSTART);
}
if(controlHeld&PI_LEFT)
{
setFacing(_player,FACING_LEFT);
_playerMode->setFacing(FACING_LEFT);
}
else if(controlHeld&PI_RIGHT)
{
setFacing(_player,FACING_RIGHT);
_playerMode->setFacing(FACING_RIGHT);
}
m_numberOfTimeAnimHasLooped=0;
@ -89,56 +93,49 @@ void CPlayerStateRun::enter(CPlayer *_player)
Params:
Returns:
---------------------------------------------------------------------- */
void CPlayerStateRun::think(CPlayer *_player)
void CPlayerStateRun::think(CPlayerModeBasic *_playerMode)
{
int controlDown,controlHeld;
int switchedState=false;
controlDown=getPadInputDown(_player);
controlHeld=getPadInputHeld(_player);
controlDown=_playerMode->getPadInputDown();
controlHeld=_playerMode->getPadInputHeld();
if(controlDown&PI_JUMP)
{
switchedState=setState(_player,STATE_JUMP);
switchedState=_playerMode->setState(STATE_JUMP);
}
if(controlHeld&PI_DOWN)
{
switchedState=setState(_player,STATE_DUCK);
}
if(controlDown&PI_ACTION)
{
switchedState=setState(_player,STATE_RUNATTACK);
switchedState=_playerMode->setState(STATE_DUCK);
}
if(controlHeld&PI_LEFT)
{
moveLeft(_player);
_playerMode->moveLeft();
}
else if(controlHeld&PI_RIGHT)
{
moveRight(_player);
_playerMode->moveRight();
}
else
{
if(getMoveVelocity(_player).vx==0)
if(!switchedState)
{
if(!switchedState)
if(_playerMode->slowdown())
{
setState(_player,STATE_IDLE);
_playerMode->setState(STATE_IDLE);
if(m_numberOfTimeAnimHasLooped>=4)
{
setAnimNo(_player,ANIM_SPONGEBOB_RUNSTOP);
_playerMode->setAnimNo(ANIM_SPONGEBOB_RUNSTOP);
}
return;
}
}
else
{
slowdown(_player);
}
}
if(advanceAnimFrameAndCheckForEndOfAnim(_player))
if(_playerMode->advanceAnimFrameAndCheckForEndOfAnim())
{
setAnimNo(_player,ANIM_SPONGEBOB_RUN);
_playerMode->setAnimNo(ANIM_SPONGEBOB_RUN);
m_numberOfTimeAnimHasLooped++;
}
}

View File

@ -35,8 +35,8 @@
class CPlayerStateRun : public CPlayerState
{
public:
void enter(class CPlayer *_player);
void think(class CPlayer *_player);
void enter(class CPlayerModeBasic *_playerMode);
void think(class CPlayerModeBasic *_playerMode);
private:
int m_numberOfTimeAnimHasLooped;

View File

@ -18,11 +18,6 @@
Includes
-------- */
#ifndef _GLOBAL_HEADER_
#include "system\global.h"
#endif
/* Std Lib
------- */
@ -37,41 +32,8 @@
class CPlayerState
{
public:
virtual void enter(class CPlayer *_player) {;}
virtual void think(class CPlayer *_player) {;}
protected:
const struct PlayerMetrics *getPlayerMetrics(class CPlayer *_player);
int setState(class CPlayer *_player,int _state);
void setMode(class CPlayer *_player,int _mode);
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);
int retreatAnimFrameAndCheckForEndOfAnim(class CPlayer *_player);
DVECTOR getMoveVelocity(class CPlayer *_player);
void setMoveVelocity(class CPlayer *_player,DVECTOR *_moveVel);
DVECTOR getPlayerPos(class CPlayer *_player);
void setPlayerPos(class CPlayer *_player,DVECTOR *_pos);
int getPadInputHeld(class CPlayer *_player);
int getPadInputDown(class CPlayer *_player);
int isOnEdge(class CPlayer *_player);
int canMoveLeft(class CPlayer *_player);
int canMoveRight(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);
void respawn(class CPlayer *_player);
virtual void enter(class CPlayerModeBasic *_playerMode) {;}
virtual void think(class CPlayerModeBasic *_playerMode) {;}
};