SBSPSS/source/player/pmjelly.cpp

436 lines
9.6 KiB
C++
Raw Normal View History

2001-04-03 23:00:00 +02:00
/*=========================================================================
pmjelly.cpp
Author: PKG
Created:
Project: Spongebob
Purpose:
Copyright (c) 2001 Climax Development Ltd
===========================================================================*/
/*----------------------------------------------------------------------
Includes
-------- */
#include "player\pmjelly.h"
2001-06-28 21:14:44 +02:00
#ifndef __PAD_VIBE_H__
#include "pad\vibe.h"
#endif
2001-04-03 23:00:00 +02:00
#ifndef __GFX_SPRBANK_H__
#include "gfx\sprbank.h"
#endif
2001-04-08 20:57:16 +02:00
#ifndef __UTILS_HEADER__
#include "utils\utils.h"
#endif
#ifndef __PROJECTL_PROJECTL_H__
#include "projectl\projectl.h"
#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
// 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;
m_player->giveJellyAmmo();
2001-04-03 23:00:00 +02:00
}
/*----------------------------------------------------------------------
Function:
Purpose:
Params:
Returns:
---------------------------------------------------------------------- */
2001-05-18 18:17:16 +02:00
DVECTOR jellyLaunchPos={-20,-25};
2001-04-03 23:36:35 +02:00
void CPlayerModeJellyLauncher::think()
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;
}
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
{
2001-04-10 21:04:20 +02:00
int fc,frame;
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
m_player->setAnimNo(ANIM_SPONGEBOB_FIRESTART);
2001-06-28 23:21:14 +02:00
fc=m_player->getAnimFrameCount()-1;
2001-04-10 21:04:20 +02:00
if(m_firingTime>=fc)
{
frame=fc;
}
else
{
frame=m_firingTime;
}
m_player->setAnimFrame(frame);
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
{
m_firingState=FIRING_STATE__FIRING;
2001-06-28 21:14:44 +02:00
CPadVibrationManager::setVibration(0,CPadVibrationManager::VIBE_MEDIUM);
2001-04-26 23:15:36 +02:00
m_player->setAnimNo(ANIM_SPONGEBOB_FIREEND);
2001-04-10 21:04:20 +02:00
launchProjectile();
2001-04-08 20:57:16 +02:00
}
break;
case FIRING_STATE__FIRING:
m_player->setAnimFrame(m_firingFrame++);
if(m_firingFrame>=m_player->getAnimFrameCount())
{
2001-04-10 21:04:20 +02:00
// Finished recoil
2001-04-08 20:57:16 +02:00
setState(STATE_IDLE);
m_firingState=FIRING_STATE__NONE;
}
break;
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-04-26 23:19:53 +02:00
fh=sb->getFrameHeader(FRM__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-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:
{
int rotRange,scaleBase,scaleRange;
int xs,ys,rot;
rotRange=m_firingTime;
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-05-02 22:27:49 +02:00
sb->printRotatedScaledSprite(fh,CPlayer::POWERUPUI_ICONX+(fh->W/2),CPlayer::POWERUPUI_ICONY+(fh->H/2),xs,ys,rot,CPlayer::POWERUPUI_OT);
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::setState(int _state)
2001-04-03 23:00:00 +02:00
{
2001-04-08 20:57:16 +02:00
int allowChange;
2001-04-03 23:00:00 +02:00
2001-04-08 20:57:16 +02:00
allowChange=true;
if(m_firingState!=FIRING_STATE__NONE)
{
switch(_state)
{
case STATE_FALL:
2001-05-11 21:49:41 +02:00
case STATE_JUMPBACK:
2001-04-08 20:57:16 +02:00
// Break out of firing state!
m_firingState=FIRING_STATE__NONE;
break;
case STATE_IDLE:
case STATE_IDLETEETER:
case STATE_JUMP:
2001-05-01 20:39:41 +02:00
case STATE_SPRINGUP:
2001-04-08 20:57:16 +02:00
case STATE_RUN:
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-08 20:57:16 +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-04-08 20:57:16 +02:00
allowChange=false;
break;
}
}
if(allowChange)
{
return CPlayerModeBase::setState(_state);
}
else
{
return false;
}
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:
ret=true;
break;
2001-04-08 20:57:16 +02:00
case STATE_JUMP:
2001-05-01 20:39:41 +02:00
case STATE_SPRINGUP:
2001-04-08 20:57:16 +02:00
case STATE_RUN:
case STATE_FALL:
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:
---------------------------------------------------------------------- */
void CPlayerModeJellyLauncher::launchProjectile()
{
int playerFacing;
DVECTOR launchPos;
int fireHeading;
CPlayerProjectile *projectile;
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;
m_player->useOneJelly();
}
}
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-04-10 21:04:20 +02:00
m_player->useOneJelly();
}
}
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 */