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"
|
|
|
|
|
|
|
|
#ifndef __PLAYER_PLAYER_H__
|
|
|
|
#include "player\player.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef __PAD_PADS_H__
|
|
|
|
#include "pad\pads.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef __UTILS_HEADER__
|
|
|
|
#include "utils\utils.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
/* Std Lib
|
|
|
|
------- */
|
|
|
|
|
|
|
|
/* Data
|
|
|
|
---- */
|
|
|
|
|
|
|
|
#ifndef __ANIM_PLAYER_ANIM_HEADER__
|
|
|
|
#include <player_anim.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
/*----------------------------------------------------------------------
|
|
|
|
Tyepdefs && Defines
|
|
|
|
------------------- */
|
|
|
|
|
|
|
|
/*----------------------------------------------------------------------
|
|
|
|
Structure defintions
|
|
|
|
-------------------- */
|
|
|
|
|
|
|
|
/*----------------------------------------------------------------------
|
|
|
|
Function Prototypes
|
|
|
|
------------------- */
|
|
|
|
|
|
|
|
/*----------------------------------------------------------------------
|
|
|
|
Vars
|
|
|
|
---- */
|
|
|
|
|
|
|
|
/*----------------------------------------------------------------------
|
|
|
|
Function:
|
|
|
|
Purpose:
|
|
|
|
Params:
|
|
|
|
Returns:
|
|
|
|
---------------------------------------------------------------------- */
|
|
|
|
void CPlayerStateIdle::enter(CPlayer *_player)
|
|
|
|
{
|
2001-01-25 18:43:10 +01:00
|
|
|
m_idleTime=0;
|
|
|
|
m_currentIdleAnim=0;
|
|
|
|
m_animState=ANIMSTATE_END;
|
|
|
|
|
|
|
|
setNextIdleAnim(_player);
|
2001-01-24 16:52:31 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*----------------------------------------------------------------------
|
|
|
|
Function:
|
|
|
|
Purpose:
|
|
|
|
Params:
|
|
|
|
Returns:
|
|
|
|
---------------------------------------------------------------------- */
|
|
|
|
void CPlayerStateIdle::think(CPlayer *_player)
|
|
|
|
{
|
2001-01-29 23:35:18 +01:00
|
|
|
int controlDown,controlHeld;
|
|
|
|
controlDown=getPadInputDown(_player);
|
|
|
|
controlHeld=getPadInputHeld(_player);
|
2001-01-24 16:52:31 +01:00
|
|
|
|
2001-01-29 20:23:04 +01:00
|
|
|
if(advanceAnimFrameAndCheckForEndOfAnim(_player))
|
|
|
|
{
|
|
|
|
setNextIdleAnim(_player);
|
|
|
|
}
|
|
|
|
|
2001-01-29 23:35:18 +01:00
|
|
|
if(controlDown&CPadConfig::getButton(CPadConfig::PAD_CFG_JUMP))
|
2001-01-24 16:52:31 +01:00
|
|
|
{
|
|
|
|
setState(_player,STATE_JUMP);
|
|
|
|
}
|
2001-01-29 23:35:18 +01:00
|
|
|
else if(controlHeld&(CPadConfig::getButton(CPadConfig::PAD_CFG_LEFT)|CPadConfig::getButton(CPadConfig::PAD_CFG_RIGHT)))
|
2001-01-24 16:52:31 +01:00
|
|
|
{
|
|
|
|
setState(_player,STATE_RUN);
|
|
|
|
}
|
2001-01-29 23:35:18 +01:00
|
|
|
else if(controlHeld&CPadConfig::getButton(CPadConfig::PAD_CFG_ACTION))
|
2001-01-24 16:52:31 +01:00
|
|
|
{
|
|
|
|
setState(_player,STATE_ATTACK);
|
|
|
|
}
|
2001-01-29 23:35:18 +01:00
|
|
|
else if(controlHeld&CPadConfig::getButton(CPadConfig::PAD_CFG_DOWN))
|
2001-01-24 16:52:31 +01:00
|
|
|
{
|
|
|
|
setState(_player,STATE_DUCK);
|
|
|
|
}
|
2001-01-25 18:43:10 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*----------------------------------------------------------------------
|
|
|
|
Function:
|
|
|
|
Purpose:
|
|
|
|
Params:
|
|
|
|
Returns:
|
|
|
|
---------------------------------------------------------------------- */
|
|
|
|
void CPlayerStateIdle::setNextIdleAnim(CPlayer *_player)
|
|
|
|
{
|
|
|
|
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;
|
|
|
|
setAnimNo(_player,anims->m_loopFrame);
|
|
|
|
break;
|
|
|
|
case ANIMSTATE_LOOP:
|
|
|
|
if(--m_loopCount<=0)
|
|
|
|
{
|
|
|
|
if(anims->m_endFrame==-1)
|
|
|
|
{
|
|
|
|
finished=true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_animState=ANIMSTATE_END;
|
|
|
|
setAnimNo(_player,anims->m_endFrame);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
setAnimNo(_player,anims->m_loopFrame);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case ANIMSTATE_END:
|
|
|
|
finished=true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(finished)
|
|
|
|
{
|
|
|
|
int animNo;
|
|
|
|
if(m_idleTime<5)
|
|
|
|
{
|
|
|
|
m_currentIdleAnim=0; // First anim in list is the default idle
|
|
|
|
}
|
2001-01-24 16:52:31 +01:00
|
|
|
else
|
2001-01-25 18:43:10 +01:00
|
|
|
{
|
2001-01-29 23:35:18 +01:00
|
|
|
if(getNumIdleAnims()>1)
|
2001-01-25 18:43:10 +01:00
|
|
|
{
|
|
|
|
// Randomly choose the next anim to run
|
|
|
|
int lastAnim;
|
|
|
|
lastAnim=m_currentIdleAnim;
|
|
|
|
do
|
|
|
|
{
|
2001-01-29 23:35:18 +01:00
|
|
|
m_currentIdleAnim=getRndRange(getNumIdleAnims());
|
2001-01-25 18:43:10 +01:00
|
|
|
}while(m_currentIdleAnim==lastAnim);
|
|
|
|
}
|
|
|
|
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;
|
|
|
|
setAnimNo(_player,animNo);
|
|
|
|
|
|
|
|
m_idleTime++;
|
2001-01-24 16:52:31 +01:00
|
|
|
}
|
2001-01-25 18:43:10 +01:00
|
|
|
|
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-01-30 18:50:17 +01:00
|
|
|
{ -1, ANIM_PLAYER_ANIM_IDLEBREATHE, -1, 4 },
|
|
|
|
{ -1, ANIM_PLAYER_ANIM_IDLEBREATHE, -1, 10 },
|
2001-01-31 17:34:42 +01:00
|
|
|
{ ANIM_PLAYER_ANIM_RUNSTART, ANIM_PLAYER_ANIM_IDLEHOOLA, ANIM_PLAYER_ANIM_RUNSTOP, 3 },
|
|
|
|
{ ANIM_PLAYER_ANIM_RUNSTART, ANIM_PLAYER_ANIM_IDLEWIGGLEARM, ANIM_PLAYER_ANIM_RUNSTOP, 3 },
|
|
|
|
{ -1, ANIM_PLAYER_ANIM_IDLELOOK, -1, 1 },
|
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:
|
|
|
|
---------------------------------------------------------------------- */
|
|
|
|
static IdleAnims s_coralBlowerIdleAnims[]=
|
|
|
|
{
|
|
|
|
// start frame loop frame end frame loop count
|
2001-01-31 17:34:42 +01:00
|
|
|
{ -1, ANIM_PLAYER_ANIM_IDLEBREATHE, -1, 4 },
|
|
|
|
{ -1, ANIM_PLAYER_ANIM_IDLEBREATHE, -1, 10 },
|
|
|
|
{ -1, ANIM_PLAYER_ANIM_IDLELOOK, -1, 1 },
|
2001-01-29 23:35:18 +01:00
|
|
|
};
|
|
|
|
static int s_numCoralBlowerIdleAnims=sizeof(s_coralBlowerIdleAnims)/sizeof(IdleAnims);
|
|
|
|
IdleAnims *CPlayerStateCoralBlowerIdle::getIdleAnimsDb(int _animNo)
|
|
|
|
{
|
|
|
|
ASSERT(_animNo<getNumIdleAnims());
|
|
|
|
return &s_coralBlowerIdleAnims[_animNo];
|
|
|
|
}
|
|
|
|
int CPlayerStateCoralBlowerIdle::getNumIdleAnims()
|
|
|
|
{
|
|
|
|
return s_numCoralBlowerIdleAnims;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-01-24 16:52:31 +01:00
|
|
|
/*===========================================================================
|
|
|
|
end */
|