SBSPSS/source/player/pmjelly.cpp

427 lines
10 KiB
C++
Raw Normal View History

2001-04-03 23:00:00 +02:00
/*=========================================================================
pmjelly.cpp
Author: PKG
2001-07-17 17:19:20 +02:00
Created:
2001-04-03 23:00:00 +02:00
Project: Spongebob
2001-07-17 17:19:20 +02:00
Purpose:
2001-04-03 23:00:00 +02:00
Copyright (c) 2001 Climax Development Ltd
===========================================================================*/
/*----------------------------------------------------------------------
Includes
-------- */
#include "player\pmjelly.h"
2001-07-17 17:19:20 +02:00
#ifndef __PROJECTL_PROJECTL_H__
#include "projectl\projectl.h"
2001-04-03 23:00:00 +02:00
#endif
2001-07-17 17:19:20 +02:00
#ifndef __PAD_VIBE_H__
#include "pad\vibe.h"
2001-04-08 20:57:16 +02:00
#endif
2001-07-17 17:19:20 +02:00
#ifndef __PLATFORM_PLATFORM_H__
#include "platform\platform.h"
2001-04-08 20:57:16 +02:00
#endif
#ifndef __GFX_FONT_H__
#include "gfx\font.h"
#endif
2001-06-25 22:25:28 +02:00
#ifndef __GAME_GAME_H__
#include "game/game.h"
#endif
2001-07-17 17:19:20 +02:00
#ifndef __UTILS_HEADER__
#include "utils\utils.h"
#endif
2001-06-25 22:25:28 +02:00
// States
#ifndef __PLAYER__PSLOOK_H__
#include "player\pslook.h"
#endif
#ifndef __PLAYER__PSJUMP_H__
#include "player\psjump.h"
#endif
#ifndef __PLAYER__PSJMPBCK_H__
#include "player\psjmpbck.h"
#endif
#ifndef __PLAYER__PSRUN_H__
#include "player\psrun.h"
#endif
#ifndef __PLAYER__PSFALL_H__
#include "player\psfall.h"
#endif
#ifndef __PLAYER__PSHITGND_H__
#include "player\pshitgnd.h"
#endif
#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
#ifndef __PLAYER__PSSPRING_H__
#include "player\psspring.h"
#endif
#ifndef __PLAYER_PSCART_H__
#include "player\pscart.h"
#endif
#ifndef __PLAYER_PSFLOAT_H__
#include "player\psfloat.h"
#endif
2001-07-03 00:57:52 +02:00
#ifndef __PLAYER_PSDANCE_H__
#include "player\psdance.h"
#endif
2001-07-03 22:49:30 +02:00
#ifndef __PLAYER_PSSWAL_H__
#include "player\psswal.h"
#endif
2001-04-03 23:00:00 +02:00
/* Std Lib
------- */
/* Data
---- */
#ifndef __ANIM_SPONGEBOB_HEADER__
#include <ACTOR_SPONGEBOB_ANIM.h>
#endif
2001-04-20 16:53:35 +02:00
#ifndef __SPR_SPRITES_H__
#include <sprites.h>
2001-04-03 23:00:00 +02:00
#endif
/*----------------------------------------------------------------------
Tyepdefs && Defines
------------------- */
/*----------------------------------------------------------------------
Structure defintions
-------------------- */
/*----------------------------------------------------------------------
Function Prototypes
------------------- */
/*----------------------------------------------------------------------
Vars
---- */
2001-06-25 22:25:28 +02:00
static CPlayerState *s_stateTable[]=
{
&s_stateWeaponIdle, // STATE_IDLE
&s_stateTeeterIdle, // STATE_IDLETEETER
&s_stateJump, // STATE_JUMP
&s_stateSpring, // STATE_SPRINGUP
&s_stateRun, // STATE_RUN
&s_stateFall, // STATE_FALL
&s_stateFallFar, // STATE_FALLFAR
&s_stateHitGround, // STATE_HITGROUND
&s_stateButtBounce, // STATE_BUTTBOUNCE
&s_stateButtBounceFall, // STATE_BUTTFALL
&s_stateButtBounceLand, // STATE_BUTTLAND
&s_stateButtBounceUp, // STATE_BUTTBOUNCEUP
&s_stateSoakUp, // STATE_SOAKUP
&s_stateGetUp, // STATE_GETUP
&s_stateLookDown, // STATE_LOOKDOWN
&s_stateLookDownRelax, // STATE_LOOKDOWNRELAX
&s_stateLookUp, // STATE_LOOKUP
&s_stateLookUpRelax, // STATE_LOOKUPRELAX
&s_stateJumpBack, // STATE_JUMPBACK
&s_stateCart, // STATE_CART
&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-06-25 22:25:28 +02:00
};
2001-04-03 23:00:00 +02:00
/*----------------------------------------------------------------------
Function:
Purpose:
Params:
Returns:
---------------------------------------------------------------------- */
2001-04-03 23:36:35 +02:00
void CPlayerModeJellyLauncher::enter()
2001-04-03 23:00:00 +02:00
{
2001-05-13 21:28:48 +02:00
CPlayerModeBase::enter();
2001-04-08 20:57:16 +02:00
m_firingState=FIRING_STATE__NONE;
2001-04-03 23:00:00 +02:00
}
/*----------------------------------------------------------------------
Function:
Purpose:
Params:
Returns:
---------------------------------------------------------------------- */
2001-04-03 23:36:35 +02:00
void CPlayerModeJellyLauncher::think()
2001-04-03 23:00:00 +02:00
{
2001-07-17 17:19:20 +02:00
// If we're firing then restore the 'real' anim number/frame before
// doing the think so that the rest of the code doesn't know what
// is going on ;)
if(m_firingState==FIRING_STATE__FIRING||m_firingState==FIRING_STATE__RECOILING)
{
setAnimNo(m_savedAnimNo);
setAnimFrame(m_savedAnimFrame);
}
2001-04-03 23:00:00 +02:00
CPlayerModeBase::think();
2001-04-08 20:57:16 +02:00
// Start to fire?
switch(m_firingState)
2001-04-03 23:00:00 +02:00
{
2001-04-08 20:57:16 +02:00
case FIRING_STATE__NONE:
2001-05-10 00:12:00 +02:00
if(getPadInputDown()&PI_FIRE&&m_player->getJellyAmmo()&&canFireFromThisState())
2001-04-08 20:57:16 +02:00
{
m_firingFrame=0;
m_firingTime=0;
m_firingState=FIRING_STATE__POWERINGUP;
2001-07-17 17:19:20 +02:00
m_colourFlash=0;
2001-04-08 20:57:16 +02:00
}
break;
case FIRING_STATE__POWERINGUP:
2001-05-10 00:12:00 +02:00
if(getPadInputHeld()&PI_FIRE)
2001-04-08 20:57:16 +02:00
{
if(m_firingTime<TIMEOUT_FOR_BIG_SHOT)
{
m_firingTime++;
}
2001-04-10 21:04:20 +02:00
else
{
2001-07-17 17:19:20 +02:00
m_colourFlash=(m_colourFlash+FLASHSPEED)&4095;
2001-04-10 21:04:20 +02:00
}
2001-06-28 21:14:44 +02:00
CPadVibrationManager::setVibration(0,CPadVibrationManager::VIBE_MEDIUM,(m_firingTime*32)/TIMEOUT_FOR_BIG_SHOT);
2001-04-08 20:57:16 +02:00
}
else
2001-07-17 17:19:20 +02:00
{
2001-06-28 21:14:44 +02:00
CPadVibrationManager::setVibration(0,CPadVibrationManager::VIBE_MEDIUM);
2001-04-10 21:04:20 +02:00
launchProjectile();
2001-07-17 17:19:20 +02:00
m_firingState=FIRING_STATE__RECOILING;
m_firingFrame=0;
2001-07-20 23:26:53 +02:00
// m_firingState=FIRING_STATE__FIRING;
// m_firingFrame=0;
2001-04-08 20:57:16 +02:00
}
break;
2001-07-20 23:26:53 +02:00
case FIRING_STATE__FIRING:
// m_player->setAnimNo(ANIM_SPONGEBOB_FIRESTART);
// m_player->setAnimFrame(m_firingFrame++);
// if(m_firingFrame>=m_player->getAnimFrameCount())
// {
// CPadVibrationManager::setVibration(0,CPadVibrationManager::VIBE_MEDIUM);
// launchProjectile();
// m_firingState=FIRING_STATE__RECOILING;
// m_firingFrame=0;
// }
break;
2001-07-17 17:19:20 +02:00
case FIRING_STATE__RECOILING:
m_player->setAnimNo(ANIM_SPONGEBOB_FIREEND);
2001-04-08 20:57:16 +02:00
m_player->setAnimFrame(m_firingFrame++);
if(m_firingFrame>=m_player->getAnimFrameCount())
{
m_firingState=FIRING_STATE__NONE;
2001-07-17 17:19:20 +02:00
m_player->setAnimNo(m_savedAnimNo);
m_player->setAnimFrame(m_savedAnimFrame);
2001-04-08 20:57:16 +02:00
}
break;
2001-04-03 23:00:00 +02:00
}
}
2001-07-17 17:19:20 +02:00
/*----------------------------------------------------------------------
Function:
Purpose:
Params:
Returns:
---------------------------------------------------------------------- */
void CPlayerModeJellyLauncher::setAnimNo(int _animNo)
{
CPlayerModeBase::setAnimNo(_animNo);
m_savedAnimNo=_animNo;
}
void CPlayerModeJellyLauncher::setAnimFrame(int _animFrame)
{
CPlayerModeBase::setAnimFrame(_animFrame);
m_savedAnimFrame=_animFrame;
}
2001-04-03 23:00:00 +02:00
/*----------------------------------------------------------------------
Function:
Purpose:
Params:
Returns:
---------------------------------------------------------------------- */
2001-04-03 23:36:35 +02:00
void CPlayerModeJellyLauncher::renderModeUi()
2001-04-03 23:00:00 +02:00
{
SpriteBank *sb;
sFrameHdr *fh;
2001-04-08 20:57:16 +02:00
FontBank *fb;
char buf[4];
2001-04-03 23:00:00 +02:00
2001-05-25 20:43:47 +02:00
sb=CGameScene::getSpriteBank();
2001-07-16 22:55:33 +02:00
fh=sb->getFrameHeader(FRM__SMALL_LAUNCHER);
2001-04-08 20:57:16 +02:00
switch(m_firingState)
2001-04-03 23:00:00 +02:00
{
2001-04-08 20:57:16 +02:00
case FIRING_STATE__NONE:
case FIRING_STATE__FIRING:
2001-07-17 17:19:20 +02:00
case FIRING_STATE__RECOILING:
2001-05-02 22:27:49 +02:00
sb->printFT4(fh,CPlayer::POWERUPUI_ICONX,CPlayer::POWERUPUI_ICONY,0,0,CPlayer::POWERUPUI_OT);
2001-04-08 20:57:16 +02:00
break;
case FIRING_STATE__POWERINGUP:
{
2001-07-17 17:19:20 +02:00
int rotRange,scaleBase,scaleRange;
int xs,ys,rot;
POLY_FT4 *ft4;
int colour;
rotRange=m_firingTime/2;
2001-05-02 22:27:49 +02:00
scaleBase=4500+(m_firingTime*10);
2001-04-08 20:57:16 +02:00
scaleRange=m_firingTime*2;
rot=(getRndRange(rotRange*2)-rotRange)&4095;
xs=scaleBase+getRndRange(scaleRange);
ys=scaleBase+getRndRange(scaleRange);
2001-07-17 17:19:20 +02:00
ft4=sb->printRotatedScaledSprite(fh,CPlayer::POWERUPUI_ICONX+(fh->W/2),CPlayer::POWERUPUI_ICONY+(fh->H/2),xs,ys,rot,CPlayer::POWERUPUI_OT);
colour=abs((msin(m_colourFlash)*FLASHSCALE)>>12);
setRGB0(ft4,128+colour,128-colour,128-colour);
2001-04-08 20:57:16 +02:00
}
break;
2001-04-03 23:00:00 +02:00
}
2001-04-08 20:57:16 +02:00
fb=m_player->getFontBank();
sprintf(buf,"x%d",m_player->getJellyAmmo());
2001-05-02 22:27:49 +02:00
fb->print(CPlayer::POWERUPUI_TEXTX,CPlayer::POWERUPUI_TEXTY,buf);
2001-04-03 23:00:00 +02:00
}
/*----------------------------------------------------------------------
Function:
Purpose:
Params:
Returns:
---------------------------------------------------------------------- */
2001-04-08 20:57:16 +02:00
int CPlayerModeJellyLauncher::canFireFromThisState()
2001-04-03 23:00:00 +02:00
{
int ret=false;
switch(getState())
{
case STATE_IDLE:
case STATE_IDLETEETER:
2001-07-17 17:19:20 +02:00
case STATE_JUMP:
case STATE_RUN:
case STATE_FALL:
2001-04-03 23:00:00 +02:00
ret=true;
break;
2001-05-01 20:39:41 +02:00
case STATE_SPRINGUP:
2001-04-03 23:00:00 +02:00
case STATE_FALLFAR:
case STATE_BUTTBOUNCE:
case STATE_BUTTFALL:
case STATE_BUTTLAND:
2001-05-11 22:56:43 +02:00
case STATE_BUTTBOUNCEUP:
2001-04-03 23:00:00 +02:00
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-04-03 23:00:00 +02:00
break;
}
return ret;
}
2001-04-10 21:04:20 +02:00
/*----------------------------------------------------------------------
Function:
Purpose:
Params:
Returns:
---------------------------------------------------------------------- */
2001-07-17 17:19:20 +02:00
DVECTOR jellyLaunchPos={-20,-25};
2001-04-10 21:04:20 +02:00
void CPlayerModeJellyLauncher::launchProjectile()
{
int playerFacing;
DVECTOR launchPos;
int fireHeading;
CPlayerProjectile *projectile;
2001-07-12 20:53:06 +02:00
CSoundMediator::playSfx(CSoundMediator::SFX_JELLY_LAUNCHER);
2001-04-10 21:04:20 +02:00
playerFacing=m_player->getFacing();
launchPos=getPlayerPos();
launchPos.vx+=playerFacing*jellyLaunchPos.vx;
launchPos.vy+=jellyLaunchPos.vy;
if(m_firingTime==TIMEOUT_FOR_BIG_SHOT&&m_player->getJellyAmmo()>=AMMO_AMOUNT_FOR_BIG_SHOT)
{
// Powered up, big shot
int i;
fireHeading=1024+(1024*playerFacing)-512;
for(i=0;i<3;i++)
{
2001-06-14 18:07:48 +02:00
projectile=CPlayerProjectile::Create();
2001-04-10 21:04:20 +02:00
projectile->init(launchPos,
fireHeading,
CPlayerProjectile::PLAYER_PROJECTILE_DUMBFIRE,
CPlayerProjectile::PLAYER_PROJECTILE_FINITE_LIFE,
5*60);
2001-05-25 20:43:47 +02:00
2001-05-22 22:13:36 +02:00
projectile->setRGB( 255 + ( 128 << 8 ) + ( 255 << 16 ) );
2001-04-10 21:04:20 +02:00
fireHeading+=512;
2001-07-17 17:19:20 +02:00
#ifndef __USER_paul__
2001-04-10 21:04:20 +02:00
m_player->useOneJelly();
2001-07-17 17:19:20 +02:00
#endif
2001-04-10 21:04:20 +02:00
}
}
else
{
// Normal, small shot
fireHeading=1024+(1024*m_player->getFacing());
2001-06-14 18:07:48 +02:00
projectile=CPlayerProjectile::Create();
2001-04-10 21:04:20 +02:00
projectile->init(launchPos,
fireHeading,
CPlayerProjectile::PLAYER_PROJECTILE_DUMBFIRE,
CPlayerProjectile::PLAYER_PROJECTILE_FINITE_LIFE,
5*60);
2001-05-25 20:43:47 +02:00
2001-05-22 22:13:36 +02:00
projectile->setRGB( 255 + ( 128 << 8 ) + ( 255 << 16 ) );
2001-07-17 17:19:20 +02:00
#ifndef __USER_paul__
m_player->useOneJelly();
#endif
2001-04-10 21:04:20 +02:00
}
}
2001-06-25 22:25:28 +02:00
/*----------------------------------------------------------------------
Function:
Purpose:
Params:
Returns:
---------------------------------------------------------------------- */
CPlayerState **CPlayerModeJellyLauncher::getStateTable()
{
return s_stateTable;
}
2001-04-03 23:00:00 +02:00
/*===========================================================================
end */