This commit is contained in:
Paul 2001-01-19 23:37:40 +00:00
parent f7614f78e0
commit 302b1cb2e9
3 changed files with 331 additions and 213 deletions

View File

@ -123,7 +123,11 @@ pad_src := pads
paul_src := paul \ paul_src := paul \
scenesel scenesel
player_src := player player_src := player \
psfall \
psjump \
psrun \
pstates
script_src := script \ script_src := script \
function function

View File

@ -11,7 +11,6 @@
===========================================================================*/ ===========================================================================*/
/*---------------------------------------------------------------------- /*----------------------------------------------------------------------
Includes Includes
-------- */ -------- */
@ -26,15 +25,9 @@
#include "pad\pads.h" #include "pad\pads.h"
#endif #endif
#ifndef __UTILS_HEADER__
#include "utils\utils.h"
#endif
// to be removed // to be removed
//#include "fileio\fileio.h"
#include "gfx\tpage.h" #include "gfx\tpage.h"
//#include "gfx\prim.h"
/* Std Lib /* Std Lib
@ -51,13 +44,6 @@
Structure defintions Structure defintions
-------------------- */ -------------------- */
#define ANIM_IDLE_SHORT 0
#define ANIM_IDLE_LONG 0
#define ANIM_RUNSTART 0
#define ANIM_RUN 0
#define ANIM_RUNSTOP 0
/*---------------------------------------------------------------------- /*----------------------------------------------------------------------
Function Prototypes Function Prototypes
------------------- */ ------------------- */
@ -66,12 +52,35 @@
Vars Vars
---- */ ---- */
int JUMP_VELOCITY=8;
int MAX_JUMP_FRAMES=10;
int MAX_SAFE_FALL_FRAMES=20;
int GRAVITY_VALUE=4;
int TERMINAL_VELOCITY=8;
int MAX_RUN_VELOCITY=8;
int RUN_SPEEDUP=4;
int RUN_REVERSESLOWDOWN=2;
int RUN_SLOWDOWN=1;
int PSHIFT=2;
/*---------------------------------------------------------------------- /*----------------------------------------------------------------------
Function: Function:
Purpose: Purpose:
Params: Params:
Returns: Returns:
---------------------------------------------------------------------- */ ---------------------------------------------------------------------- */
#include "player\pstates.h"
#include "player\psjump.h"
#include "player\psrun.h"
#include "player\psfall.h"
CPlayerStateIdle testStateIdle;
CPlayerStateJump testStateJump;
CPlayerStateRun testStateRun;
CPlayerStateFall testStateFall;
CPlayerStateFallFar testStateFallFar;
void CPlayer::init() void CPlayer::init()
{ {
CThing::init(); CThing::init();
@ -81,9 +90,15 @@ void CPlayer::init()
TPLoadTex(ACTORS_SPONGEBOB_TEX); TPLoadTex(ACTORS_SPONGEBOB_TEX);
m_skel.setAnimDatabase(CAnimDB::GetPlayerAnimBank()); m_skel.setAnimDatabase(CAnimDB::GetPlayerAnimBank());
m_animNo=0;
m_animFrame=0;
setState(STATE_IDLE); setState(STATE_IDLE);
m_runVel=0; m_moveVel.vx=0;
m_moveVel.vy=0;
setFacing(FACING_RIGHT); setFacing(FACING_RIGHT);
Pos.vx=50;
Pos.vy=400;
} }
/*---------------------------------------------------------------------- /*----------------------------------------------------------------------
@ -107,127 +122,40 @@ void CPlayer::think(int _frames)
{ {
CThing::think(_frames); CThing::think(_frames);
int padInput; #ifndef __USER_paul__
int padInput=PadGetHeld(0);
int move=7*_frames;
if(padInput&PAD_UP) Pos.vy-=move;
if(padInput&PAD_DOWN) Pos.vy+=move;
if(padInput&PAD_LEFT) Pos.vx-=move;
if(padInput&PAD_RIGHT) Pos.vx+=move;
#else
if(_frames>=3)_frames=2;
if(_frames>=3)_frames=2; for(int i=0;i<_frames;i++)
padInput=getPadInput();
switch(m_state)
{ {
case STATE_IDLE: // Think
if(padInput&(PAD_LEFT|PAD_RIGHT)) m_currentState->think(this);
{ Pos.vx+=m_moveVel.vx>>PSHIFT;
if(padInput&PAD_LEFT) Pos.vy+=m_moveVel.vy>>PSHIFT;
{
setFacing(FACING_LEFT);
}
else
{
setFacing(FACING_RIGHT);
}
setState(STATE_RUNSTART);
m_runVel=RUN_SPEEDUP;
}
break;
case STATE_RUNSTART: // Ground collision
case STATE_RUN: if(m_moveVel.vy&&isOnSolidGround())
if(padInput&(PAD_LEFT|PAD_RIGHT)) {
if(m_moveVel.vx)
{ {
if(m_facing==FACING_LEFT) setState(STATE_RUN);
{
// Running left
if(padInput&PAD_LEFT)
{
m_runVel+=RUN_SPEEDUP;
if(m_runVel>MAX_RUN_VELOCITY)
{
m_runVel=MAX_RUN_VELOCITY;
}
}
else
{
m_runVel-=RUN_REVERSESLOWDOWN;
if(m_runVel<1)
{
m_runVel=0;
setFacing(FACING_RIGHT);
}
}
}
else
{
// Running right
if(padInput&PAD_RIGHT)
{
m_runVel+=RUN_SPEEDUP;
if(m_runVel>MAX_RUN_VELOCITY)
{
m_runVel=MAX_RUN_VELOCITY;
}
}
else
{
m_runVel-=RUN_REVERSESLOWDOWN;
if(m_runVel<1)
{
m_runVel=0;
setFacing(FACING_LEFT);
}
}
}
} }
else else
{ {
m_runVel-=RUN_SLOWDOWN; setState(STATE_IDLE);
if(m_runVel<1)
{
m_runVel=0;
setState(STATE_RUNSTOP);
}
} }
break; m_moveVel.vy=0;
}
case STATE_RUNSTOP:
break;
case NUM_STATES:
break;
} }
#endif
Pos.vx-=m_runVel*m_facing*_frames;
if(Pos.vx<0)Pos.vx=0; if(Pos.vx<0)Pos.vx=0;
if(Pos.vy<0)Pos.vy=500;
// Animate
m_frame+=_frames;
if(m_frame>=m_skel.getFrameCount())
{
// PKG - Overlap..!?
m_frame=0;
finishedAnim();
}
if(padInput&PAD_UP)
{
Pos.vy-=5;
}
else if(padInput&PAD_DOWN)
{
Pos.vy+=5;
}
if(Pos.vy<0)Pos.vy=0;
} }
/*---------------------------------------------------------------------- /*----------------------------------------------------------------------
@ -236,103 +164,230 @@ if(_frames>=3)_frames=2;
Params: Params:
Returns: Returns:
---------------------------------------------------------------------- */ ---------------------------------------------------------------------- */
int panim=-1;
void CPlayer::render() void CPlayer::render()
{ {
CThing::render(); CThing::render();
// Render // Render
m_skel.setFrame(m_frame); m_skel.setFrame(m_animFrame);
m_skel.setAnimNo(m_animNo); if(panim!=-1)
m_skel.setAnimNo(panim);
else
m_skel.setAnimNo(m_animNo);
m_skel.Animate(this); m_skel.Animate(this);
m_skel.Render(this); m_skel.Render(this);
} }
/*---------------------------------------------------------------------- /*----------------------------------------------------------------------
Function: Function:
Purpose: Purpose:
Params: Params:
Returns: Returns:
---------------------------------------------------------------------- */ ---------------------------------------------------------------------- */
int CPlayer::s_stateAnims[NUM_STATES]= int metrics[CPlayer::NUM_PLAYER_METRICS]=
{ {
ANIM_IDLE_SHORT, // STATE_IDLE 8, // PM__JUMP_VELOCITY
ANIM_RUNSTART, // STATE_RUNSTART 10, // PM__MAX_JUMP_FRAMES
ANIM_RUN, // STATE_RUN 20, // PM__MAX_SAFE_FALL_FRAMES
ANIM_RUNSTOP, // STATE_RUNSTOP 4, // PM__GRAVITY_VALUE
8, // PM__TERMINAL_VELOCITY
8, // PM__MAX_RUN_VELOCITY
4, // PM__RUN_SPEEDUP
2, // PM__RUN_REVERSESLOWDOWN
1, // PM__RUN_SLOWDOWN
2, // PM__PSHIFT
};
int CPlayer::getPlayerMetric(PLAYER_METRIC _metric)
{
return metrics[_metric];
}
/*----------------------------------------------------------------------
Function:
Purpose:
Params:
Returns:
---------------------------------------------------------------------- */
CPlayerState *CPlayer::s_states[NUM_STATES]=
{
&testStateIdle, // STATE_IDLE
&testStateJump, // STATE_JUMP
&testStateRun, // STATE_RUN
&testStateFall, // STATE_FALL
&testStateFallFar, // STATE_FALLFAR
}; };
int panim=-1;
void CPlayer::setState(PLAYER_STATE _state) void CPlayer::setState(PLAYER_STATE _state)
{ {
PAUL_DBGMSG("set state %d",_state);
m_currentState=s_states[_state];
m_currentState->enter(this);
m_state=_state; m_state=_state;
m_animNo=s_stateAnims[_state];
if(panim!=-1)m_animNo=panim;
m_frame=0;
} }
/*---------------------------------------------------------------------- /*----------------------------------------------------------------------
Function: Function:
Purpose: Purpose:
Params: Params:
Returns: Returns:
---------------------------------------------------------------------- */ ---------------------------------------------------------------------- */
int CPlayer::getFacing()
{
return m_facing;
}
void CPlayer::setFacing(int _facing) void CPlayer::setFacing(int _facing)
{ {
switch(_facing) if(m_facing!=_facing)
{ {
case FACING_LEFT: switch(_facing)
m_facing=FACING_LEFT; {
m_skel.setAng(512); case FACING_LEFT:
break; m_facing=FACING_LEFT;
case FACING_RIGHT: m_skel.setAng(512);
m_facing=FACING_RIGHT; break;
m_skel.setAng(3096+512); case FACING_RIGHT:
break; m_facing=FACING_RIGHT;
default: m_skel.setAng(3096+512);
ASSERT(0); break;
break; default:
ASSERT(0);
break;
}
} }
} }
int CPlayer::getAnimFrame()
/*----------------------------------------------------------------------
Function:
Purpose:
Params:
Returns:
---------------------------------------------------------------------- */
void CPlayer::finishedAnim()
{ {
switch(m_state) return m_animFrame;
{ }
case STATE_IDLE: void CPlayer::setAnimFrame(int _animFrame)
if(getRndRange(100)<95) {
m_animNo=ANIM_IDLE_SHORT; m_animFrame=_animFrame;
else }
m_animNo=ANIM_IDLE_LONG; int CPlayer::getAnimFrameCount()
break; {
case STATE_RUNSTART: return m_skel.getFrameCount();
setState(STATE_RUN); }
break; int CPlayer::getAnimNo()
case STATE_RUN: {
break; return m_animNo;
case STATE_RUNSTOP: }
setState(STATE_IDLE); void CPlayer::setAnimNo(int _animNo)
break; {
case NUM_STATES: m_animNo=_animNo;
break; m_animFrame=0;
} }
DVECTOR CPlayer::getMoveVelocity()
{
return m_moveVel;
}
void CPlayer::setMoveVelocity(DVECTOR *_moveVel)
{
m_moveVel=*_moveVel;
} }
/*----------------------------------------------------------------------
Function:
Purpose:
Params:
Returns:
---------------------------------------------------------------------- */
int CPlayer::getPadInput() int CPlayer::getPadInput()
{ {
return PadGetHeld(0); return PadGetHeld(0);
} }
/*----------------------------------------------------------------------
Function:
Purpose:
Params:
Returns:
---------------------------------------------------------------------- */
int CPlayer::isOnSolidGround()
{
return Pos.vy>400;
}
void CPlayer::moveLeft()
{
setFacing(FACING_LEFT);
if(m_moveVel.vx<=0)
{
m_moveVel.vx-=RUN_SPEEDUP;
if(m_moveVel.vx<-MAX_RUN_VELOCITY<<PSHIFT)
{
m_moveVel.vx=-MAX_RUN_VELOCITY<<PSHIFT;
// setFacing(FACING_LEFT);
}
}
else
{
m_moveVel.vx-=RUN_REVERSESLOWDOWN;
// if(m_moveVel.vx<=0)
// {
// setFacing(FACING_LEFT);
// }
}
}
void CPlayer::moveRight()
{
setFacing(FACING_RIGHT);
if(m_moveVel.vx>=0)
{
m_moveVel.vx+=RUN_SPEEDUP;
if(m_moveVel.vx>MAX_RUN_VELOCITY<<PSHIFT)
{
m_moveVel.vx=MAX_RUN_VELOCITY<<PSHIFT;
// setFacing(FACING_RIGHT);
}
}
else
{
m_moveVel.vx+=RUN_REVERSESLOWDOWN;
// if(m_moveVel.vx>=0)
// {
// setFacing(FACING_RIGHT);
// }
}
}
void CPlayer::slowdown()
{
if(m_moveVel.vx<0)
{
m_moveVel.vx+=RUN_SLOWDOWN;
if(m_moveVel.vx>0)m_moveVel.vx=0;
}
else if(m_moveVel.vx>0)
{
m_moveVel.vx-=RUN_SLOWDOWN;
if(m_moveVel.vx<0)m_moveVel.vx=0;
}
}
void CPlayer::jump()
{
}
void CPlayer::fall()
{
}
/*=========================================================================== /*===========================================================================
end */ end */

