SBSPSS/source/player/pstates.cpp
2001-01-19 22:54:48 +00:00

136 lines
2.5 KiB
C++

#include "player\pstates.h"
#ifndef __PLAYER_PLAYER_H__
#include "player\player.h"
#endif
#ifndef __UTILS_HEADER__
#include "utils\utils.h"
#endif
#ifndef __PAD_PADS_H__
#include "pad\pads.h"
#endif
#ifndef __ANIM_PLAYER_ANIM_HEADER__
#include <player_anim.h>
#endif
/*----------------------------------------------------------------------*/
void CPlayerState::setState(CPlayer *_player,int _state)
{
_player->setState((PLAYER_STATE)_state);
}
int CPlayerState::getFacing(CPlayer *_player)
{
return _player->getFacing();
}
void CPlayerState::setFacing(CPlayer *_player,int _facing)
{
_player->setFacing(_facing);
}
int CPlayerState::getAnimNo(CPlayer *_player)
{
return _player->getAnimNo();
}
void CPlayerState::setAnimNo(CPlayer *_player,int _animNo)
{
_player->setAnimNo(_animNo);
}
void CPlayerState::setAnimFrame(CPlayer *_player,int _animFrame)
{
_player->setAnimFrame(_animFrame);
}
int CPlayerState::advanceAnimFrameAndCheckForEndOfAnim(class CPlayer *_player)
{
int animFrame,frameCount;
int looped;
animFrame=_player->getAnimFrame()+1;
frameCount=_player->getAnimFrameCount();
looped=false;
if(animFrame>=frameCount)
{
looped=true;
animFrame=0;
}
_player->setAnimFrame(animFrame);
return looped;
}
DVECTOR CPlayerState::getMoveVelocity(CPlayer *_player)
{
return _player->getMoveVelocity();
}
void CPlayerState::setMoveVelocity(CPlayer *_player,DVECTOR *_moveVel)
{
_player->setMoveVelocity(_moveVel);
}
int CPlayerState::getPadInput(CPlayer *_player)
{
return _player->getPadInput();
}
int CPlayerState::isOnSolidGround(CPlayer *_player)
{
return _player->isOnSolidGround();
}
void CPlayerState::moveLeft(CPlayer *_player)
{
_player->moveLeft();
}
void CPlayerState::moveRight(CPlayer *_player)
{
_player->moveRight();
}
void CPlayerState::slowdown(CPlayer *_player)
{
_player->slowdown();
}
void CPlayerState::jump(CPlayer *_player)
{
_player->jump();
}
void CPlayerState::fall(CPlayer *_player)
{
_player->fall();
}
/*----------------------------------------------------------------------*/
void CPlayerStateIdle::enter(CPlayer *_player)
{
setAnimNo(_player,ANIM_PLAYER_ANIM_IDLEGENERIC04);
}
void CPlayerStateIdle::think(CPlayer *_player)
{
int control;
control=getPadInput(_player);
if(control&PAD_CROSS)
{
setState(_player,STATE_JUMP);
}
else if(control&(PAD_LEFT|PAD_RIGHT))
{
setState(_player,STATE_RUN);
}
else if(advanceAnimFrameAndCheckForEndOfAnim(_player))
{
if(getRndRange(100)<95)
setAnimNo(_player,ANIM_PLAYER_ANIM_IDLEGENERIC04);
else
setAnimNo(_player,ANIM_PLAYER_ANIM_IDLEGENERIC03);
}
}