SBSPSS/source/player/pmodes.cpp

824 lines
20 KiB
C++
Raw Normal View History

2001-03-23 20:44:14 +01:00
/*=========================================================================
pmodes.cpp
Author: PKG
Created:
Project: Spongebob
Purpose:
Copyright (c) 2001 Climax Development Ltd
===========================================================================*/
/*----------------------------------------------------------------------
Includes
-------- */
#include "player\pmodes.h"
#ifndef __PLAYER_PLAYER_H__
#include "player\player.h"
#endif
#ifndef __PLAYER_PSTATES_H__
#include "player\pstates.h"
#endif
#ifndef __LAYER_COLLISION_H__
#include "level\layercollision.h"
#endif
2001-07-31 21:37:07 +02:00
#ifndef __PAD_VIBE_H__
#include "pad\vibe.h"
#endif
2001-03-23 20:44:14 +01:00
// States
2001-05-29 17:54:26 +02:00
#ifndef __PLAYER__PSLOOK_H__
#include "player\pslook.h"
2001-05-14 18:43:48 +02:00
#endif
2001-03-23 20:44:14 +01:00
#ifndef __PLAYER__PSJUMP_H__
#include "player\psjump.h"
#endif
2001-05-11 21:49:41 +02:00
#ifndef __PLAYER__PSJMPBCK_H__
#include "player\psjmpbck.h"
#endif
2001-03-23 20:44:14 +01:00
#ifndef __PLAYER__PSRUN_H__
#include "player\psrun.h"
#endif
#ifndef __PLAYER__PSFALL_H__
#include "player\psfall.h"
#endif
2001-04-04 17:40:38 +02:00
#ifndef __PLAYER__PSHITGND_H__
#include "player\pshitgnd.h"
#endif
2001-03-23 20:44:14 +01:00
#ifndef __PLAYER__PSIDLE_H__
#include "player\psidle.h"
#endif
#ifndef __PLAYER__PSBUTT_H__
#include "player\psbutt.h"
#endif
#ifndef __PLAYER__PSDUCK_H__
#include "player\psduck.h"
#endif
2001-05-01 20:39:41 +02:00
#ifndef __PLAYER__PSSPRING_H__
#include "player\psspring.h"
#endif
2001-06-12 18:28:39 +02:00
#ifndef __PLAYER_PSCART_H__
#include "player\pscart.h"
#endif
2001-07-03 22:49:30 +02:00
#ifndef __PLAYER_PSSWAL_H__
#include "player\psswal.h"
#endif
2001-06-15 23:24:14 +02:00
#ifndef __PLAYER_PSFLOAT_H__
#include "player\psfloat.h"
#endif
2001-06-12 01:12:58 +02:00
#ifndef __PLATFORM_PLATFORM_H__
#include "platform\platform.h"
#endif
2001-07-03 00:57:52 +02:00
#ifndef __PLAYER_PSDANCE_H__
#include "player\psdance.h"
#endif
#ifndef __GAME_GAME_H__
#include "game/game.h"
#endif
2001-07-12 23:20:06 +02:00
#ifndef __FX_FX_H__
#include "fx\fx.h"
#endif
2001-07-03 00:57:52 +02:00
2001-03-23 20:44:14 +01:00
/* Std Lib
------- */
/* Data
---- */
#ifndef __ANIM_SPONGEBOB_HEADER__
#include <ACTOR_SPONGEBOB_ANIM.h>
#endif
/*----------------------------------------------------------------------
Tyepdefs && Defines
------------------- */
/*----------------------------------------------------------------------
Structure defintions
-------------------- */
/*----------------------------------------------------------------------
Function Prototypes
------------------- */
/*----------------------------------------------------------------------
Vars
---- */
2001-04-03 18:47:07 +02:00
static CPlayerState *s_stateTable[]=
2001-03-23 20:44:14 +01:00
{
2001-04-03 18:47:07 +02:00
&s_stateUnarmedIdle, // STATE_IDLE
&s_stateTeeterIdle, // STATE_IDLETEETER
&s_stateJump, // STATE_JUMP
2001-05-01 20:39:41 +02:00
&s_stateSpring, // STATE_SPRINGUP
2001-04-03 18:47:07 +02:00
&s_stateRun, // STATE_RUN
&s_stateFall, // STATE_FALL
&s_stateFallFar, // STATE_FALLFAR
2001-04-04 17:40:38 +02:00
&s_stateHitGround, // STATE_HITGROUND
2001-04-03 18:47:07 +02:00
&s_stateButtBounce, // STATE_BUTTBOUNCE
&s_stateButtBounceFall, // STATE_BUTTFALL
&s_stateButtBounceLand, // STATE_BUTTLAND
2001-05-11 22:56:43 +02:00
&s_stateButtBounceUp, // STATE_BUTTBOUNCEUP
2001-04-03 18:47:07 +02:00
&s_stateSoakUp, // STATE_SOAKUP
&s_stateGetUp, // STATE_GETUP
2001-05-29 17:54:26 +02:00
&s_stateLookDown, // STATE_LOOKDOWN
&s_stateLookDownRelax, // STATE_LOOKDOWNRELAX
2001-06-19 17:23:50 +02:00
&s_stateLookUp, // STATE_LOOKUP
&s_stateLookUpRelax, // STATE_LOOKUPRELAX
2001-05-11 21:49:41 +02:00
&s_stateJumpBack, // STATE_JUMPBACK
2001-06-12 18:28:39 +02:00
&s_stateCart, // STATE_CART
2001-06-15 23:24:14 +02:00
&s_stateFloat, // STATE_FLOAT
2001-07-03 00:57:52 +02:00
&s_stateDance, // STATE_CELEBRATE
2001-07-03 22:49:30 +02:00
&s_stateSwallow, // STATE_SWALLOW
2001-03-23 20:44:14 +01:00
};
2001-04-03 18:47:07 +02:00
static PlayerMetrics s_playerMetrics=
2001-03-23 20:44:14 +01:00
{ {
DEFAULT_PLAYER_JUMP_VELOCITY, // PM__JUMP_VELOCITY
2001-03-25 22:36:28 +02:00
DEFAULT_PLAYER_MAX_JUMP_FRAMES, // PM__MAX_JUMP_FRAMES
2001-03-23 20:44:14 +01:00
DEFAULT_PLAYER_MAX_SAFE_FALL_FRAMES, // PM__MAX_SAFE_FALL_FRAMES
DEFAULT_PLAYER_MAX_RUN_VELOCITY, // PM__MAX_RUN_VELOCITY
2001-03-25 22:36:28 +02:00
DEFAULT_PLAYER_RUN_SPEEDUP, // PM__RUN_SPEEDUP
DEFAULT_PLAYER_RUN_REVERSESLOWDOWN, // PM__RUN_REVERSESLOWDOWN
2001-03-23 20:44:14 +01:00
DEFAULT_PLAYER_RUN_SLOWDOWN, // PM__RUN_SLOWDOWN
2001-03-25 22:36:28 +02:00
DEFAULT_PLAYER_PLAYER_GRAVITY, // PM__GRAVITY
DEFAULT_PLAYER_TERMINAL_VELOCITY, // PM__TERMINAL_VELOCITY
2001-04-11 17:48:16 +02:00
DEFAULT_BUTT_FALL_VELOCITY, // PM__BUTT_FALL_VELOCITY
2001-05-11 21:49:41 +02:00
DEFAULT_HITREACT_XVELOCITY, // PM__HITREACT_XVELOCITY
DEFAULT_HITREACT_YVELOCITY, // PM__HITREACT_YVELOCITY
DEFAULT_HITREACT_FRAMES, // PM__HITREACT_FRAMES
2001-03-23 20:44:14 +01:00
} };
2001-07-20 04:00:57 +02:00
2001-07-30 02:35:24 +02:00
int checkx=8;
2001-07-20 18:34:24 +02:00
int checky=15;
2001-07-20 22:56:30 +02:00
int checkycanmove=16;
2001-07-20 04:00:57 +02:00
int checkdist=16;
2001-03-23 20:44:14 +01:00
/*----------------------------------------------------------------------
Function:
Purpose:
Params:
Returns:
---------------------------------------------------------------------- */
int CPlayerMode::getPadInputHeld() {return m_player->getPadInputHeld();}
int CPlayerMode::getPadInputDown() {return m_player->getPadInputDown();}
2001-03-27 22:29:02 +02:00
2001-07-03 00:57:52 +02:00
/*----------------------------------------------------------------------
Function:
Purpose:
Params:
Returns:
---------------------------------------------------------------------- */
2001-07-30 17:28:39 +02:00
extern int checkx;
2001-07-03 00:57:52 +02:00
int CPlayerMode::getHeightFromGound()
{
2001-07-30 17:28:39 +02:00
int height[2];
2001-07-23 21:26:37 +02:00
DVECTOR const &pos=getPlayerPos();
2001-07-30 17:28:39 +02:00
height[0]=m_player->getHeightFromGround(pos.vx-checkx,pos.vy);
height[1]=m_player->getHeightFromGround(pos.vx+checkx,pos.vy);
return height[0]<height[1]?height[0]:height[1];
2001-07-03 00:57:52 +02:00
}
2001-05-04 01:45:28 +02:00
/*----------------------------------------------------------------------
Function:
Purpose:
Params:
Returns:
---------------------------------------------------------------------- */
void CPlayerMode::inSoakUpState() {m_player->inSoakUpState();}
2001-03-27 22:29:02 +02:00
/*----------------------------------------------------------------------
Function:
Purpose:
Params:
Returns:
---------------------------------------------------------------------- */
2001-07-23 21:26:37 +02:00
DVECTOR const &CPlayerMode::getPlayerPos() {return m_player->getPlayerPos();}
2001-03-25 22:36:28 +02:00
void CPlayerMode::setPlayerPos(DVECTOR *_pos) {m_player->setPlayerPos(_pos);}
2001-03-23 20:44:14 +01:00
2001-03-25 23:33:20 +02:00
/*----------------------------------------------------------------------
Function:
Purpose:
Params:
Returns:
---------------------------------------------------------------------- */
void CPlayerMode::respawn() {m_player->respawn();}
2001-03-23 20:44:14 +01:00
/*----------------------------------------------------------------------
Function:
Purpose:
Params:
Returns:
---------------------------------------------------------------------- */
2001-03-25 22:36:28 +02:00
void CPlayerModeBase::enter()
2001-03-23 20:44:14 +01:00
{
m_fallFrames=0;
}
/*----------------------------------------------------------------------
Function:
Purpose:
Params:
Returns:
---------------------------------------------------------------------- */
2001-03-25 22:36:28 +02:00
void CPlayerModeBase::think()
2001-03-23 20:44:14 +01:00
{
2001-04-03 18:47:07 +02:00
getStateTable()[m_currentState]->think(this);
2001-03-23 20:44:14 +01:00
thinkVerticalMovement();
2001-06-12 18:28:39 +02:00
thinkHorizontalMovement();
2001-03-23 20:44:14 +01:00
// Teeter if on an edge
if(canTeeter()&&isOnEdge())
{
setState(STATE_IDLETEETER);
}
}
/*----------------------------------------------------------------------
Function:
Purpose:
Params:
Returns:
---------------------------------------------------------------------- */
2001-04-18 18:35:26 +02:00
int CPlayerModeBase::canDoLookAround()
2001-03-23 20:44:14 +01:00
{
2001-04-18 18:35:26 +02:00
int ret=false;
switch(getState())
{
case STATE_IDLE:
case STATE_IDLETEETER:
case STATE_SOAKUP:
2001-05-29 17:54:26 +02:00
case STATE_LOOKDOWN:
2001-06-19 17:23:50 +02:00
case STATE_LOOKUP:
2001-04-18 18:35:26 +02:00
ret=true;
break;
case STATE_JUMP:
2001-05-01 20:39:41 +02:00
case STATE_SPRINGUP:
2001-04-18 18:35:26 +02:00
case STATE_RUN:
case STATE_FALL:
case STATE_FALLFAR:
case STATE_HITGROUND:
case STATE_BUTTBOUNCE:
case STATE_BUTTFALL:
case STATE_BUTTLAND:
2001-05-11 22:56:43 +02:00
case STATE_BUTTBOUNCEUP:
2001-04-18 18:35:26 +02:00
case STATE_GETUP:
2001-05-29 17:54:26 +02:00
case STATE_LOOKDOWNRELAX:
2001-06-19 17:23:50 +02:00
case STATE_LOOKUPRELAX:
2001-05-11 21:49:41 +02:00
case STATE_JUMPBACK:
2001-04-18 18:35:26 +02:00
break;
}
return ret;
2001-03-23 20:44:14 +01:00
}
2001-03-27 22:29:02 +02:00
/*----------------------------------------------------------------------
Function:
Purpose:
Params:
Returns:
---------------------------------------------------------------------- */
2001-04-12 20:48:33 +02:00
ATTACK_STATE CPlayerModeBase::getAttackState()
2001-03-27 22:29:02 +02:00
{
2001-04-12 20:48:33 +02:00
ATTACK_STATE ret=ATTACK_STATE__NONE;
2001-03-27 22:29:02 +02:00
switch(getState())
{
case STATE_BUTTFALL:
case STATE_BUTTLAND:
2001-05-11 22:56:43 +02:00
case STATE_BUTTBOUNCEUP:
2001-04-12 20:48:33 +02:00
ret=ATTACK_STATE__BUTT_BOUNCE;
2001-03-27 22:29:02 +02:00
break;
case STATE_IDLE:
case STATE_IDLETEETER:
case STATE_JUMP:
2001-05-01 20:39:41 +02:00
case STATE_SPRINGUP:
2001-03-27 22:29:02 +02:00
case STATE_RUN:
case STATE_FALL:
case STATE_FALLFAR:
case STATE_BUTTBOUNCE:
case STATE_SOAKUP:
case STATE_GETUP:
2001-05-29 17:54:26 +02:00
case STATE_LOOKDOWN:
case STATE_LOOKDOWNRELAX:
2001-06-19 17:23:50 +02:00
case STATE_LOOKUP:
case STATE_LOOKUPRELAX:
2001-05-11 21:49:41 +02:00
case STATE_JUMPBACK:
2001-03-27 22:29:02 +02:00
break;
}
return ret;
}
2001-03-23 20:44:14 +01:00
/*----------------------------------------------------------------------
Function:
Purpose:
Params:
Returns:
---------------------------------------------------------------------- */
2001-03-25 22:36:28 +02:00
void CPlayerModeBase::thinkVerticalMovement()
2001-03-23 20:44:14 +01:00
{
2001-05-01 18:26:31 +02:00
if(m_player->moveVertical(m_player->getMoveVelocity()->vy>>VELOCITY_SHIFT))
2001-03-23 20:44:14 +01:00
{
2001-07-03 00:57:52 +02:00
if(m_currentState!=STATE_CELEBRATE)
playerHasHitGround();
2001-07-23 21:26:37 +02:00
DVECTOR const &pos=m_player->getPlayerPos();
2001-05-15 00:08:19 +02:00
if(m_player->getHeightFromGround(pos.vx,pos.vy,5)==0&&
2001-07-12 23:20:06 +02:00
(CGameScene::getCollision()->getCollisionBlock(pos.vx,pos.vy)&COLLISION_TYPE_MASK)==COLLISION_TYPE_FLAG_SOAKUP)
2001-05-15 00:08:19 +02:00
{
2001-07-12 23:20:06 +02:00
// Hit water - Make a splash!
DVECTOR pos;
CSoundMediator::playSfx(CSoundMediator::SFX_SPONGEBOB_SPLASH_INTO_WATER);
pos=getPlayerPos();
pos.vy-=40;
CFX::Create(CFX::FX_TYPE_SPLASH_WATER,pos);
if(!m_player->getIsHelmetSoFullThatIDontNeedToSoakUp())
{
// Not got full water levels - Go into soakup mode
setState(STATE_SOAKUP);
}
2001-05-15 00:08:19 +02:00
}
2001-03-23 20:44:14 +01:00
}
2001-05-11 22:56:43 +02:00
else if(m_currentState!=STATE_FALL&&m_currentState!=STATE_FALLFAR&& // Hmm.. (pkg)
2001-04-25 20:38:33 +02:00
m_currentState!=STATE_BUTTFALL&&m_currentState!=STATE_BUTTBOUNCE&&
2001-05-11 21:49:41 +02:00
m_currentState!=STATE_JUMP&&m_currentState!=STATE_SPRINGUP&&
2001-06-15 23:24:14 +02:00
m_currentState!=STATE_JUMPBACK&&m_currentState!=STATE_BUTTBOUNCEUP&&
2001-07-03 00:57:52 +02:00
m_currentState!=STATE_FLOAT&&m_currentState!=STATE_CELEBRATE)
2001-03-23 20:44:14 +01:00
{
2001-07-23 21:26:37 +02:00
DVECTOR const &pos=m_player->getPlayerPos();
2001-07-30 02:35:24 +02:00
if(m_player->getHeightFromGround(pos.vx,pos.vy,1)!=0&&
2001-07-20 04:00:57 +02:00
m_player->getHeightFromGround(pos.vx-checkx,pos.vy,1)!=0&&
2001-07-20 22:56:30 +02:00
m_player->getHeightFromGround(pos.vx+checkx,pos.vy,1)!=0
)
2001-03-31 00:43:35 +02:00
{
2001-04-25 20:38:33 +02:00
// Was floating in the air.. fall!
setState(STATE_FALL);
2001-03-31 00:43:35 +02:00
}
2001-03-23 20:44:14 +01:00
}
}
/*----------------------------------------------------------------------
Function:
Purpose:
Params:
Returns:
---------------------------------------------------------------------- */
2001-03-25 22:36:28 +02:00
void CPlayerModeBase::thinkHorizontalMovement()
2001-03-23 20:44:14 +01:00
{
2001-05-01 18:26:31 +02:00
DVECTOR moveVel;
moveVel=*m_player->getMoveVelocity();
if(m_player->moveHorizontal(moveVel.vx>>VELOCITY_SHIFT))
2001-03-23 20:44:14 +01:00
{
2001-04-25 20:38:33 +02:00
// If running then go to idle, otherwise leave in same state
if(m_currentState==STATE_RUN)
2001-03-23 20:44:14 +01:00
{
2001-04-25 20:38:33 +02:00
setState(STATE_IDLE);
2001-03-23 20:44:14 +01:00
}
2001-05-01 18:26:31 +02:00
moveVel.vx=0;
setMoveVelocity(&moveVel);
2001-03-23 20:44:14 +01:00
}
}
2001-04-03 22:26:21 +02:00
/*----------------------------------------------------------------------
Function:
Purpose:
Params:
Returns:
---------------------------------------------------------------------- */
void CPlayerModeBase::playerHasHitGround()
{
2001-05-01 18:26:31 +02:00
DVECTOR moveVel;
moveVel=*m_player->getMoveVelocity();
moveVel.vy=0;
2001-04-03 22:26:21 +02:00
m_fallFrames=0;
2001-08-17 16:25:04 +02:00
m_player->setLockoutPlatform( NULL );
2001-04-03 22:26:21 +02:00
if(m_currentState==STATE_BUTTFALL)
{
// Landed from a butt bounce
setState(STATE_BUTTLAND);
}
else if(m_currentState==STATE_FALLFAR)
{
// Landed from a painfully long fall
2001-07-16 18:07:28 +02:00
// This no longer hurts as per THQs request..
2001-04-04 17:40:38 +02:00
setState(STATE_HITGROUND);
2001-07-16 22:55:33 +02:00
#ifdef __USER_paul__
m_player->takeDamage(DAMAGE__FALL,REACT__NO_REACTION);
2001-07-31 21:37:07 +02:00
#else
CPadVibrationManager::setVibration(0,CPadVibrationManager::VIBE_SHORT);
2001-07-16 22:55:33 +02:00
#endif
2001-07-31 21:37:07 +02:00
2001-05-01 18:26:31 +02:00
moveVel.vx=0;
2001-06-28 22:36:45 +02:00
CGameScene::setCameraShake(0,8);
2001-04-03 22:26:21 +02:00
}
2001-05-01 18:26:31 +02:00
else if(moveVel.vx)
2001-04-03 22:26:21 +02:00
{
// Landed from a jump with x movement
setState(STATE_RUN);
}
else
{
// Landed from a jump with no x movement
setState(STATE_IDLE);
setAnimNo(ANIM_SPONGEBOB_JUMPEND);
}
2001-05-01 18:26:31 +02:00
setMoveVelocity(&moveVel);
2001-04-03 22:26:21 +02:00
}
2001-03-23 20:44:14 +01:00
/*----------------------------------------------------------------------
Function:
Purpose:
Params:
Returns:
---------------------------------------------------------------------- */
2001-03-25 22:36:28 +02:00
const struct PlayerMetrics *CPlayerModeBase::getPlayerMetrics()
2001-03-23 20:44:14 +01:00
{
return &s_playerMetrics;
}
/*----------------------------------------------------------------------
Function:
2001-07-16 18:07:28 +02:00
Purpose: Sets player state.
NB: When you re-enter a state due to changing modes ( ie: when picking up
a weapon ) then strange things can happen :/
2001-03-23 20:44:14 +01:00
Params:
Returns:
---------------------------------------------------------------------- */
2001-03-25 22:36:28 +02:00
int CPlayerModeBase::setState(int _state)
2001-03-23 20:44:14 +01:00
{
int ret=false;
2001-07-16 21:46:48 +02:00
if(m_currentState==STATE_CELEBRATE&&_state!=STATE_IDLE)
2001-03-23 20:44:14 +01:00
{
ret=true;
}
2001-07-16 21:46:48 +02:00
else
{
CPlayerState *nextState;
nextState=getStateTable()[_state];
if(nextState)
{
m_player->resetPlayerCollisionSizeToBase();
m_currentStateClass=nextState;
m_currentStateClass->enter(this);
m_currentState=(PLAYER_STATE)_state;
ret=true;
}
}
2001-03-23 20:44:14 +01:00
return ret;
}
/*----------------------------------------------------------------------
Function:
Purpose:
Params:
Returns:
---------------------------------------------------------------------- */
2001-03-25 22:36:28 +02:00
int CPlayerModeBase::getFacing() {return m_player->getFacing();}
void CPlayerModeBase::setFacing(int _facing) {m_player->setFacing(_facing);}
2001-03-27 22:00:44 +02:00
int CPlayerModeBase::getAnimNo() {return m_player->getAnimNo();}
void CPlayerModeBase::setAnimNo(int _animNo) {m_player->setAnimNo(_animNo);setAnimFrame(0);}
int CPlayerModeBase::getAnimFrame() {return m_player->getAnimFrame();}
int CPlayerModeBase::getAnimFrameCount() {return m_player->getAnimFrameCount();}
2001-03-25 22:36:28 +02:00
void CPlayerModeBase::setAnimFrame(int _animFrame) {m_player->setAnimFrame(_animFrame);}
2001-03-23 20:44:14 +01:00
/*----------------------------------------------------------------------
Function:
Purpose:
Params:
Returns:
---------------------------------------------------------------------- */
2001-03-25 22:36:28 +02:00
int CPlayerModeBase::advanceAnimFrameAndCheckForEndOfAnim()
2001-03-23 20:44:14 +01:00
{
int animFrame,frameCount;
int looped;
2001-03-27 22:00:44 +02:00
animFrame=getAnimFrame()+1;
frameCount=getAnimFrameCount();
2001-03-23 20:44:14 +01:00
looped=false;
if(animFrame>=frameCount)
{
looped=true;
animFrame=0;
}
2001-03-27 22:00:44 +02:00
setAnimFrame(animFrame);
2001-03-23 20:44:14 +01:00
return looped;
}
/*----------------------------------------------------------------------
Function:
Purpose:
Params:
Returns:
---------------------------------------------------------------------- */
2001-05-01 18:26:31 +02:00
DVECTOR CPlayerModeBase::getMoveVelocity() {return *m_player->getMoveVelocity();}
void CPlayerModeBase::zeroMoveVelocity() {DVECTOR v={0,0};setMoveVelocity(&v);}
void CPlayerModeBase::setMoveVelocity(DVECTOR *_moveVel) {m_player->setMoveVelocity(_moveVel);}
2001-03-23 20:44:14 +01:00
/*----------------------------------------------------------------------
Function:
Purpose:
Params:
Returns: FACING_LEFT if left half of player is hanging, FACING_RIGHT
if right half of player is hanging or 0 if no part of the
player is hanging
---------------------------------------------------------------------- */
int csize=5;
int cheight=15;
2001-03-25 22:36:28 +02:00
int CPlayerModeBase::isOnEdge()
2001-03-23 20:44:14 +01:00
{
2001-05-25 20:43:47 +02:00
CLayerCollision *collision=CGameScene::getCollision();
2001-03-23 20:44:14 +01:00
int ret;
2001-07-23 21:26:37 +02:00
DVECTOR const &pos=m_player->getPlayerPos();
2001-03-23 20:44:14 +01:00
ret=0;
2001-03-29 21:19:33 +02:00
if(m_player->getHeightFromGround(pos.vx-csize,pos.vy,cheight+1)>cheight)
2001-03-23 20:44:14 +01:00
{
ret=FACING_LEFT;
}
2001-03-29 21:19:33 +02:00
else if(m_player->getHeightFromGround(pos.vx+csize,pos.vy,cheight+1)>cheight)
2001-03-23 20:44:14 +01:00
{
ret=FACING_RIGHT;
}
return ret;
}
/*----------------------------------------------------------------------
Function:
Purpose:
Params:
Returns:
---------------------------------------------------------------------- */
2001-03-25 22:36:28 +02:00
int CPlayerModeBase::canMoveLeft()
2001-03-23 20:44:14 +01:00
{
2001-07-23 21:26:37 +02:00
DVECTOR const &pos=m_player->getPlayerPos();
2001-07-30 02:35:24 +02:00
return m_player->getHeightFromGround(pos.vx-checkx-1,pos.vy,checkdist)>-checkycanmove?true:false;
2001-07-20 22:56:30 +02:00
2001-03-23 20:44:14 +01:00
}
2001-03-25 22:36:28 +02:00
int CPlayerModeBase::canMoveRight()
2001-03-23 20:44:14 +01:00
{
2001-07-23 21:26:37 +02:00
DVECTOR const &pos=m_player->getPlayerPos();
2001-07-30 02:35:24 +02:00
return m_player->getHeightFromGround(pos.vx+checkx+1,pos.vy,checkdist)>-checkycanmove?true:false;
2001-03-23 20:44:14 +01:00
}
2001-04-18 18:35:26 +02:00
/*----------------------------------------------------------------------
Function:
Purpose:
Params:
Returns:
---------------------------------------------------------------------- */
void CPlayerModeBase::setPlayerCollisionSize(int _x,int _y,int _w,int _h)
{
m_player->setPlayerCollisionSize(_x,_y,_w,_h);
}
2001-05-01 22:23:32 +02:00
void CPlayerModeBase::getPlayerCollisionSize(int *_x,int *_y,int *_w,int *_h)
{
m_player->getPlayerCollisionSize(_x,_y,_w,_h);
}
2001-04-18 18:35:26 +02:00
2001-03-23 20:44:14 +01:00
/*----------------------------------------------------------------------
Function:
Purpose:
Params:
Returns:
---------------------------------------------------------------------- */
2001-03-25 22:36:28 +02:00
void CPlayerModeBase::moveLeft()
2001-03-23 20:44:14 +01:00
{
const PlayerMetrics *metrics;
2001-05-01 18:26:31 +02:00
DVECTOR moveVel;
2001-03-23 20:44:14 +01:00
2001-05-01 18:26:31 +02:00
metrics=getPlayerMetrics();
moveVel=*m_player->getMoveVelocity();
2001-03-23 20:44:14 +01:00
setFacing(FACING_LEFT);
2001-05-01 18:26:31 +02:00
if(moveVel.vx<=0)
2001-03-23 20:44:14 +01:00
{
2001-05-01 18:26:31 +02:00
moveVel.vx-=metrics->m_metric[PM__RUN_SPEEDUP];
if(moveVel.vx<-metrics->m_metric[PM__MAX_RUN_VELOCITY]<<VELOCITY_SHIFT)
2001-03-23 20:44:14 +01:00
{
2001-05-01 18:26:31 +02:00
moveVel.vx=-metrics->m_metric[PM__MAX_RUN_VELOCITY]<<VELOCITY_SHIFT;
2001-03-23 20:44:14 +01:00
}
}
else
{
2001-05-01 18:26:31 +02:00
moveVel.vx-=metrics->m_metric[PM__RUN_REVERSESLOWDOWN];
2001-03-23 20:44:14 +01:00
}
2001-05-01 18:26:31 +02:00
setMoveVelocity(&moveVel);
2001-05-13 21:28:48 +02:00
m_player->moveLeft();
2001-03-23 20:44:14 +01:00
}
2001-03-25 22:36:28 +02:00
void CPlayerModeBase::moveRight()
2001-03-23 20:44:14 +01:00
{
const PlayerMetrics *metrics;
2001-05-01 18:26:31 +02:00
DVECTOR moveVel;
2001-03-23 20:44:14 +01:00
metrics=getPlayerMetrics();
2001-05-01 18:26:31 +02:00
moveVel=*m_player->getMoveVelocity();
2001-03-23 20:44:14 +01:00
setFacing(FACING_RIGHT);
2001-05-01 18:26:31 +02:00
if(moveVel.vx>=0)
2001-03-23 20:44:14 +01:00
{
2001-05-01 18:26:31 +02:00
moveVel.vx+=metrics->m_metric[PM__RUN_SPEEDUP];
if(moveVel.vx>metrics->m_metric[PM__MAX_RUN_VELOCITY]<<VELOCITY_SHIFT)
2001-03-23 20:44:14 +01:00
{
2001-05-01 18:26:31 +02:00
moveVel.vx=metrics->m_metric[PM__MAX_RUN_VELOCITY]<<VELOCITY_SHIFT;
2001-03-23 20:44:14 +01:00
}
}
else
{
2001-05-01 18:26:31 +02:00
moveVel.vx+=metrics->m_metric[PM__RUN_REVERSESLOWDOWN];
2001-03-23 20:44:14 +01:00
}
2001-05-01 18:26:31 +02:00
setMoveVelocity(&moveVel);
2001-05-13 21:28:48 +02:00
m_player->moveRight();
2001-03-23 20:44:14 +01:00
}
2001-03-25 22:36:28 +02:00
int CPlayerModeBase::slowdown()
2001-03-23 20:44:14 +01:00
{
const PlayerMetrics *metrics;
2001-05-01 18:26:31 +02:00
DVECTOR moveVel;
2001-03-23 20:44:14 +01:00
int ret=false;
2001-05-01 18:26:31 +02:00
2001-03-23 20:44:14 +01:00
metrics=getPlayerMetrics();
2001-05-01 18:26:31 +02:00
moveVel=*m_player->getMoveVelocity();
2001-03-23 20:44:14 +01:00
2001-05-01 18:26:31 +02:00
if(moveVel.vx<0)
2001-03-23 20:44:14 +01:00
{
2001-05-01 18:26:31 +02:00
moveVel.vx+=metrics->m_metric[PM__RUN_SLOWDOWN];
if(moveVel.vx>=0)
2001-03-23 20:44:14 +01:00
{
2001-05-01 18:26:31 +02:00
moveVel.vx=0;
2001-03-23 20:44:14 +01:00
ret=true;
}
}
2001-05-01 18:26:31 +02:00
else if(moveVel.vx>0)
2001-03-23 20:44:14 +01:00
{
2001-05-01 18:26:31 +02:00
moveVel.vx-=metrics->m_metric[PM__RUN_SLOWDOWN];
if(moveVel.vx<=0)
2001-03-23 20:44:14 +01:00
{
2001-05-01 18:26:31 +02:00
moveVel.vx=0;
2001-03-23 20:44:14 +01:00
ret=true;
}
}
2001-04-03 22:26:21 +02:00
else
{
// Hmm.. was already stopped(?)
// This should probly be considered a bug.. (pkg)
ret=true;
}
2001-05-01 18:26:31 +02:00
setMoveVelocity(&moveVel);
2001-03-23 20:44:14 +01:00
return ret;
}
2001-03-25 22:36:28 +02:00
void CPlayerModeBase::jump()
2001-03-23 20:44:14 +01:00
{
2001-05-01 18:26:31 +02:00
DVECTOR moveVel;
moveVel=*m_player->getMoveVelocity();
moveVel.vy=-getPlayerMetrics()->m_metric[PM__JUMP_VELOCITY]<<VELOCITY_SHIFT;
setMoveVelocity(&moveVel);
2001-03-23 20:44:14 +01:00
}
2001-06-14 23:22:40 +02:00
int spr=5;
2001-06-10 19:07:06 +02:00
void CPlayerModeBase::spring()
{
DVECTOR moveVel;
moveVel=*m_player->getMoveVelocity();
// moveVel.vy=-getPlayerMetrics()->m_metric[PM__JUMP_VELOCITY]<<VELOCITY_SHIFT;
moveVel.vy-=spr;
if(moveVel.vy<-getPlayerMetrics()->m_metric[PM__JUMP_VELOCITY]<<VELOCITY_SHIFT)
{
moveVel.vy=-getPlayerMetrics()->m_metric[PM__JUMP_VELOCITY]<<VELOCITY_SHIFT;
}
setMoveVelocity(&moveVel);
}
2001-05-11 21:49:41 +02:00
void CPlayerModeBase::jumpback()
{
DVECTOR moveVel;
int xvel;
moveVel=*m_player->getMoveVelocity();
moveVel.vy=-getPlayerMetrics()->m_metric[PM__HITREACT_YVELOCITY]<<VELOCITY_SHIFT;
xvel=getPlayerMetrics()->m_metric[PM__HITREACT_XVELOCITY]<<VELOCITY_SHIFT;
if(moveVel.vx<0)
{
moveVel.vx=-xvel;
}
else if(moveVel.vx>0)
{
moveVel.vx=xvel;
}
setMoveVelocity(&moveVel);
}
2001-03-25 22:36:28 +02:00
void CPlayerModeBase::fall()
2001-03-23 20:44:14 +01:00
{
2001-03-25 22:36:28 +02:00
const PlayerMetrics *metrics;
2001-05-01 18:26:31 +02:00
DVECTOR moveVel;
2001-03-25 22:36:28 +02:00
2001-05-01 18:26:31 +02:00
metrics=getPlayerMetrics();
moveVel=*m_player->getMoveVelocity();
2001-03-25 22:36:28 +02:00
2001-05-01 18:26:31 +02:00
moveVel.vy+=getPlayerMetrics()->m_metric[PM__GRAVITY];
if(moveVel.vy>=metrics->m_metric[PM__TERMINAL_VELOCITY]<<VELOCITY_SHIFT)
2001-03-23 20:44:14 +01:00
{
2001-05-01 18:26:31 +02:00
moveVel.vy=metrics->m_metric[PM__TERMINAL_VELOCITY]<<VELOCITY_SHIFT;
2001-03-23 20:44:14 +01:00
if(!canFallForever()&&m_currentState!=STATE_FALLFAR)
{
const PlayerMetrics *metrics;
metrics=getPlayerMetrics();
m_fallFrames++;
if(m_fallFrames>metrics->m_metric[PM__MAX_SAFE_FALL_FRAMES])
{
setState(STATE_FALLFAR);
}
}
}
2001-05-01 18:26:31 +02:00
setMoveVelocity(&moveVel);
2001-05-24 22:00:19 +02:00
m_player->fall();
2001-03-23 20:44:14 +01:00
}
2001-07-03 00:57:52 +02:00
// whatever..
void CPlayerModeBase::fallToDance()
{
const PlayerMetrics *metrics;
DVECTOR moveVel;
metrics=getPlayerMetrics();
moveVel=*m_player->getMoveVelocity();
moveVel.vy+=getPlayerMetrics()->m_metric[PM__GRAVITY];
if(moveVel.vy>=metrics->m_metric[PM__TERMINAL_VELOCITY]<<VELOCITY_SHIFT)
{
moveVel.vy=metrics->m_metric[PM__TERMINAL_VELOCITY]<<VELOCITY_SHIFT;
}
setMoveVelocity(&moveVel);
m_player->fall();
}
2001-04-28 00:49:54 +02:00
int buttfallspeed=9;
2001-04-11 17:48:16 +02:00
void CPlayerModeBase::buttFall()
{
const PlayerMetrics *metrics;
2001-05-01 18:26:31 +02:00
DVECTOR moveVel;
2001-04-11 17:48:16 +02:00
2001-05-01 18:26:31 +02:00
metrics=getPlayerMetrics();
moveVel=*m_player->getMoveVelocity();
// moveVel.vy=metrics->m_metric[PM__BUTT_FALL_VELOCITY]<<(VELOCITY_SHIFT+1);
moveVel.vy=metrics->m_metric[buttfallspeed]<<VELOCITY_SHIFT;
setMoveVelocity(&moveVel);
2001-05-24 22:00:19 +02:00
m_player->buttFall();
2001-04-11 17:48:16 +02:00
}
2001-03-23 20:44:14 +01:00
2001-04-03 18:47:07 +02:00
/*----------------------------------------------------------------------
Function:
Purpose:
Params:
Returns:
---------------------------------------------------------------------- */
CPlayerState **CPlayerModeBase::getStateTable()
{
return s_stateTable;
}
2001-03-23 20:44:14 +01:00
/*===========================================================================
end */