SBSPSS/source/player/psidle.cpp

378 lines
9.3 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-06-25 22:25:28 +02:00
CPlayerStateNoAnimIdle s_stateNoAnimIdle;
2001-04-10 20:44:12 +02:00
CPlayerStateWeaponIdle s_stateWeaponIdle;
2001-06-21 21:11:35 +02:00
CPlayerStateNetIdle s_stateNetIdle;
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-07-19 21:25:46 +02:00
_playerMode->slowdown();
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-08-13 18:31:14 +02:00
CPlayer *player = _playerMode->getPlayer();
player->setMoveLeftRight( player->getMoveLeftRight() - 1 );
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-08-13 18:31:14 +02:00
CPlayer *player = _playerMode->getPlayer();
player->setMoveLeftRight( player->getMoveLeftRight() + 1 );
2001-03-23 21:09:14 +01:00
if(_playerMode->canMoveRight())
_playerMode->setState(STATE_RUN);
2001-02-06 18:15:28 +01:00
}
2001-05-23 23:52:38 +02:00
else if(controlHeld&PI_DOWN&&_playerMode->canDoLookAround())
2001-02-06 18:15:28 +01:00
{
2001-05-29 17:54:26 +02:00
_playerMode->setState(STATE_LOOKDOWN);
2001-02-06 18:15:28 +01:00
}
2001-06-19 17:23:50 +02:00
else if(controlHeld&PI_UP&&_playerMode->canDoLookAround())
{
_playerMode->setState(STATE_LOOKUP);
}
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-06-25 22:25:28 +02:00
/*----------------------------------------------------------------------
Function:
Purpose:
Params:
Returns:
---------------------------------------------------------------------- */
void CPlayerStateNoAnimIdle::enter(CPlayerModeBase *_playerMode)
{
_playerMode->setAnimNo(ANIM_SPONGEBOB_IDLEBREATH);
}
/*----------------------------------------------------------------------
Function:
Purpose:
Params:
Returns:
---------------------------------------------------------------------- */
void CPlayerStateNoAnimIdle::think(CPlayerModeBase *_playerMode)
{
2001-06-28 15:46:43 +02:00
if(_playerMode->advanceAnimFrameAndCheckForEndOfAnim())
{
_playerMode->setAnimNo(ANIM_SPONGEBOB_IDLEBREATH);
}
2001-06-25 22:25:28 +02:00
thinkControl(_playerMode);
}
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;
2001-07-27 18:54:28 +02:00
if(m_idleTime<2)
2001-01-25 18:43:10 +01:00
{
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-07-27 18:54:28 +02:00
m_currentIdleAnim=getRndRange(getNumIdleAnims()-1)+1;
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[]=
{
2001-06-11 21:46:09 +02:00
// start frame loop frame end frame loop count
2001-08-14 20:57:15 +02:00
{ -1, ANIM_SPONGEBOB_IDLEBREATH, ANIM_SPONGEBOB_IDLEBLINK, 4*60 }, // default
{ -1, ANIM_SPONGEBOB_IDLEBREATH, ANIM_SPONGEBOB_IDLEBLINK, 5*60 },
{ -1, ANIM_SPONGEBOB_IDLEBREATH, ANIM_SPONGEBOB_IDLEBLINK, 2*60 },
2001-07-27 16:43:39 +02:00
{ -1, ANIM_SPONGEBOB_IDLEFACEUPSIDEDOWN, -1, 1 },
{ -1, ANIM_SPONGEBOB_IDLEBANDAID, -1, 1 },
{ -1, ANIM_SPONGEBOB_IDLEMATURE, -1, 1 },
{ -1, ANIM_SPONGEBOB_IDLEMOUSTACHE, -1, 1 },
{ -1, ANIM_SPONGEBOB_IDLENOFACE, -1, 1 },
{ -1, ANIM_SPONGEBOB_IDLEZORRO, -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:
---------------------------------------------------------------------- */
2001-04-10 20:44:12 +02:00
static IdleAnims s_weaponIdleAnims[]=
2001-01-29 23:35:18 +01:00
{
2001-06-11 21:46:09 +02:00
// start frame loop frame end frame loop count
2001-08-14 20:57:15 +02:00
{ -1, ANIM_SPONGEBOB_IDLEBREATH, ANIM_SPONGEBOB_IDLEBLINK, 4*60 }, // default
{ -1, ANIM_SPONGEBOB_IDLEBREATH, ANIM_SPONGEBOB_IDLEBLINK, 5*60 },
{ -1, ANIM_SPONGEBOB_IDLEBREATH, ANIM_SPONGEBOB_IDLEBLINK, 2*60 },
2001-06-11 21:46:09 +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-06-21 21:11:35 +02:00
/*----------------------------------------------------------------------
Function:
Purpose:
Params:
Returns:
---------------------------------------------------------------------- */
static IdleAnims s_netIdleAnims[]=
{
// start frame loop frame end frame loop count
2001-08-14 20:57:15 +02:00
{ -1, ANIM_SPONGEBOB_IDLEBREATH, ANIM_SPONGEBOB_IDLEBLINK, 4*60 }, // default
{ -1, ANIM_SPONGEBOB_IDLEBREATH, ANIM_SPONGEBOB_IDLEBLINK, 5*60 },
{ -1, ANIM_SPONGEBOB_IDLEBREATH, ANIM_SPONGEBOB_IDLEBLINK, 2*60 },
2001-06-21 21:11:35 +02:00
{ -1, ANIM_SPONGEBOB_IDLEWEAPON, -1, 1 },
};
static int s_numNetIdleAnims=sizeof(s_netIdleAnims)/sizeof(IdleAnims);
IdleAnims *CPlayerStateNetIdle::getIdleAnimsDb(int _animNo)
{
ASSERT(_animNo<getNumIdleAnims());
return &s_netIdleAnims[_animNo];
}
int CPlayerStateNetIdle::getNumIdleAnims()
{
return s_numNetIdleAnims;
}
2001-01-24 16:52:31 +01:00
/*===========================================================================
end */