View File

@ -30,6 +30,10 @@
#include <dstructs.h> #include <dstructs.h>
#endif #endif
#ifndef __PLAYER_PSTATES_H__
#include "player\pstates.h"
#endif
/* Std Lib /* Std Lib
------- */ ------- */
@ -38,58 +42,113 @@
Tyepdefs && Defines Tyepdefs && Defines
------------------- */ ------------------- */
#define ANIM_IDLE_SHORT 0
#define ANIM_IDLE_LONG 1
#define ANIM_JUMP 0
#define ANIM_RUNSTART 2
#define ANIM_RUN 3
#define ANIM_RUNSTOP 4
typedef enum
{
STATE_IDLE,
STATE_JUMP,
STATE_RUN,
STATE_FALL,
STATE_FALLFAR,
NUM_STATES,
}PLAYER_STATE;
enum
{
FACING_LEFT=+1,
FACING_RIGHT=-1,
};
extern int JUMP_VELOCITY;
extern int MAX_JUMP_FRAMES;
extern int MAX_SAFE_FALL_FRAMES;
extern int GRAVITY_VALUE;
extern int TERMINAL_VELOCITY;
extern int MAX_RUN_VELOCITY;
extern int RUN_SPEEDUP;
extern int RUN_REVERSESLOWDOWN;
extern int RUN_SLOWDOWN;
extern int PSHIFT;
/*---------------------------------------------------------------------- /*----------------------------------------------------------------------
Structure defintions Structure defintions
-------------------- */ -------------------- */
class CPlayer : public CThing class CPlayer : public CThing
{ {
public: public:
typedef enum
{
PM__JUMP_VELOCITY,
PM__MAX_JUMP_FRAMES,
PM__MAX_SAFE_FALL_FRAMES,
PM__GRAVITY_VALUE,
PM__TERMINAL_VELOCITY,
PM__MAX_RUN_VELOCITY,
PM__RUN_SPEEDUP,
PM__RUN_REVERSESLOWDOWN,
PM__RUN_SLOWDOWN,
PM__PSHIFT,
NUM_PLAYER_METRICS
}PLAYER_METRIC;
void init(); void init();
void shutdown(); void shutdown();
void think(int _frames); void think(int _frames);
void render(); void render();
private: protected:
typedef enum int getPlayerMetric(PLAYER_METRIC _metric);
{
STATE_IDLE,
STATE_RUNSTART,
STATE_RUN,
STATE_RUNSTOP,
NUM_STATES,
}PLAYER_STATE;
enum
{
MAX_RUN_VELOCITY=8,
RUN_SPEEDUP=4,
RUN_REVERSESLOWDOWN=2,
RUN_SLOWDOWN=1,
};
enum
{
FACING_LEFT=+1,
FACING_RIGHT=-1,
};
void setState(PLAYER_STATE _state); void setState(PLAYER_STATE _state);
int getFacing();
void setFacing(int _facing); void setFacing(int _facing);
void finishedAnim(); int getAnimFrame();
void setAnimFrame(int _animFrame);
int getAnimFrameCount();
int getAnimNo();
void setAnimNo(int _animNo);
DVECTOR getMoveVelocity();
void setMoveVelocity(DVECTOR *_moveVel);
virtual int getPadInput(); virtual int getPadInput();
int m_frame; int isOnSolidGround();
void moveLeft();
void moveRight();
void slowdown();
void jump();
void fall();
friend class CPlayerState;
private:
int m_animFrame;
int m_animNo; int m_animNo;
PLAYER_STATE m_state; PLAYER_STATE m_state;
CSkel m_skel; CSkel m_skel;
int m_runVel; DVECTOR m_moveVel;
int m_facing; int m_facing;
static int s_stateAnims[NUM_STATES]; static class CPlayerState *s_states[NUM_STATES];
class CPlayerState *m_currentState;
}; };