SBSPSS/source/player/pmjelly.cpp

317 lines
6.9 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"
#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-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
---- */
/*----------------------------------------------------------------------
Function:
Purpose:
Params:
Returns:
---------------------------------------------------------------------- */
2001-04-03 23:36:35 +02:00
void CPlayerModeJellyLauncher::enter()
2001-04-03 23:00:00 +02:00
{
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-04-08 22:19:53 +02:00
DVECTOR jellyLaunchPos={-20,-40};
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);
fc=m_player->getAnimFrameCount();
if(m_firingTime>=fc)
{
frame=fc;
}
else
{
frame=m_firingTime;
}
m_player->setAnimFrame(frame);
2001-04-08 20:57:16 +02:00
}
else
{
m_firingState=FIRING_STATE__FIRING;
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
sb=m_player->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:
// 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:
case STATE_DUCK:
case STATE_SOAKUP:
case STATE_GETUP:
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:
case STATE_DUCK:
case STATE_SOAKUP:
case STATE_GETUP:
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++)
{
projectile=new("JellyProjectile") CPlayerProjectile;
projectile->init(launchPos,
fireHeading,
CPlayerProjectile::PLAYER_PROJECTILE_DUMBFIRE,
CPlayerProjectile::PLAYER_PROJECTILE_FINITE_LIFE,
5*60);
2001-04-12 18:33:48 +02:00
projectile->setLayerCollision( m_player->getLayerCollision() );
2001-04-10 21:04:20 +02:00
fireHeading+=512;
m_player->useOneJelly();
}
}
else
{
// Normal, small shot
fireHeading=1024+(1024*m_player->getFacing());
projectile=new("JellyProjectile") CPlayerProjectile;
projectile->init(launchPos,
fireHeading,
CPlayerProjectile::PLAYER_PROJECTILE_DUMBFIRE,
CPlayerProjectile::PLAYER_PROJECTILE_FINITE_LIFE,
5*60);
2001-04-12 18:33:48 +02:00
projectile->setLayerCollision( m_player->getLayerCollision() );
2001-04-10 21:04:20 +02:00
m_player->useOneJelly();
}
}
2001-04-03 23:00:00 +02:00
/*===========================================================================
end */