SBSPSS/source/player/player.cpp

540 lines
10 KiB
C++
Raw Normal View History

2001-01-16 20:27:14 +01:00
/*=========================================================================
2001-01-09 21:38:20 +01:00
2001-01-16 20:27:14 +01:00
player.cpp
Author: PKG
Created:
Project: Spongebob
Purpose:
Copyright (c) 2001 Climax Development Ltd
===========================================================================*/
/*----------------------------------------------------------------------
Includes
-------- */
#include "player\player.h"
#ifndef __ANIM_HEADER__
2001-01-12 23:40:39 +01:00
#include "gfx\anim.h"
2001-01-16 20:27:14 +01:00
#endif
2001-01-09 21:38:20 +01:00
2001-01-16 20:27:14 +01:00
#ifndef __PAD_PADS_H__
2001-01-15 23:09:47 +01:00
#include "pad\pads.h"
2001-01-16 20:27:14 +01:00
#endif
2001-01-15 23:09:47 +01:00
2001-01-22 23:58:12 +01:00
#ifndef __GAME_GAMESLOT_H__
#include "game\gameslot.h"
#endif
2001-01-16 20:27:14 +01:00
// to be removed
2001-01-12 23:40:39 +01:00
#include "gfx\tpage.h"
2001-01-16 20:27:14 +01:00
2001-01-12 23:40:39 +01:00
2001-01-16 20:27:14 +01:00
/* Std Lib
------- */
2001-01-15 23:09:47 +01:00
2001-01-16 20:27:14 +01:00
/* Data
---- */
2001-01-25 16:25:46 +01:00
#ifndef __ANIM_PLAYER_ANIM_HEADER__
#include <player_anim.h>
#endif
2001-01-16 20:27:14 +01:00
/*----------------------------------------------------------------------
Tyepdefs && Defines
------------------- */
/*----------------------------------------------------------------------
Structure defintions
-------------------- */
2001-01-15 23:09:47 +01:00
2001-01-16 20:27:14 +01:00
/*----------------------------------------------------------------------
Function Prototypes
------------------- */
/*----------------------------------------------------------------------
Vars
---- */
2001-01-15 23:09:47 +01:00
2001-01-22 23:58:12 +01:00
/*----------------------------------------------------------------------
Function:
Purpose:
Params:
Returns:
---------------------------------------------------------------------- */
2001-01-12 23:40:39 +01:00
void CPlayer::init()
2001-01-09 21:38:20 +01:00
{
2001-01-16 17:20:45 +01:00
CThing::init();
sActor3dHdr *Hdr=m_skel.Load(ACTORS_SPONGEBOB_A3D);
m_skel.Init(Hdr);
TPLoadTex(ACTORS_SPONGEBOB_TEX);
m_skel.setAnimDatabase(CAnimDB::GetPlayerAnimBank());
2001-01-20 00:37:40 +01:00
m_animNo=0;
m_animFrame=0;
2001-01-26 19:20:41 +01:00
m_currentMode=PLAYER_MODE_BASICUNARMED;
2001-01-16 17:20:45 +01:00
setState(STATE_IDLE);
2001-01-20 00:37:40 +01:00
m_moveVel.vx=0;
m_moveVel.vy=0;
2001-01-16 20:27:14 +01:00
setFacing(FACING_RIGHT);
2001-01-20 00:37:40 +01:00
2001-01-22 23:58:12 +01:00
m_lives=CGameSlotManager::getSlotData().m_lives;
m_invincibleFrameCount=INVIBCIBLE_FRAMES__START;
2001-01-22 22:02:59 +01:00
#ifdef __USER_paul__
2001-01-25 23:19:47 +01:00
Pos.vx=23*16;
Pos.vy=23*16;
2001-01-22 22:02:59 +01:00
#else
Pos.vx=10;
Pos.vy=10;
#endif
2001-01-25 16:25:46 +01:00
m_cameraOffsetTarget.vx=0;
m_cameraOffsetTarget.vy=0;
m_cameraOffset.vx=0;
m_cameraOffset.vy=0;
2001-01-29 23:35:18 +01:00
m_lastPadInput=m_padInput=0;
2001-01-09 21:38:20 +01:00
}
2001-01-16 20:27:14 +01:00
/*----------------------------------------------------------------------
Function:
Purpose:
Params:
Returns:
---------------------------------------------------------------------- */
2001-01-12 23:40:39 +01:00
void CPlayer::shutdown()
2001-01-09 21:38:20 +01:00
{
2001-01-16 17:20:45 +01:00
CThing::shutdown();
2001-01-09 21:38:20 +01:00
}
2001-01-16 20:27:14 +01:00
/*----------------------------------------------------------------------
Function:
Purpose:
Params:
Returns:
---------------------------------------------------------------------- */
2001-01-25 23:19:47 +01:00
DVECTOR ofs={-240,-134}; // nearly -256,-128 ;)
2001-01-26 19:20:41 +01:00
int psize=0;
2001-01-29 23:35:18 +01:00
int newmode=-1;
2001-01-15 23:09:47 +01:00
void CPlayer::think(int _frames)
{
2001-01-25 16:25:46 +01:00
int i;
2001-01-16 17:20:45 +01:00
CThing::think(_frames);
2001-01-29 23:35:18 +01:00
if(newmode!=-1)
{
setMode((PLAYER_MODE)newmode);
newmode=-1;
}
2001-01-20 00:37:40 +01:00
#ifndef __USER_paul__
int padInput=PadGetHeld(0);
int move=7*_frames;
if(padInput&PAD_UP) Pos.vy-=move;
if(padInput&PAD_DOWN) Pos.vy+=move;
if(padInput&PAD_LEFT) Pos.vx-=move;
if(padInput&PAD_RIGHT) Pos.vx+=move;
2001-01-25 23:19:47 +01:00
m_invincibleFrameCount=0;
2001-01-20 00:37:40 +01:00
#else
if(_frames>=3)_frames=2;
2001-01-25 16:25:46 +01:00
for(i=0;i<_frames;i++)
2001-01-15 23:09:47 +01:00
{
2001-01-20 00:37:40 +01:00
// Think
2001-01-29 23:35:18 +01:00
updatePadInput();
2001-01-26 19:20:41 +01:00
m_currentStateClass->think(this);
2001-01-25 23:19:47 +01:00
// Horizontal movement
2001-01-22 22:02:59 +01:00
Pos.vx+=m_moveVel.vx>>VELOCITY_SHIFT;
2001-01-25 23:19:47 +01:00
if(Pos.vx<350)
{
2001-01-29 20:23:04 +01:00
if(m_currentState==STATE_RUN)
{
setState(STATE_IDLE);
2001-01-26 19:20:41 +01:00
// setAnimNo(ANIM_PLAYER_ANIM_RUNSTOP);
2001-01-29 20:23:04 +01:00
}
2001-01-25 23:19:47 +01:00
Pos.vx=350;
m_moveVel.vx=0;
}
2001-01-20 00:37:40 +01:00
2001-01-25 23:19:47 +01:00
// Vertical movement
Pos.vy+=m_moveVel.vy>>VELOCITY_SHIFT;
2001-01-25 16:25:46 +01:00
if(isOnSolidGround())
2001-01-20 00:37:40 +01:00
{
2001-01-25 16:25:46 +01:00
if(m_moveVel.vy)
2001-01-22 22:02:59 +01:00
{
2001-01-25 16:25:46 +01:00
// Was falling.. so we've just hit the ground
2001-01-26 19:20:41 +01:00
if(m_currentState==STATE_BUTTFALL)
2001-01-25 16:25:46 +01:00
{
setState(STATE_BUTTLAND);
}
2001-01-26 19:20:41 +01:00
else if(m_currentState==STATE_FALLFAR)
2001-01-25 16:25:46 +01:00
{
setState(STATE_IDLE);
}
else if(m_moveVel.vx)
{
setState(STATE_RUN);
setAnimNo(ANIM_PLAYER_ANIM_RUNJUMPEND);
}
else
{
setState(STATE_IDLE);
setAnimNo(ANIM_PLAYER_ANIM_JUMPEND);
}
m_moveVel.vy=0;
m_fallFrames=0;
2001-01-22 22:02:59 +01:00
}
2001-01-25 16:25:46 +01:00
}
else
{
2001-01-26 19:20:41 +01:00
if(m_currentState!=STATE_JUMP&&m_currentState!=STATE_BUTTBOUNCE)
2001-01-15 23:09:47 +01:00
{
2001-01-25 16:25:46 +01:00
// Fall
const PlayerMetrics *metrics;
metrics=getPlayerMetrics();
m_moveVel.vy+=metrics->m_metric[PM__GRAVITY_VALUE];
if(m_moveVel.vy>=metrics->m_metric[PM__TERMINAL_VELOCITY]<<VELOCITY_SHIFT)
{
m_moveVel.vy=metrics->m_metric[PM__TERMINAL_VELOCITY]<<VELOCITY_SHIFT;
m_fallFrames++;
if(m_fallFrames>metrics->m_metric[PM__MAX_SAFE_FALL_FRAMES])
{
setState(STATE_FALLFAR);
}
}
2001-01-15 23:09:47 +01:00
}
2001-01-20 00:37:40 +01:00
}
2001-01-22 23:58:12 +01:00
2001-01-25 16:25:46 +01:00
// Flashing..
2001-01-22 23:58:12 +01:00
if(m_invincibleFrameCount)
{
m_invincibleFrameCount--;
}
2001-01-15 23:09:47 +01:00
}
2001-01-25 16:25:46 +01:00
2001-01-20 00:37:40 +01:00
#endif
2001-01-25 16:25:46 +01:00
// Move the camera offset
2001-01-25 23:19:47 +01:00
m_cameraOffsetTarget=ofs;
m_cameraOffset=ofs;
/*
2001-01-25 16:25:46 +01:00
for(i=0;i<_frames;i++)
{
int moveDelta;
moveDelta=(m_cameraOffset.vx-m_cameraOffsetTarget.vx);
if(moveDelta)
{
if(moveDelta<0)
{
moveDelta>>=2;
if(moveDelta==0)moveDelta=1;
}
else if(moveDelta>0)
{
moveDelta>>=2;
if(moveDelta==0)moveDelta=-1;
}
m_cameraOffset.vx+=moveDelta;
}
}
2001-01-25 23:19:47 +01:00
*/
2001-01-15 23:09:47 +01:00
if(Pos.vx<0)Pos.vx=0;
2001-01-22 16:03:14 +01:00
if(Pos.vy<0)Pos.vy=0;
2001-01-15 23:09:47 +01:00
}
2001-01-16 20:27:14 +01:00
/*----------------------------------------------------------------------
Function:
Purpose:
Params:
Returns:
---------------------------------------------------------------------- */
2001-01-20 00:37:40 +01:00
int panim=-1;
2001-01-25 16:25:46 +01:00
SVECTOR ppos={0,1024,5000};
2001-01-15 23:09:47 +01:00
void CPlayer::render()
{
2001-01-16 17:20:45 +01:00
CThing::render();
2001-01-15 23:09:47 +01:00
// Render
2001-01-25 16:25:46 +01:00
if(m_invincibleFrameCount==0||m_invincibleFrameCount&2)
2001-01-22 23:58:12 +01:00
{
2001-01-25 16:25:46 +01:00
m_skel.setPos(&ppos);
2001-01-22 23:58:12 +01:00
if(panim!=-1)
m_skel.setAnimNo(panim);
else
m_skel.setAnimNo(m_animNo);
2001-01-30 00:01:20 +01:00
m_skel.setFrame(m_animFrame);
2001-01-22 23:58:12 +01:00
m_skel.Animate(this);
m_skel.Render(this);
}
2001-01-15 23:09:47 +01:00
}
2001-01-20 00:37:40 +01:00
2001-01-25 16:25:46 +01:00
/*----------------------------------------------------------------------
Function:
Purpose:
Params:
Returns:
---------------------------------------------------------------------- */
DVECTOR CPlayer::getCameraPos()
{
DVECTOR cameraPos;
2001-01-25 23:19:47 +01:00
cameraPos.vx=Pos.vx+m_cameraOffset.vx;
cameraPos.vy=Pos.vy+m_cameraOffset.vy;
2001-01-25 16:25:46 +01:00
return cameraPos;
}
2001-01-20 00:37:40 +01:00
2001-01-16 20:27:14 +01:00
/*----------------------------------------------------------------------
Function:
Purpose:
Params:
Returns:
---------------------------------------------------------------------- */
2001-01-22 23:58:12 +01:00
const PlayerMetrics *CPlayer::getPlayerMetrics()
2001-01-15 23:09:47 +01:00
{
2001-01-26 19:20:41 +01:00
return &s_modes[m_currentMode].m_metrics;
2001-01-15 23:09:47 +01:00
}
2001-01-20 00:37:40 +01:00
2001-01-16 20:27:14 +01:00
/*----------------------------------------------------------------------
Function:
Purpose:
Params:
Returns:
---------------------------------------------------------------------- */
2001-01-20 00:37:40 +01:00
void CPlayer::setState(PLAYER_STATE _state)
{
2001-01-26 19:20:41 +01:00
CPlayerState *nextState;
nextState=s_modes[m_currentMode].m_states[_state];
if(nextState)
{
m_currentStateClass=nextState;
m_currentStateClass->enter(this);
m_currentState=_state;
}
}
/*----------------------------------------------------------------------
Function:
Purpose:
Params:
Returns:
---------------------------------------------------------------------- */
void CPlayer::setMode(PLAYER_MODE _mode)
{
m_currentMode=_mode;
setState(m_currentState);
2001-01-16 20:27:14 +01:00
}
2001-01-15 23:09:47 +01:00
2001-01-20 00:37:40 +01:00
2001-01-16 20:27:14 +01:00
/*----------------------------------------------------------------------
Function:
Purpose:
Params:
Returns:
---------------------------------------------------------------------- */
2001-01-20 00:37:40 +01:00
int CPlayer::getFacing()
{
return m_facing;
}
void CPlayer::setFacing(int _facing)
2001-01-15 23:09:47 +01:00
{
2001-01-20 00:37:40 +01:00
if(m_facing!=_facing)
2001-01-15 23:09:47 +01:00
{
2001-01-20 00:37:40 +01:00
switch(_facing)
{
case FACING_LEFT:
m_facing=FACING_LEFT;
2001-01-25 23:19:47 +01:00
m_skel.setAng(512);//1024);
2001-01-20 00:37:40 +01:00
break;
case FACING_RIGHT:
m_facing=FACING_RIGHT;
2001-01-25 23:19:47 +01:00
m_skel.setAng(3096+512);//-1024);
2001-01-20 00:37:40 +01:00
break;
default:
ASSERT(0);
break;
}
2001-01-15 23:09:47 +01:00
}
2001-01-12 23:40:39 +01:00
}
2001-01-20 00:37:40 +01:00
int CPlayer::getAnimFrame()
{
return m_animFrame;
}
void CPlayer::setAnimFrame(int _animFrame)
{
m_animFrame=_animFrame;
}
int CPlayer::getAnimFrameCount()
{
return m_skel.getFrameCount();
}
int CPlayer::getAnimNo()
{
return m_animNo;
}
void CPlayer::setAnimNo(int _animNo)
{
m_animNo=_animNo;
m_animFrame=0;
}
DVECTOR CPlayer::getMoveVelocity()
{
return m_moveVel;
}
void CPlayer::setMoveVelocity(DVECTOR *_moveVel)
{
m_moveVel=*_moveVel;
}
2001-01-26 19:20:41 +01:00
DVECTOR CPlayer::getPlayerPos()
{
return Pos;
}
2001-01-29 23:35:18 +01:00
int CPlayer::getPadInputHeld()
2001-01-20 00:37:40 +01:00
{
2001-01-29 23:35:18 +01:00
return m_padInput;
}
int CPlayer::getPadInputDown()
{
return m_padInputDown;
2001-01-20 00:37:40 +01:00
}
2001-01-15 23:09:47 +01:00
2001-01-16 20:27:14 +01:00
/*----------------------------------------------------------------------
Function:
Purpose:
Params:
Returns:
---------------------------------------------------------------------- */
2001-01-20 00:37:40 +01:00
int CPlayer::isOnSolidGround()
2001-01-16 20:27:14 +01:00
{
2001-01-25 23:19:47 +01:00
return Pos.vy>23*16;//16*15;
2001-01-20 00:37:40 +01:00
}
2001-01-25 23:19:47 +01:00
/*----------------------------------------------------------------------
Function:
Purpose:
Params:
Returns:
---------------------------------------------------------------------- */
2001-01-20 00:37:40 +01:00
void CPlayer::moveLeft()
{
2001-01-22 23:58:12 +01:00
const PlayerMetrics *metrics;
2001-01-22 22:02:59 +01:00
metrics=getPlayerMetrics();
2001-01-20 00:37:40 +01:00
setFacing(FACING_LEFT);
if(m_moveVel.vx<=0)
{
2001-01-22 22:02:59 +01:00
m_moveVel.vx-=metrics->m_metric[PM__RUN_SPEEDUP];
if(m_moveVel.vx<-metrics->m_metric[PM__MAX_RUN_VELOCITY]<<VELOCITY_SHIFT)
2001-01-20 00:37:40 +01:00
{
2001-01-22 22:02:59 +01:00
m_moveVel.vx=-metrics->m_metric[PM__MAX_RUN_VELOCITY]<<VELOCITY_SHIFT;
2001-01-20 00:37:40 +01:00
}
}
else
{
2001-01-22 22:02:59 +01:00
m_moveVel.vx-=metrics->m_metric[PM__RUN_REVERSESLOWDOWN];
2001-01-20 00:37:40 +01:00
}
2001-01-16 20:27:14 +01:00
}
2001-01-20 00:37:40 +01:00
void CPlayer::moveRight()
{
2001-01-22 23:58:12 +01:00
const PlayerMetrics *metrics;
2001-01-22 22:02:59 +01:00
metrics=getPlayerMetrics();
2001-01-20 00:37:40 +01:00
setFacing(FACING_RIGHT);
if(m_moveVel.vx>=0)
{
2001-01-22 22:02:59 +01:00
m_moveVel.vx+=metrics->m_metric[PM__RUN_SPEEDUP];
if(m_moveVel.vx>metrics->m_metric[PM__MAX_RUN_VELOCITY]<<VELOCITY_SHIFT)
2001-01-20 00:37:40 +01:00
{
2001-01-22 22:02:59 +01:00
m_moveVel.vx=metrics->m_metric[PM__MAX_RUN_VELOCITY]<<VELOCITY_SHIFT;
2001-01-20 00:37:40 +01:00
}
}
else
{
2001-01-22 22:02:59 +01:00
m_moveVel.vx+=metrics->m_metric[PM__RUN_REVERSESLOWDOWN];
2001-01-20 00:37:40 +01:00
}
}
void CPlayer::slowdown()
{
2001-01-22 23:58:12 +01:00
const PlayerMetrics *metrics;
2001-01-22 22:02:59 +01:00
metrics=getPlayerMetrics();
2001-01-20 00:37:40 +01:00
if(m_moveVel.vx<0)
{
2001-01-22 22:02:59 +01:00
m_moveVel.vx+=metrics->m_metric[PM__RUN_SLOWDOWN];
2001-01-20 00:37:40 +01:00
if(m_moveVel.vx>0)m_moveVel.vx=0;
}
else if(m_moveVel.vx>0)
{
2001-01-22 22:02:59 +01:00
m_moveVel.vx-=metrics->m_metric[PM__RUN_SLOWDOWN];
2001-01-20 00:37:40 +01:00
if(m_moveVel.vx<0)m_moveVel.vx=0;
}
}
void CPlayer::jump()
{
}
void CPlayer::fall()
{
}
2001-01-15 23:09:47 +01:00
2001-01-29 23:35:18 +01:00
/*----------------------------------------------------------------------
Function:
Purpose:
Params:
Returns:
---------------------------------------------------------------------- */
void CPlayer::updatePadInput()
{
m_lastPadInput=m_padInput;
m_padInput=readPadInput();
m_padInputDown=m_padInput&(m_lastPadInput^-1);
}
/*----------------------------------------------------------------------
Function:
Purpose:
Params:
Returns:
---------------------------------------------------------------------- */
int CPlayer::readPadInput()
{
return PadGetHeld(0);
}
2001-01-16 20:27:14 +01:00
/*===========================================================================
end */