This commit is contained in:
Paul 2001-01-16 19:27:14 +00:00
parent d7e13123b1
commit e890f6ce88
2 changed files with 190 additions and 52 deletions

View File

@ -1,22 +1,55 @@
/**************/
/*** Player ***/
/**************/
/*=========================================================================
#include "system\global.h"
#include "Game\Thing.h"
#include "Gfx\Skel.h"
player.cpp
Author: PKG
Created:
Project: Spongebob
Purpose:
Copyright (c) 2001 Climax Development Ltd
===========================================================================*/
/*----------------------------------------------------------------------
Includes
-------- */
#include "player\player.h"
#ifndef __ANIM_HEADER__
#include "gfx\anim.h"
#include "Player\Player.h"
#endif
#ifndef __PAD_PADS_H__
#include "pad\pads.h"
#endif
#ifndef __UTILS_HEADER__
#include "utils\utils.h"
#endif
// to be removed
#include "fileio\fileio.h"
#include "utils\utils.h"
//#include "fileio\fileio.h"
#include "gfx\tpage.h"
#include "gfx\prim.h"
//#include "gfx\prim.h"
/* Std Lib
------- */
/* Data
---- */
/*----------------------------------------------------------------------
Tyepdefs && Defines
------------------- */
/*----------------------------------------------------------------------
Structure defintions
-------------------- */
#define ANIM_IDLE_SHORT 15
#define ANIM_IDLE_LONG 16
@ -25,8 +58,20 @@
#define ANIM_RUNSTOP 30
/*----------------------------------------------------------------------
Function Prototypes
------------------- */
/*****************************************************************************/
/*----------------------------------------------------------------------
Vars
---- */
/*----------------------------------------------------------------------
Function:
Purpose:
Params:
Returns:
---------------------------------------------------------------------- */
void CPlayer::init()
{
CThing::init();
@ -38,17 +83,26 @@ void CPlayer::init()
setState(STATE_IDLE);
m_runVel=0;
m_facing=-1;
setFacing(FACING_RIGHT);
}
/*****************************************************************************/
/*----------------------------------------------------------------------
Function:
Purpose:
Params:
Returns:
---------------------------------------------------------------------- */
void CPlayer::shutdown()
{
CThing::shutdown();
}
/*****************************************************************************/
/*----------------------------------------------------------------------
Function:
Purpose:
Params:
Returns:
---------------------------------------------------------------------- */
void CPlayer::think(int _frames)
{
CThing::think(_frames);
@ -57,8 +111,7 @@ void CPlayer::think(int _frames)
if(_frames>=3)_frames=2;
// PKG - Needs to come from somewhere local rather than direct from pad handler..
padInput=PadGetHeld(0);
padInput=getPadInput();
switch(m_state)
{
@ -67,13 +120,11 @@ if(_frames>=3)_frames=2;
{
if(padInput&PAD_LEFT)
{
m_facing=FACING_LEFT;
m_skel.setAng(512);
setFacing(FACING_LEFT);
}
else
{
m_facing=FACING_RIGHT;
m_skel.setAng(3096+512);
setFacing(FACING_RIGHT);
}
setState(STATE_RUNSTART);
m_runVel=RUN_SPEEDUP;
@ -101,8 +152,7 @@ if(_frames>=3)_frames=2;
if(m_runVel<1)
{
m_runVel=0;
m_facing=FACING_RIGHT;
m_skel.setAng(3096+512);
setFacing(FACING_RIGHT);
}
}
}
@ -123,8 +173,7 @@ if(_frames>=3)_frames=2;
if(m_runVel<1)
{
m_runVel=0;
m_facing=FACING_LEFT;
m_skel.setAng(512);
setFacing(FACING_LEFT);
}
}
}
@ -181,8 +230,12 @@ if(_frames>=3)_frames=2;
if(Pos.vy<0)Pos.vy=0;
}
/*****************************************************************************/
/*----------------------------------------------------------------------
Function:
Purpose:
Params:
Returns:
---------------------------------------------------------------------- */
void CPlayer::render()
{
CThing::render();
@ -194,8 +247,12 @@ void CPlayer::render()
m_skel.Render(this);
}
/*****************************************************************************/
/*----------------------------------------------------------------------
Function:
Purpose:
Params:
Returns:
---------------------------------------------------------------------- */
int CPlayer::s_stateAnims[NUM_STATES]=
{
ANIM_IDLE_SHORT, // STATE_IDLE
@ -213,9 +270,36 @@ if(panim!=-1)m_animNo=panim;
m_frame=0;
}
/*----------------------------------------------------------------------
Function:
Purpose:
Params:
Returns:
---------------------------------------------------------------------- */
void CPlayer::setFacing(int _facing)
{
switch(_facing)
{
case FACING_LEFT:
m_facing=FACING_LEFT;
m_skel.setAng(512);
break;
case FACING_RIGHT:
m_facing=FACING_RIGHT;
m_skel.setAng(3096+512);
break;
default:
ASSERT(0);
break;
}
}
/*****************************************************************************/
/*----------------------------------------------------------------------
Function:
Purpose:
Params:
Returns:
---------------------------------------------------------------------- */
void CPlayer::finishedAnim()
{
switch(m_state)
@ -239,6 +323,16 @@ void CPlayer::finishedAnim()
}
}
/*----------------------------------------------------------------------
Function:
Purpose:
Params:
Returns:
---------------------------------------------------------------------- */
int CPlayer::getPadInput()
{
return PadGetHeld(0);
}
/*===========================================================================
end */

View File

@ -1,16 +1,46 @@
/**************/
/*** Player ***/
/**************/
/*=========================================================================
player.h
Author: PKG
Created:
Project: Spongebob
Purpose:
Copyright (c) 2001 Climax Development Ltd
===========================================================================*/
#ifndef __PLAYER_PLAYER_H__
#define __PLAYER_PLAYER_H__
#include <dstructs.h>
/*----------------------------------------------------------------------
Includes
-------- */
#ifndef __GAME_THING_H__
#include "Game/Thing.h"
#endif
#ifndef __SKEL_HEADER__
#include "Gfx/Skel.h"
#endif
#ifndef __DATA_STRUCTS_HEADER__
#include <dstructs.h>
#endif
/*****************************************************************************/
/* Std Lib
------- */
/*----------------------------------------------------------------------
Tyepdefs && Defines
------------------- */
/*----------------------------------------------------------------------
Structure defintions
-------------------- */
class CPlayer : public CThing
{
@ -32,15 +62,6 @@ private:
NUM_STATES,
}PLAYER_STATE;
void setState(PLAYER_STATE _state);
void finishedAnim();
int m_frame;
int m_animNo;
PLAYER_STATE m_state;
CSkel m_skel;
enum
{
MAX_RUN_VELOCITY=8,
@ -48,13 +69,24 @@ private:
RUN_REVERSESLOWDOWN=2,
RUN_SLOWDOWN=1,
};
int m_runVel;
enum
{
FACING_LEFT=+1,
FACING_RIGHT=-1,
};
void setState(PLAYER_STATE _state);
void setFacing(int _facing);
void finishedAnim();
virtual int getPadInput();
int m_frame;
int m_animNo;
PLAYER_STATE m_state;
CSkel m_skel;
int m_runVel;
int m_facing;
static int s_stateAnims[NUM_STATES];
@ -62,5 +94,17 @@ private:
};
/*****************************************************************************/
#endif
/*----------------------------------------------------------------------
Globals
------- */
/*----------------------------------------------------------------------
Functions
--------- */
/*---------------------------------------------------------------------- */
#endif /* __PLAYER_PLAYER_H__ */
/*===========================================================================
end */