SBSPSS/source/player/player.cpp

1196 lines
24 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 __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
2001-02-06 18:15:28 +01:00
#ifndef __LAYER_COLLISION_H__
2001-03-23 21:09:14 +01:00
#include "level\layercollision.h"
2001-02-06 18:15:28 +01:00
#endif
2001-03-05 21:43:32 +01:00
#ifndef __PLAYER_PMODES_H__
#include "player\pmodes.h"
#endif
2001-03-30 19:47:00 +02:00
#ifndef __PLAYER_PMBLOON_H__
#include "player\pmbloon.h"
#endif
#ifndef __PLAYER_PMBUBBLE_H__
#include "player\pmbubble.h"
#endif
2001-03-31 20:22:38 +02:00
#ifndef __PLAYER_PMNET_H__
#include "player\pmnet.h"
#endif
2001-03-25 23:33:20 +02:00
#ifndef __PLAYER_PMCHOP_H__
#include "player\pmchop.h"
2001-03-23 21:09:14 +01:00
#endif
2001-03-30 19:47:00 +02:00
#ifndef __PLAYER_PMCORAL_H__
#include "player\pmcoral.h"
2001-03-25 22:36:28 +02:00
#endif
2001-03-25 23:33:20 +02:00
#ifndef __PLAYER_PMDEAD_H__
#include "player\pmdead.h"
#endif
#ifndef __PLAYER_PMFLY_H__
#include "player\pmfly.h"
#endif
2001-04-03 23:36:35 +02:00
#ifndef __PLAYER_PMJELLY_H__
#include "player\pmjelly.h"
#endif
2001-03-31 20:22:38 +02:00
#ifndef __GFX_FONT_H__
#include "gfx\font.h"
#endif
#ifndef __GFX_SPRBANK_H__
#include "gfx\sprbank.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-04-20 16:53:35 +02:00
#ifndef __SPR_SPRITES_H__
#include <sprites.h>
2001-04-05 16:40:50 +02:00
#endif
2001-01-16 20:27:14 +01:00
/*----------------------------------------------------------------------
Tyepdefs && Defines
------------------- */
2001-02-09 18:01:04 +01:00
//#define _RECORD_DEMO_MODE_
2001-02-09 22:41:55 +01:00
#ifdef __USER_paul__
#define _STATE_DEBUG_
#endif
2001-02-09 18:01:04 +01:00
2001-02-14 18:34:11 +01:00
#define SLIPSPEED 10 // Speed that player slips on icy surfaces
2001-01-16 20:27:14 +01:00
/*----------------------------------------------------------------------
Structure defintions
-------------------- */
2001-01-15 23:09:47 +01:00
2001-02-28 20:37:01 +01:00
// Two dice. One says 'Re' on every face, the other says 'boot',
// 'install', 'try', 'tire', 'sume' and 'number'
2001-03-02 17:02:30 +01:00
/*
WEAPON MODES
unamred constant
karate-chop constant
balloon timed ( respawn )
bubble mixture (un)limited supply ( respawn )
helmet constant ( respawn )
coral blower constant ( respawn )
net constant
jelly launcher limited supply ( respawn )
POWER-UPS
glasses constant
squeaky boots timed ( respawn )
mm & bb ring timed
*/
2001-01-16 20:27:14 +01:00
/*----------------------------------------------------------------------
Function Prototypes
------------------- */
/*----------------------------------------------------------------------
Vars
---- */
2001-01-15 23:09:47 +01:00
2001-02-09 18:01:04 +01:00
#ifdef _RECORD_DEMO_MODE_
#include "player\demoplay.h"
#define MAX_DEMO_SIZE 512 // So max size of a demo is 1k
2001-02-12 16:26:00 +01:00
#define MAX_DEMO_TIME_IN_FRAMES 30*60 // Recorded demo will last 30 seconds
2001-02-09 18:01:04 +01:00
static CDemoPlayer::demoPlayerControl s_demoControls[MAX_DEMO_SIZE]={{PI_NONE,0}};
static int s_demoSize=0;
static int s_demoFrameCount=0;
static void writeDemoControls()
{
char filename[32];
int fh;
int fc=MAX_DEMO_TIME_IN_FRAMES;
sprintf(filename,"demo____.dmo");
fh=PCcreat((char *)filename,0);
ASSERT(fh!=-1);
PCwrite(fh,(char*)&fc,sizeof(fc)); // frame count
PCwrite(fh,(char*)&s_demoSize,sizeof(s_demoSize)); // demo size
for(int i=0;i<s_demoSize;i++)
PCwrite(fh,(char*)&s_demoControls[i],sizeof(CDemoPlayer::demoPlayerControl)); // control data
PCclose(fh);
SYSTEM_DBGMSG("Written demo file %s with %d frames",filename,s_demoSize);
}
#endif
2001-02-09 22:41:55 +01:00
#ifdef _STATE_DEBUG_
static const char *s_modeText[NUM_PLAYERMODES]=
{
"BASICUNARMED",
2001-03-25 23:33:20 +02:00
"FULLUNARMED",
2001-03-25 22:36:28 +02:00
"BALLOON",
2001-03-30 19:47:00 +02:00
"BUBBLE MIXTURE",
2001-03-31 20:22:38 +02:00
"NET",
2001-03-30 19:47:00 +02:00
"CORALBLOWER",
2001-04-03 23:36:35 +02:00
"JELLY LAUNCHER",
2001-03-30 19:47:00 +02:00
"DEAD",
2001-03-23 21:09:14 +01:00
"FLY",
2001-02-09 22:41:55 +01:00
};
#endif
2001-02-09 18:01:04 +01:00
2001-04-17 22:45:02 +02:00
int s_screenPos;
int m_cameraLookOffset;
2001-02-08 17:51:16 +01:00
int MAP2D_CENTRE_X=-256;
2001-04-13 00:14:49 +02:00
int MAP2D_CENTRE_Y=-170;
2001-02-08 17:51:16 +01:00
int MAP2D_BLOCKSTEPSIZE=16;
2001-03-30 19:47:00 +02:00
CPlayerModeBase PLAYERMODE;
CPlayerModeChop PLAYERMODECHOP;
CPlayerModeBalloon PLAYERMODEBALLOON;
CPlayerModeBubbleMixture PLAYERMODEBUBBLEMIXTURE;
2001-03-31 20:22:38 +02:00
CPlayerModeNet PLAYERMODENET;
2001-03-30 19:47:00 +02:00
CPlayerModeCoralBlower PLAYERMODECORALBLOWER;
2001-04-03 23:36:35 +02:00
CPlayerModeJellyLauncher PLAYERMODEJELLYLAUNCHER;
2001-03-30 19:47:00 +02:00
CPlayerModeDead PLAYERMODEDEAD;
CPlayerModeFly PLAYERMODEFLY;
2001-03-23 21:09:14 +01:00
CPlayerMode *CPlayer::s_playerModes[NUM_PLAYERMODES]=
{
2001-03-25 22:36:28 +02:00
&PLAYERMODE, // PLAYER_MODE_BASICUNARMED
2001-03-25 23:33:20 +02:00
&PLAYERMODECHOP, // PLAYER_MODE_FULLUNARMED
2001-03-25 22:36:28 +02:00
&PLAYERMODEBALLOON, // PLAYER_MODE_BALLOON
2001-03-30 19:47:00 +02:00
&PLAYERMODEBUBBLEMIXTURE, // PLAYER_MODE_BUBBLE_MIXTURE
2001-03-31 20:22:38 +02:00
&PLAYERMODENET, // PLAYER_MODE_NET
2001-03-30 19:47:00 +02:00
&PLAYERMODECORALBLOWER, // PLAYER_MODE_CORALBLOWER
2001-04-03 23:36:35 +02:00
&PLAYERMODEJELLYLAUNCHER, // PLAYER_MODE_JELLY_LAUNCHER
2001-03-25 23:33:20 +02:00
&PLAYERMODEDEAD, // PLAYER_MODE_DEAD
2001-03-25 22:36:28 +02:00
&PLAYERMODEFLY, // PLAYER_MODE_FLY
2001-03-23 21:09:14 +01:00
};
2001-02-09 18:01:04 +01:00
2001-04-18 18:35:26 +02:00
// A big bunch of 'temporary' variables for tweaking things
// This #def makes them static under a release build..
2001-04-18 18:54:22 +02:00
#ifdef __VERSION_DEBUG__
2001-04-18 18:35:26 +02:00
#define pint int
#else
#define pint static const int
#endif
pint sbanimspeed=0;
pint looktimeout=20;
pint lookmaxoffsetup=3*MAP2D_BLOCKSTEPSIZE;
pint lookmaxoffsetdown=6*MAP2D_BLOCKSTEPSIZE;
pint lookspeed=2;
pint lookreturnspeed=5;
pint ledgeTimer=50;
pint ledgeSpeedIn=1;
pint ledgeSpeedOut=3;
pint ledgeShift=1;
pint cammove=2;
2001-04-02 17:48:02 +02:00
2001-02-06 22:09:45 +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-02-27 17:59:50 +01:00
CPlayerThing::init();
2001-02-06 18:15:28 +01:00
2001-03-31 20:22:38 +02:00
m_fontBank=new ("PlayerFont") FontBank();
m_fontBank->initialise(&standardFont);
m_fontBank->setOt(5);
m_spriteBank=new ("PlayerSprites") SpriteBank();
2001-04-20 16:53:35 +02:00
m_spriteBank->load(SPRITES_SPRITES_SPR);
2001-03-31 20:22:38 +02:00
2001-02-06 18:15:28 +01:00
m_layerCollision=NULL;
2001-03-06 21:13:16 +01:00
2001-04-01 22:22:49 +02:00
m_actorGfx=CActorPool::GetActor(ACTORS_SPONGEBOB_SBK);
2001-01-16 17:20:45 +01:00
2001-03-23 21:09:14 +01:00
for(int i=0;i<NUM_PLAYERMODES;i++)
{
s_playerModes[i]->initialise(this);
}
m_currentPlayerModeClass=NULL;
2001-04-08 20:57:16 +02:00
setMode(PLAYER_MODE_FULLUNARMED); //PKG
2001-03-23 21:09:14 +01:00
2001-01-20 00:37:40 +01:00
m_animNo=0;
m_animFrame=0;
2001-01-16 20:27:14 +01:00
setFacing(FACING_RIGHT);
2001-02-12 18:55:01 +01:00
respawn();
2001-01-20 00:37:40 +01:00
2001-01-22 23:58:12 +01:00
m_lives=CGameSlotManager::getSlotData().m_lives;
2001-02-09 18:01:04 +01:00
m_lastPadInput=m_padInput=PI_NONE;
2001-02-06 22:09:45 +01:00
2001-02-08 17:51:16 +01:00
s_screenPos=128;
2001-04-18 18:35:26 +02:00
resetPlayerCollisionSizeToBase();
2001-03-02 17:02:30 +01:00
2001-03-29 23:30:34 +02:00
m_divingHelmet=false;
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-03-27 22:01:22 +02:00
for(int i=0;i<NUM_PLAYERMODES;i++)
{
s_playerModes[i]->shutdown();
}
2001-04-10 01:28:27 +02:00
delete m_actorGfx;
2001-03-31 20:22:38 +02:00
m_spriteBank->dump(); delete m_spriteBank;
m_fontBank->dump(); delete m_fontBank;
2001-02-27 17:59:50 +01:00
CPlayerThing::shutdown();
2001-01-09 21:38:20 +01:00
}
2001-01-16 20:27:14 +01:00
/*----------------------------------------------------------------------
Function:
Purpose:
Params:
Returns:
---------------------------------------------------------------------- */
2001-02-06 18:15:28 +01:00
int newmode=-1;
2001-03-02 19:00:19 +01:00
2001-02-20 18:37:25 +01:00
#ifdef _STATE_DEBUG_
char posBuf[100];
#endif
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
2001-01-29 23:35:18 +01:00
2001-02-06 18:15:28 +01:00
if(PadGetHeld(0)&PAD_L1&&PadGetHeld(0)&PAD_L2)
{
2001-02-12 20:35:29 +01:00
respawn();
2001-02-06 18:15:28 +01:00
}
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
2001-04-11 22:59:16 +02:00
if(isOnPlatform())
{
shove(m_platform->getPosDelta());
}
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-03-23 21:09:14 +01:00
// s_modes[m_currentMode].m_modeControl->think();
// m_currentStateClass->think(this);
2001-03-27 22:01:22 +02:00
m_currentPlayerModeClass->think();
2001-01-25 23:19:47 +01:00
2001-03-02 17:02:30 +01:00
// Powerups
if(m_squeakyBootsTimer)
{
m_squeakyBootsTimer--;
}
if(m_invinvibilityRingTimer)
{
m_invinvibilityRingTimer--;
}
// Flashing..
if(m_invincibleFrameCount)
{
m_invincibleFrameCount--;
}
2001-02-16 23:53:16 +01:00
if(Pos.vx<64)Pos.vx=64;
else if(Pos.vx>m_mapEdge.vx-64)Pos.vx=m_mapEdge.vx-64;
if(Pos.vy<64)Pos.vy=64;
else if(Pos.vy>m_mapEdge.vy-64)Pos.vy=m_mapEdge.vy-64;
2001-02-12 21:14:31 +01:00
2001-02-09 18:01:04 +01:00
2001-01-31 22:05:12 +01:00
// Look around
int pad=getPadInputHeld();
2001-04-18 18:35:26 +02:00
if(pad&PI_UP&&canDoLookAround())
2001-04-11 17:48:16 +02:00
{
2001-04-12 00:37:57 +02:00
if(m_padLookAroundTimer>0)
2001-04-11 17:48:16 +02:00
{
2001-04-12 00:37:57 +02:00
m_padLookAroundTimer=0;
2001-04-11 17:48:16 +02:00
}
2001-04-12 00:37:57 +02:00
else if(m_padLookAroundTimer>-looktimeout)
2001-04-11 17:48:16 +02:00
{
2001-04-12 00:37:57 +02:00
m_padLookAroundTimer--;
2001-04-11 17:48:16 +02:00
}
else if(m_cameraLookOffset>-lookmaxoffsetup)
{
m_cameraLookOffset-=lookspeed;
if(m_cameraLookOffset<-lookmaxoffsetup)
{
m_cameraLookOffset=-lookmaxoffsetup;
}
}
}
2001-04-18 18:35:26 +02:00
else if(pad&PI_DOWN&&canDoLookAround())
2001-04-11 17:48:16 +02:00
{
2001-04-12 00:37:57 +02:00
if(m_padLookAroundTimer<0)
2001-04-11 17:48:16 +02:00
{
2001-04-12 00:37:57 +02:00
m_padLookAroundTimer=0;
2001-04-11 17:48:16 +02:00
}
2001-04-12 00:37:57 +02:00
else if(m_padLookAroundTimer<looktimeout)
2001-04-11 17:48:16 +02:00
{
2001-04-12 00:37:57 +02:00
m_padLookAroundTimer++;
2001-04-11 17:48:16 +02:00
}
else if(m_cameraLookOffset<lookmaxoffsetdown)
{
m_cameraLookOffset+=lookspeed;
if(m_cameraLookOffset>lookmaxoffsetdown)
{
m_cameraLookOffset=lookmaxoffsetdown;
}
}
}
else
{
2001-04-12 00:37:57 +02:00
m_padLookAroundTimer=0;
2001-04-11 17:48:16 +02:00
}
// Return to centre
2001-04-17 22:45:02 +02:00
if(m_padLookAroundTimer==0&&m_cameraLookOffset<0)
2001-04-11 17:48:16 +02:00
{
m_cameraLookOffset+=lookreturnspeed;
if(m_cameraLookOffset>0)
{
m_cameraLookOffset=0;
}
}
2001-04-17 22:45:02 +02:00
if(m_padLookAroundTimer==0&&m_cameraLookOffset>0)
2001-04-11 17:48:16 +02:00
{
m_cameraLookOffset-=lookreturnspeed;
if(m_cameraLookOffset<0)
{
m_cameraLookOffset=0;
}
}
2001-04-19 01:37:52 +02:00
// Automatic anim sfx
playAnimFrameSfx(m_animNo,m_animFrame);
2001-01-15 23:09:47 +01:00
}
2001-01-25 16:25:46 +01:00
2001-04-17 22:09:33 +02:00
// Ledge look-ahead stuff
if(m_ledgeLookAhead&&m_ledgeLookAhead==m_lastLedgeLookAhead)
{
if(m_ledgeLookTimer<ledgeTimer)
{
2001-04-17 22:45:02 +02:00
m_ledgeLookTimer+=_frames;
2001-04-17 22:09:33 +02:00
}
else
{
int limit;
limit=(m_ledgeLookAhead*MAP2D_BLOCKSTEPSIZE)<<ledgeShift;
2001-04-17 22:45:02 +02:00
if(m_ledgeLookAhead>0)
2001-04-17 22:09:33 +02:00
{
2001-04-17 22:45:02 +02:00
if(m_ledgeLookOffset<limit)
2001-04-17 22:09:33 +02:00
{
2001-04-17 22:45:02 +02:00
// Look down
m_ledgeLookOffset+=ledgeSpeedIn*_frames;
if(m_ledgeLookOffset>limit)
{
m_ledgeLookOffset=limit;
}
}
else if(m_ledgeLookOffset>limit)
{
// Look up
m_ledgeLookOffset-=ledgeSpeedIn*_frames;
if(m_ledgeLookOffset<limit)
{
m_ledgeLookOffset=limit;
}
2001-04-17 22:09:33 +02:00
}
}
}
}
else
{
if(m_ledgeLookOffset>0)
{
2001-04-17 22:45:02 +02:00
// Relax from look down
2001-04-17 22:09:33 +02:00
m_ledgeLookOffset-=ledgeSpeedOut*_frames;
if(m_ledgeLookOffset<=0)
{
m_ledgeLookOffset=0;
m_ledgeLookTimer=0;
}
}
else if(m_ledgeLookOffset<0)
{
2001-04-17 22:45:02 +02:00
// Relax from look up
2001-04-17 22:09:33 +02:00
m_ledgeLookOffset+=ledgeSpeedOut*_frames;
if(m_ledgeLookOffset>=0)
{
m_ledgeLookOffset=0;
m_ledgeLookTimer=0;
}
}
}
m_lastLedgeLookAhead=m_ledgeLookAhead;
m_ledgeLookAhead=0;
2001-04-13 00:14:49 +02:00
// Camera focus point stuff
m_currentCamFocusPointTarget.vx=Pos.vx+MAP2D_CENTRE_X;
2001-04-17 22:45:02 +02:00
m_currentCamFocusPointTarget.vy=Pos.vy+MAP2D_CENTRE_Y;
2001-04-17 22:09:33 +02:00
for(i=0;i<_frames;i++)
{
m_currentCamFocusPoint.vx+=(m_currentCamFocusPointTarget.vx-m_currentCamFocusPoint.vx)>>cammove;
m_currentCamFocusPoint.vy+=(m_currentCamFocusPointTarget.vy-m_currentCamFocusPoint.vy)>>cammove;
}
2001-04-17 22:45:02 +02:00
// Final camera position
int yoff;
yoff=m_cameraLookOffset+(m_ledgeLookOffset>>ledgeShift);
if(yoff<-lookmaxoffsetup)yoff=-lookmaxoffsetup;
else if(yoff>lookmaxoffsetdown)yoff=lookmaxoffsetdown;
2001-04-12 00:37:57 +02:00
m_cameraPos.vx=m_currentCamFocusPoint.vx;
2001-04-17 22:45:02 +02:00
m_cameraPos.vy=m_currentCamFocusPoint.vy+yoff;
2001-02-09 18:01:04 +01:00
2001-04-17 22:09:33 +02:00
2001-02-12 16:26:00 +01:00
// Limit camera scroll to the edges of the map
if(m_cameraPos.vx<0)
{
m_cameraPos.vx=0;
}
else if(m_cameraPos.vx>m_mapCameraEdges.vx)
{
m_cameraPos.vx=m_mapCameraEdges.vx;
}
if(m_cameraPos.vy<0)
{
m_cameraPos.vy=0;
}
else if(m_cameraPos.vy>m_mapCameraEdges.vy)
{
m_cameraPos.vy=m_mapCameraEdges.vy;
}
2001-04-01 23:40:52 +02:00
CPlayerThing::think(_frames);
2001-01-15 23:09:47 +01:00
}
2001-02-16 21:25:02 +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-03-01 18:01:37 +01:00
#include "gfx\prim.h" // (pkg)
2001-04-11 18:00:25 +02:00
int healthx=40;
2001-04-09 22:25:06 +02:00
int healthy=40;
2001-04-05 16:40:50 +02:00
int healthr=200;
int healthg=75;
int healthb=75;
2001-03-02 19:00:19 +01:00
2001-02-02 18:48:40 +01:00
#ifdef __USER_paul__
int mouth=-1,eyes=-1;
#endif
2001-01-15 23:09:47 +01:00
void CPlayer::render()
{
2001-02-27 17:59:50 +01:00
CPlayerThing::render();
2001-01-16 17:20:45 +01:00
2001-02-20 18:37:25 +01:00
#ifdef _STATE_DEBUG_
2001-03-29 21:19:33 +02:00
sprintf(posBuf,"%03d (%02d) ,%03d (%02d) = dfg:%+02d",Pos.vx,Pos.vx&0x0f,Pos.vy,Pos.vy&0x0f,getHeightFromGround(Pos.vx,Pos.vy));
2001-03-31 20:22:38 +02:00
m_fontBank->print(40,40,posBuf);
2001-02-20 18:37:25 +01:00
#endif
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-04-05 18:26:17 +02:00
DVECTOR sbPos=
2001-04-02 17:48:02 +02:00
{
2001-04-12 00:37:57 +02:00
Pos.vx-m_cameraPos.vx,
Pos.vy-m_cameraPos.vy,
2001-04-02 17:48:02 +02:00
};
2001-04-05 18:26:17 +02:00
renderSb(&sbPos,m_animNo,m_animFrame>>sbanimspeed);
m_currentPlayerModeClass->render(&sbPos);
2001-01-22 23:58:12 +01:00
}
2001-02-09 22:41:55 +01:00
#ifdef _STATE_DEBUG_
char buf[128];
sprintf(buf,"MODE: %s",s_modeText[m_currentMode]);
2001-03-31 20:22:38 +02:00
m_fontBank->print(40,210,buf);
2001-02-09 22:41:55 +01:00
#endif
2001-03-01 18:01:37 +01:00
2001-04-05 16:40:50 +02:00
// Health
2001-03-01 18:01:37 +01:00
{
2001-04-05 16:40:50 +02:00
static int s_fullHealthFrames[]=
{
FRM__HEALTH_FULL_1,
FRM__HEALTH_FULL_2,
FRM__HEALTH_FULL_3,
FRM__HEALTH_FULL_4,
FRM__HEALTH_FULL_5,
};
static int s_emptyHealthFrames[]=
2001-03-01 18:01:37 +01:00
{
2001-04-05 16:40:50 +02:00
FRM__HEALTH_EMPTY_1,
FRM__HEALTH_EMPTY_2,
FRM__HEALTH_EMPTY_3,
FRM__HEALTH_EMPTY_4,
FRM__HEALTH_EMPTY_5,
};
int i,x,y;
POLY_FT4 *ft4;
int *frames;
x=healthx;
y=healthy;
2001-04-06 23:25:18 +02:00
if(m_health==0||m_healthReactFrames)
2001-04-05 16:40:50 +02:00
{
2001-04-06 23:25:18 +02:00
if(m_healthReactFrames)
{
m_healthReactFrames--;
}
frames=s_emptyHealthFrames;
2001-03-01 18:01:37 +01:00
}
else
{
2001-04-06 23:25:18 +02:00
frames=s_fullHealthFrames;
2001-03-01 18:01:37 +01:00
}
2001-03-01 21:30:25 +01:00
2001-04-05 16:40:50 +02:00
for(i=5;i>0;i--)
{
ft4=m_spriteBank->printFT4(*frames++,x,y,0,0,5);
2001-04-06 23:25:18 +02:00
if(i>m_health)
2001-04-05 16:40:50 +02:00
{
setRGB0(ft4,healthr,healthg,healthb);
}
y+=9;
}
2001-03-01 18:01:37 +01:00
}
2001-03-31 20:22:38 +02:00
// Mode specific ui
m_currentPlayerModeClass->renderModeUi();
2001-01-15 23:09:47 +01:00
}
2001-01-20 00:37:40 +01:00
2001-02-12 16:26:00 +01:00
/*----------------------------------------------------------------------
Function:
Purpose: Pre-calcs the visible edges of the map ( ie: the hard limits
for the camera pos )
Params:
Returns:
---------------------------------------------------------------------- */
void CPlayer::setMapSize(DVECTOR _mapSize)
{
m_mapCameraEdges.vx=(_mapSize.vx-34)*MAP2D_BLOCKSTEPSIZE; // Made up numbers! :) (pkg)
m_mapCameraEdges.vy=(_mapSize.vy-18)*MAP2D_BLOCKSTEPSIZE;
2001-02-12 21:14:31 +01:00
m_mapEdge.vx=_mapSize.vx*MAP2D_BLOCKSTEPSIZE;
m_mapEdge.vy=_mapSize.vy*MAP2D_BLOCKSTEPSIZE;
2001-01-25 16:25:46 +01:00
}
2001-03-29 21:19:33 +02:00
/*----------------------------------------------------------------------
Function:
Purpose:
Params:
Returns:
---------------------------------------------------------------------- */
int CPlayer::getHeightFromGround(int _x,int _y,int _maxHeight)
{
int height;
2001-04-06 22:53:48 +02:00
DVECTOR platformPos;
DVECTOR newPos;
2001-03-29 21:19:33 +02:00
if(isOnPlatform())
{
2001-04-06 22:53:48 +02:00
CThing *platform = isOnPlatform();
height = platform->getNewYPos( this ) - Pos.vy;
2001-03-31 00:43:35 +02:00
2001-04-06 22:53:48 +02:00
int groundHeight = m_layerCollision->getHeightFromGround(_x,_y,_maxHeight);
2001-04-06 18:26:33 +02:00
2001-04-06 22:53:48 +02:00
if ( groundHeight < height )
{
height = groundHeight;
clearPlatform();
}
2001-03-29 21:19:33 +02:00
}
else
{
height=m_layerCollision->getHeightFromGround(_x,_y,_maxHeight);
}
return height;
}
2001-04-07 21:52:45 +02:00
/*----------------------------------------------------------------------
Function:
Purpose:
Params:
Returns:
---------------------------------------------------------------------- */
int CPlayer::getHeightFromGroundNoPlatform(int _x,int _y,int _maxHeight=32)
{
return( m_layerCollision->getHeightFromGround(_x,_y,_maxHeight) );
}
2001-03-01 21:30:25 +01:00
/*----------------------------------------------------------------------
Function:
Purpose:
Params:
Returns:
---------------------------------------------------------------------- */
void CPlayer::addHealth(int _health)
{
2001-04-06 23:25:18 +02:00
m_health+=_health;
if(m_health>MAX_HEALTH)
2001-03-01 21:30:25 +01:00
{
2001-04-06 23:25:18 +02:00
m_health=MAX_HEALTH;
2001-03-01 21:30:25 +01:00
}
}
2001-01-20 00:37:40 +01:00
2001-03-01 21:30:25 +01:00
/*----------------------------------------------------------------------
Function:
Purpose:
Params:
Returns:
---------------------------------------------------------------------- */
void CPlayer::addLife()
{
m_lives++;
if(m_lives>MAX_LIVES)
{
m_lives=MAX_LIVES;
}
}
2001-01-20 00:37:40 +01:00
2001-04-12 20:48:33 +02:00
/*----------------------------------------------------------------------
Function:
Purpose:
Params:
Returns:
---------------------------------------------------------------------- */
ATTACK_STATE CPlayer::getAttackState()
{
return m_currentPlayerModeClass->getAttackState();
}
2001-01-26 19:20:41 +01:00
/*----------------------------------------------------------------------
Function:
Purpose:
Params:
Returns:
---------------------------------------------------------------------- */
2001-01-31 23:50:59 +01:00
void CPlayer::setMode(PLAYER_MODE _mode)
2001-01-26 19:20:41 +01:00
{
2001-04-18 18:35:26 +02:00
resetPlayerCollisionSizeToBase();
2001-01-26 19:20:41 +01:00
m_currentMode=_mode;
2001-03-23 21:09:14 +01:00
m_currentPlayerModeClass=s_playerModes[_mode];
m_currentPlayerModeClass->enter();
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-04-02 17:48:02 +02:00
m_facing=_facing;
2001-01-12 23:40:39 +01:00
}
2001-02-01 18:01:12 +01:00
/*----------------------------------------------------------------------
Function:
Purpose:
Params:
Returns:
---------------------------------------------------------------------- */
2001-01-20 00:37:40 +01:00
int CPlayer::getAnimFrame()
{
return m_animFrame;
}
void CPlayer::setAnimFrame(int _animFrame)
{
m_animFrame=_animFrame;
2001-04-19 01:37:52 +02:00
}
int CPlayer::getAnimFrameCount()
{
return m_actorGfx->getFrameCount(m_animNo)<<sbanimspeed;
}
int CPlayer::getAnimNo()
{
return m_animNo;
}
void CPlayer::setAnimNo(int _animNo)
{
m_animNo=_animNo;
setAnimFrame(0);
}
/*----------------------------------------------------------------------
Function:
Purpose:
Params:
Returns:
---------------------------------------------------------------------- */
void CPlayer::playAnimFrameSfx(int _animNo,int _animFrame)
{
static int lastAnimNo=-1;
static const AnimSfx *sfx;
2001-02-01 18:01:12 +01:00
2001-04-19 01:37:52 +02:00
if(_animNo!=lastAnimNo)
{
// Lookup the new anim number and cache it for next time :)
int i;
sfx=s_animSfx;
for(i=0;i<s_numAnimSfx;i++)
{
if(sfx->m_animNumber==_animNo)
{
break;
}
sfx++;
}
if(i==s_numAnimSfx)
{
// No sfx for this anim
sfx=NULL;
}
lastAnimNo=_animNo;
}
// Are there any sounds for this anim at this frame?
if(sfx)
2001-02-01 18:01:12 +01:00
{
2001-02-01 18:32:16 +01:00
const AnimFrameSfx *frameSfx;
int i;
2001-02-01 18:01:12 +01:00
2001-04-19 01:37:52 +02:00
ASSERT(sfx->m_numAnimFrameSfx);
2001-02-01 18:01:12 +01:00
frameSfx=sfx->m_animFrameSfx;
for(i=0;i<sfx->m_numAnimFrameSfx;i++)
{
if(m_animFrame==frameSfx->m_frame)
{
2001-02-08 17:51:16 +01:00
CSoundMediator::SFXID sfxId=frameSfx->m_sfxId;
2001-03-02 17:02:30 +01:00
if(m_squeakyBootsTimer)
2001-02-08 17:51:16 +01:00
{
// Ugh.. horrible way to change the sfx when wearing squeaky boots (pkg)
if(sfxId==CSoundMediator::SFX_SPONGEBOB_WALK_1)sfxId=CSoundMediator::SFX_SPONGEBOB_SQUEAKY_SHOES_1;
else if(sfxId==CSoundMediator::SFX_SPONGEBOB_WALK_2)sfxId=CSoundMediator::SFX_SPONGEBOB_SQUEAKY_SHOES_2;
}
CSoundMediator::playSfx(sfxId);
2001-03-02 17:02:30 +01:00
break;
2001-02-01 18:01:12 +01:00
}
if(m_animFrame<frameSfx->m_frame)
{
break;
}
frameSfx++;
}
}
2001-01-20 00:37:40 +01:00
}
2001-02-01 18:01:12 +01:00
2001-02-12 18:55:01 +01:00
/*----------------------------------------------------------------------
Function:
Purpose:
Params:
Returns:
---------------------------------------------------------------------- */
void CPlayer::respawn()
{
// Strip any items that the player might be holding
2001-03-25 23:33:20 +02:00
if(m_currentMode!=PLAYER_MODE_BASICUNARMED)
{
setMode(PLAYER_MODE_FULLUNARMED);
}
else
{
2001-02-16 21:25:02 +01:00
setMode(PLAYER_MODE_BASICUNARMED);
2001-03-25 23:33:20 +02:00
}
2001-02-12 18:55:01 +01:00
2001-04-06 23:25:18 +02:00
m_health=MAX_HEALTH;
m_healthReactFrames=0;
2001-03-27 22:01:22 +02:00
m_invincibleFrameCount=INVINCIBLE_FRAMES__START;
2001-02-12 18:55:01 +01:00
Pos=m_respawnPos;
2001-04-12 00:37:57 +02:00
m_cameraLookOffset=0;
2001-04-17 17:33:00 +02:00
m_currentCamFocusPoint.vx=Pos.vx+MAP2D_CENTRE_X;
m_currentCamFocusPoint.vy=Pos.vy+MAP2D_CENTRE_Y;
2001-04-12 00:37:57 +02:00
m_padLookAroundTimer=0;
2001-04-17 22:09:33 +02:00
m_ledgeLookAhead=m_lastLedgeLookAhead=0;
m_ledgeLookOffset=0;
m_ledgeLookTimer=0;
2001-03-29 21:19:33 +02:00
2001-03-31 04:05:24 +02:00
m_glassesFlag=0;
m_squeakyBootsTimer=0;
m_invinvibilityRingTimer=0;
m_bubbleAmmo=0;
2001-04-08 20:57:16 +02:00
m_jellyAmmo=0;
2001-03-31 04:05:24 +02:00
2001-04-11 17:48:16 +02:00
2001-03-29 21:19:33 +02:00
clearPlatform();
2001-02-12 18:55:01 +01:00
}
2001-04-05 18:26:17 +02:00
/*----------------------------------------------------------------------
Function:
Purpose:
Params:
Returns:
---------------------------------------------------------------------- */
void CPlayer::renderSb(DVECTOR *_pos,int _animNo,int _animFrame)
{
m_actorGfx->Render(*_pos,_animNo,_animFrame,m_facing==FACING_RIGHT?0:1);
}
2001-04-18 18:35:26 +02:00
/*----------------------------------------------------------------------
Function:
Purpose: Says whether SB can do the look up/down thing
Params:
Returns:
---------------------------------------------------------------------- */
int CPlayer::canDoLookAround()
{
return m_currentPlayerModeClass->canDoLookAround();
}
2001-02-06 22:09:45 +01:00
/*----------------------------------------------------------------------
Function:
Purpose:
Params:
Returns:
---------------------------------------------------------------------- */
#ifdef __VERSION_DEBUG__
2001-02-12 18:55:01 +01:00
int invincibleSponge=false; // NB: This is for debugging purposes only so don't try and use it for a permenant cheat mode..
2001-02-06 22:09:45 +01:00
#endif
void CPlayer::takeDamage(DAMAGE_TYPE _damage)
{
2001-04-13 00:14:49 +02:00
if(m_invincibleFrameCount==0&& // Don't take damage if still recovering from the last hit
m_invinvibilityRingTimer==0&& // Or if we have the invincibility ring on
m_currentMode!=PLAYER_MODE_DEAD) // Or already dead! :)
2001-02-06 22:09:45 +01:00
{
int ouchThatHurt=true;
// Check if we are currently immune to this damage type
switch(_damage)
{
2001-03-05 22:11:51 +01:00
case DAMAGE__NONE:
break;
2001-04-18 22:31:14 +02:00
case DAMAGE__ELECTROCUTION:
case DAMAGE__SHOCK_ENEMY:
if(m_squeakyBootsTimer)
{
ouchThatHurt=false;
}
break;
2001-02-06 22:09:45 +01:00
case DAMAGE__FALL:
case DAMAGE__LAVA:
2001-02-27 17:59:50 +01:00
case DAMAGE__HIT_ENEMY:
2001-03-05 22:11:51 +01:00
case DAMAGE__GAS_ENEMY:
case DAMAGE__POISON_ENEMY:
case DAMAGE__SWALLOW_ENEMY:
case DAMAGE__PINCH_ENEMY:
case DAMAGE__SQUASH_ENEMY:
case DAMAGE__BURN_ENEMY:
case DAMAGE__BITE_ENEMY:
2001-02-06 22:09:45 +01:00
break;
}
if(ouchThatHurt)
{
#ifdef __VERSION_DEBUG__
if(invincibleSponge){m_invincibleFrameCount=INVINCIBLE_FRAMES__HIT;return;}
#endif
2001-04-06 23:25:18 +02:00
if(m_health)
2001-02-06 22:09:45 +01:00
{
m_invincibleFrameCount=INVINCIBLE_FRAMES__HIT;
2001-04-06 23:25:18 +02:00
m_healthReactFrames=10;
m_health--;
2001-02-06 22:09:45 +01:00
}
else
{
CSoundMediator::playSfx(CSoundMediator::SFX_SPONGEBOB_DEFEATED_JINGLE);
2001-03-25 23:33:20 +02:00
setMode(PLAYER_MODE_DEAD);
2001-02-06 22:09:45 +01:00
}
}
}
2001-01-20 00:37:40 +01:00
}
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();
2001-02-09 18:01:04 +01:00
m_padInputDown=(PLAYERINPUT)(m_padInput&(m_lastPadInput^-1));
2001-01-29 23:35:18 +01:00
}
/*----------------------------------------------------------------------
Function:
Purpose:
Params:
Returns:
---------------------------------------------------------------------- */
2001-02-09 18:01:04 +01:00
PLAYERINPUT CPlayer::readPadInput()
2001-01-29 23:35:18 +01:00
{
2001-02-09 18:01:04 +01:00
PLAYERINPUT input;
int pad;
input=PI_NONE;
pad=PadGetHeld(0);
if(pad&CPadConfig::getButton(CPadConfig::PAD_CFG_UP))
{
input=(PLAYERINPUT)(input|PI_UP);
}
if(pad&CPadConfig::getButton(CPadConfig::PAD_CFG_DOWN))
{
input=(PLAYERINPUT)(input|PI_DOWN);
}
if(pad&CPadConfig::getButton(CPadConfig::PAD_CFG_LEFT))
{
input=(PLAYERINPUT)(input|PI_LEFT);
}
if(pad&CPadConfig::getButton(CPadConfig::PAD_CFG_RIGHT))
{
input=(PLAYERINPUT)(input|PI_RIGHT);
}
if(pad&CPadConfig::getButton(CPadConfig::PAD_CFG_JUMP))
{
input=(PLAYERINPUT)(input|PI_JUMP);
}
if(pad&CPadConfig::getButton(CPadConfig::PAD_CFG_ACTION))
{
input=(PLAYERINPUT)(input|PI_ACTION);
}
#ifdef _RECORD_DEMO_MODE_
CDemoPlayer::demoPlayerControl *crnt;
PLAYERINPUT lastInput;
crnt=&s_demoControls[s_demoSize];
if(s_demoFrameCount==0)
{
crnt->m_inputValue=input;
}
lastInput=(PLAYERINPUT)crnt->m_inputValue;
if(crnt->m_length==255)
{
lastInput=(PLAYERINPUT)(input-1);
}
if(lastInput==input)
{
crnt->m_length++;
}
else
{
s_demoSize++;
ASSERT(s_demoSize<MAX_DEMO_SIZE);
crnt++;
crnt->m_inputValue=input;
crnt->m_length=1;
}
s_demoFrameCount++;
2001-03-05 16:08:50 +01:00
if(s_demoFrameCount==MAX_DEMO_TIME_IN_FRAMES)
2001-02-09 18:01:04 +01:00
{
writeDemoControls();
ASSERT(!"DEMO ENDED");
}
#endif
return input;
2001-01-29 23:35:18 +01:00
}
2001-03-08 21:12:47 +01:00
/*----------------------------------------------------------------------
Function:
Purpose:
Params:
Returns:
---------------------------------------------------------------------- */
2001-04-11 22:59:16 +02:00
void CPlayer::shove( DVECTOR move )
2001-03-08 21:12:47 +01:00
{
2001-03-29 21:19:33 +02:00
int colHeight;
// X movement
colHeight=m_layerCollision->getHeightFromGround(Pos.vx+move.vx,Pos.vy,5);
if(colHeight<0)
{
// Stop at the edge of the obstruction
int dir,vx,cx,i;
if(move.vx<0)
{
dir=-1;
vx=move.vx;
}
else
{
dir=+1;
vx=move.vx;
}
cx=Pos.vx;
for(i=0;i<vx;i++)
{
if(m_layerCollision->getHeightFromGround(cx,Pos.vy)<0)
{
break;
}
cx+=dir;
}
2001-04-03 22:26:21 +02:00
if(i)
Pos.vx=cx-dir;
2001-03-29 21:19:33 +02:00
}
else
{
// No obstruction
Pos.vx+=move.vx;
}
// Y movement
colHeight=m_layerCollision->getHeightFromGround(Pos.vx,Pos.vy+move.vy,5);
if(colHeight<0)
{
// Stop at the edge of the obstruction
int dir,vy,cy,i;
if(move.vy<0)
{
dir=-1;
vy=move.vy;
}
else
{
dir=+1;
vy=move.vy;
}
cy=Pos.vy;
for(i=0;i<vy;i++)
{
if(m_layerCollision->getHeightFromGround(Pos.vx,cy)<0)
{
break;
}
cy+=dir;
}
2001-04-03 22:26:21 +02:00
if(i)
Pos.vy=cy-dir;
2001-03-29 21:19:33 +02:00
}
else
{
// No obstruction
Pos.vy+=move.vy;
}
2001-04-11 22:59:16 +02:00
}
2001-03-29 21:19:33 +02:00
void CPlayer::setPlatform(CThing *_newPlatform)
{
m_platform=_newPlatform;
}
void CPlayer::clearPlatform()
{
m_platform=NULL;
}
2001-03-31 00:43:35 +02:00
void CPlayer::setHasPlatformCollided( bool newVal )
{
m_hasPlatformCollided = newVal;
}
bool CPlayer::getHasPlatformCollided()
{
return( m_hasPlatformCollided );
}
2001-03-29 21:19:33 +02:00
2001-03-06 21:13:16 +01:00
2001-04-18 18:35:26 +02:00
/*----------------------------------------------------------------------
Function:
Purpose:
Params:
Returns:
---------------------------------------------------------------------- */
void CPlayer::resetPlayerCollisionSizeToBase()
{
setPlayerCollisionSize(0,-COLSIZE_BASE_HEIGHT/2,COLSIZE_BASE_WIDTH,COLSIZE_BASE_HEIGHT);
}
/*----------------------------------------------------------------------
Function:
Purpose:
Params:
Returns:
---------------------------------------------------------------------- */
void CPlayer::setPlayerCollisionSize(int _x,int _y,int _w,int _h)
{
setCollisionSize(_w,_h);
setCollisionCentreOffset(_x,_y);
}
2001-01-16 20:27:14 +01:00
/*===========================================================================
end */