SBSPSS/source/player/psidle.cpp

306 lines
6.9 KiB
C++
Raw Normal View History

2001-01-24 16:52:31 +01:00
/*=========================================================================
psidle.cpp
Author: PKG
Created:
Project: Spongebob
Purpose:
Copyright (c) 2001 Climax Development Ltd
===========================================================================*/
/*----------------------------------------------------------------------
Includes
-------- */
#include "player\psidle.h"
2001-03-23 21:09:14 +01:00
#ifndef __PLAYER_PMODES_H__
#include "player\pmodes.h"
2001-01-24 16:52:31 +01:00
#endif
#ifndef __UTILS_HEADER__
#include "utils\utils.h"
#endif
/* Std Lib
------- */
/* Data
---- */
2001-02-26 21:05:31 +01:00
#ifndef __ANIM_SPONGEBOB_HEADER__
#include <ACTOR_SPONGEBOB_ANIM.h>
2001-01-24 16:52:31 +01:00
#endif
/*----------------------------------------------------------------------
Tyepdefs && Defines
------------------- */
/*----------------------------------------------------------------------
Structure defintions
-------------------- */
/*----------------------------------------------------------------------
Function Prototypes
------------------- */
/*----------------------------------------------------------------------
Vars
---- */
2001-04-03 18:47:07 +02:00
CPlayerStateUnarmedIdle s_stateUnarmedIdle;
CPlayerStateTeeterIdle s_stateTeeterIdle;
2001-04-10 20:44:12 +02:00
CPlayerStateWeaponIdle s_stateWeaponIdle;
2001-04-03 18:47:07 +02:00
2001-02-06 18:15:28 +01:00
/*----------------------------------------------------------------------
Function:
Purpose:
Params:
Returns:
---------------------------------------------------------------------- */
2001-03-25 22:36:28 +02:00
void CPlayerStateBaseIdle::thinkControl(CPlayerModeBase *_playerMode)
2001-02-06 18:15:28 +01:00
{
int controlDown,controlHeld;
2001-03-23 21:09:14 +01:00
controlDown=_playerMode->getPadInputDown();
controlHeld=_playerMode->getPadInputHeld();
2001-02-06 18:15:28 +01:00
2001-02-09 18:01:04 +01:00
if(controlDown&PI_JUMP)
2001-02-06 18:15:28 +01:00
{
2001-03-23 21:09:14 +01:00
_playerMode->setState(STATE_JUMP);
2001-02-06 18:15:28 +01:00
}
2001-02-09 18:01:04 +01:00
else if(controlHeld&PI_LEFT)
2001-02-06 18:15:28 +01:00
{
2001-03-23 21:09:14 +01:00
if(_playerMode->canMoveLeft())
_playerMode->setState(STATE_RUN);
2001-02-06 18:15:28 +01:00
}
2001-02-09 18:01:04 +01:00
else if(controlHeld&PI_RIGHT)
2001-02-06 18:15:28 +01:00
{
2001-03-23 21:09:14 +01:00
if(_playerMode->canMoveRight())
_playerMode->setState(STATE_RUN);
2001-02-06 18:15:28 +01:00
}
2001-04-05 16:40:50 +02:00
else if(controlDown&PI_DOWN)
2001-02-06 18:15:28 +01:00
{
2001-05-14 18:43:48 +02:00
_playerMode->setState(STATE_CROUCHDOWN);
2001-02-06 18:15:28 +01:00
}
}
/*----------------------------------------------------------------------
Function:
Purpose:
Params:
Returns:
---------------------------------------------------------------------- */
2001-03-25 22:36:28 +02:00
void CPlayerStateTeeterIdle::enter(CPlayerModeBase *_playerMode)
2001-02-06 18:15:28 +01:00
{
int edgeType,dir;
int anim;
2001-03-23 21:09:14 +01:00
edgeType=_playerMode->isOnEdge();
dir=_playerMode->getFacing();
2001-02-06 18:15:28 +01:00
if(edgeType==FACING_LEFT)
{
2001-02-26 21:05:31 +01:00
anim=dir==FACING_LEFT?ANIM_SPONGEBOB_TEETERFRONT:ANIM_SPONGEBOB_TEETERBACK;
2001-02-06 18:15:28 +01:00
}
else
{
2001-02-26 21:05:31 +01:00
anim=dir==FACING_RIGHT?ANIM_SPONGEBOB_TEETERFRONT:ANIM_SPONGEBOB_TEETERBACK;
2001-02-06 18:15:28 +01:00
}
2001-03-23 21:09:14 +01:00
_playerMode->setAnimNo(anim);
2001-02-06 18:15:28 +01:00
}
/*----------------------------------------------------------------------
Function:
Purpose:
Params:
Returns:
---------------------------------------------------------------------- */
2001-03-25 22:36:28 +02:00
void CPlayerStateTeeterIdle::think(CPlayerModeBase *_playerMode)
2001-02-06 18:15:28 +01:00
{
2001-03-23 21:09:14 +01:00
_playerMode->advanceAnimFrameAndCheckForEndOfAnim();
thinkControl(_playerMode);
2001-02-06 18:15:28 +01:00
}
2001-01-24 16:52:31 +01:00
/*----------------------------------------------------------------------
Function:
Purpose:
Params:
Returns:
---------------------------------------------------------------------- */
2001-03-25 22:36:28 +02:00
void CPlayerStateIdle::enter(CPlayerModeBase *_playerMode)
2001-01-24 16:52:31 +01:00
{
2001-01-25 18:43:10 +01:00
m_idleTime=0;
m_currentIdleAnim=0;
m_animState=ANIMSTATE_END;
2001-03-23 21:09:14 +01:00
setNextIdleAnim(_playerMode);
2001-01-24 16:52:31 +01:00
}
/*----------------------------------------------------------------------
Function:
Purpose:
Params:
Returns:
---------------------------------------------------------------------- */
2001-03-25 22:36:28 +02:00
void CPlayerStateIdle::think(CPlayerModeBase *_playerMode)
2001-01-24 16:52:31 +01:00
{
2001-03-23 21:09:14 +01:00
if(_playerMode->advanceAnimFrameAndCheckForEndOfAnim())
2001-01-29 20:23:04 +01:00
{
2001-03-23 21:09:14 +01:00
setNextIdleAnim(_playerMode);
2001-01-29 20:23:04 +01:00
}
2001-03-23 21:09:14 +01:00
thinkControl(_playerMode);
2001-01-25 18:43:10 +01:00
}
/*----------------------------------------------------------------------
Function:
Purpose:
Params:
Returns:
---------------------------------------------------------------------- */
2001-03-25 22:36:28 +02:00
void CPlayerStateIdle::setNextIdleAnim(CPlayerModeBase *_playerMode)
2001-01-25 18:43:10 +01:00
{
IdleAnims *anims;
2001-01-29 23:35:18 +01:00
int finished=false;
2001-01-25 18:43:10 +01:00
2001-01-29 23:35:18 +01:00
anims=getIdleAnimsDb(m_currentIdleAnim);
2001-01-25 18:43:10 +01:00
switch(m_animState)
{
case ANIMSTATE_START:
m_animState=ANIMSTATE_LOOP;
2001-03-23 21:09:14 +01:00
_playerMode->setAnimNo(anims->m_loopFrame);
2001-01-25 18:43:10 +01:00
break;
case ANIMSTATE_LOOP:
if(--m_loopCount<=0)
{
if(anims->m_endFrame==-1)
{
finished=true;
}
else
{
m_animState=ANIMSTATE_END;
2001-03-23 21:09:14 +01:00
_playerMode->setAnimNo(anims->m_endFrame);
2001-01-25 18:43:10 +01:00
}
}
else
{
2001-03-23 21:09:14 +01:00
_playerMode->setAnimNo(anims->m_loopFrame);
2001-01-25 18:43:10 +01:00
}
break;
case ANIMSTATE_END:
finished=true;
break;
}
if(finished)
{
int animNo;
if(m_idleTime<5)
{
2001-02-01 22:55:22 +01:00
// Run the default idle anim a number of times before
// starting to do weird things..
m_currentIdleAnim=0;
2001-01-25 18:43:10 +01:00
}
2001-01-24 16:52:31 +01:00
else
2001-01-25 18:43:10 +01:00
{
2001-02-01 22:55:22 +01:00
// Alternate random idle anims with the default one
if(m_currentIdleAnim==0&&getNumIdleAnims()>1)
2001-01-25 18:43:10 +01:00
{
2001-02-01 22:55:22 +01:00
m_currentIdleAnim=getRndRange(getNumIdleAnims());
2001-01-25 18:43:10 +01:00
}
else
{
m_currentIdleAnim=0;
}
}
// Start playing the anim
2001-01-29 23:35:18 +01:00
anims=getIdleAnimsDb(m_currentIdleAnim);
2001-01-25 18:43:10 +01:00
if(anims->m_startFrame==-1)
{
// No start anim - go straight into loop
animNo=anims->m_loopFrame;
m_animState=ANIMSTATE_LOOP;
}
else
{
// Play start anim for this idle
animNo=anims->m_startFrame;
m_animState=ANIMSTATE_START;
}
m_loopCount=anims->m_loopCount;
2001-03-23 21:09:14 +01:00
_playerMode->setAnimNo(animNo);
2001-01-25 18:43:10 +01:00
m_idleTime++;
2001-01-24 16:52:31 +01:00
}
}
2001-01-29 23:35:18 +01:00
/*----------------------------------------------------------------------
Function:
Purpose:
Params:
Returns:
---------------------------------------------------------------------- */
static IdleAnims s_unarmedIdleAnims[]=
{
// start frame loop frame end frame loop count
2001-05-09 22:26:11 +02:00
{ -1, ANIM_SPONGEBOB_IDLEBREATH, -1, 160 }, // default
{ -1, ANIM_SPONGEBOB_IDLEBREATH, -1, 160 },
{ -1, ANIM_SPONGEBOB_IDLEBREATH, -1, 80 },
2001-04-02 17:48:02 +02:00
{ -1, ANIM_SPONGEBOB_IDLEWIND, -1, 1 },
2001-04-01 22:22:49 +02:00
2001-01-29 23:35:18 +01:00
};
static int s_numUnarmedIdleAnims=sizeof(s_unarmedIdleAnims)/sizeof(IdleAnims);
IdleAnims *CPlayerStateUnarmedIdle::getIdleAnimsDb(int _animNo)
{
ASSERT(_animNo<getNumIdleAnims());
return &s_unarmedIdleAnims[_animNo];
}
int CPlayerStateUnarmedIdle::getNumIdleAnims()
{
return s_numUnarmedIdleAnims;
}
/*----------------------------------------------------------------------
Function:
Purpose:
Params:
Returns:
---------------------------------------------------------------------- */
2001-04-10 20:44:12 +02:00
static IdleAnims s_weaponIdleAnims[]=
2001-01-29 23:35:18 +01:00
{
// start frame loop frame end frame loop count
2001-05-09 22:26:11 +02:00
{ -1, ANIM_SPONGEBOB_IDLEBREATH, -1, 160 }, // default
{ -1, ANIM_SPONGEBOB_IDLEBREATH, -1, 160 },
{ -1, ANIM_SPONGEBOB_IDLEBREATH, -1, 80 },
2001-04-10 20:44:12 +02:00
{ -1, ANIM_SPONGEBOB_IDLEWEAPON, -1, 1 },
2001-01-29 23:35:18 +01:00
};
2001-04-10 20:44:12 +02:00
static int s_numWeaponIdleAnims=sizeof(s_weaponIdleAnims)/sizeof(IdleAnims);
IdleAnims *CPlayerStateWeaponIdle::getIdleAnimsDb(int _animNo)
2001-01-29 23:35:18 +01:00
{
ASSERT(_animNo<getNumIdleAnims());
2001-04-10 20:44:12 +02:00
return &s_weaponIdleAnims[_animNo];
2001-01-29 23:35:18 +01:00
}
2001-04-10 20:44:12 +02:00
int CPlayerStateWeaponIdle::getNumIdleAnims()
2001-01-29 23:35:18 +01:00
{
2001-04-10 20:44:12 +02:00
return s_numWeaponIdleAnims;
2001-01-29 23:35:18 +01:00
}
2001-01-24 16:52:31 +01:00
/*===========================================================================
end */