SBSPSS/source/player/pmcoral.cpp

446 lines
11 KiB
C++
Raw Normal View History

2001-03-30 18:09:02 +02:00
/*=========================================================================
pmcoral.cpp
Author: PKG
Created:
Project: Spongebob
Purpose:
Copyright (c) 2001 Climax Development Ltd
===========================================================================*/
/*----------------------------------------------------------------------
Includes
-------- */
#include "player\pmcoral.h"
2001-03-31 20:22:38 +02:00
#ifndef __GFX_SPRBANK_H__
#include "gfx\sprbank.h"
#endif
2001-04-03 18:47:07 +02:00
// States
2001-05-29 17:54:26 +02:00
#ifndef __PLAYER__PSLOOK_H__
#include "player\pslook.h"
2001-05-14 18:43:48 +02:00
#endif
2001-04-03 18:47:07 +02:00
#ifndef __PLAYER__PSJUMP_H__
#include "player\psjump.h"
#endif
2001-05-11 21:49:41 +02:00
#ifndef __PLAYER__PSJMPBCK_H__
#include "player\psjmpbck.h"
#endif
2001-04-03 18:47:07 +02:00
#ifndef __PLAYER__PSRUN_H__
#include "player\psrun.h"
#endif
#ifndef __PLAYER__PSFALL_H__
#include "player\psfall.h"
#endif
2001-04-04 17:40:38 +02:00
#ifndef __PLAYER__PSHITGND_H__
#include "player\pshitgnd.h"
#endif
2001-04-03 18:47:07 +02:00
#ifndef __PLAYER__PSIDLE_H__
#include "player\psidle.h"
#endif
#ifndef __PLAYER__PSDUCK_H__
#include "player\psduck.h"
#endif
2001-05-01 20:39:41 +02:00
#ifndef __PLAYER__PSSPRING_H__
#include "player\psspring.h"
#endif
2001-05-05 00:11:44 +02:00
#ifndef __ENEMY_NPC_H__
#include "enemy\npc.h"
#endif
#ifndef __GAME_GAME_H__
#include "game\game.h"
#endif
2001-05-16 21:45:43 +02:00
#ifndef __PROJECTL_PRNPCSPR_H__
#include "projectl\prnpcspr.h"
2001-05-09 22:46:22 +02:00
#endif
2001-05-11 16:52:35 +02:00
#ifndef __GFX_FONT_H__
#include "gfx\font.h"
#endif
2001-05-24 00:03:53 +02:00
#ifndef __MATHTABLE_HEADER__
#include "utils\mathtab.h"
#endif
2001-03-30 18:09:02 +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-03-31 20:22:38 +02:00
#endif
2001-03-30 18:09:02 +02:00
/*----------------------------------------------------------------------
Tyepdefs && Defines
------------------- */
/*----------------------------------------------------------------------
Structure defintions
-------------------- */
/*----------------------------------------------------------------------
Function Prototypes
------------------- */
/*----------------------------------------------------------------------
Vars
---- */
2001-04-03 18:47:07 +02:00
static CPlayerState *s_stateTable[]=
{
2001-04-10 20:44:12 +02:00
&s_stateWeaponIdle, // STATE_IDLE
&s_stateWeaponIdle, // STATE_IDLETEETER
2001-04-03 18:47:07 +02:00
&s_stateJump, // STATE_JUMP
2001-05-01 20:39:41 +02:00
&s_stateSpring, // STATE_SPRINGUP
2001-04-03 18:47:07 +02:00
&s_stateWalk, // STATE_RUN
&s_stateFall, // STATE_FALL
&s_stateFallFar, // STATE_FALLFAR
2001-04-04 17:40:38 +02:00
&s_stateHitGround, // STATE_HITGROUND
2001-04-03 18:47:07 +02:00
NULL, // STATE_BUTTBOUNCE
NULL, // STATE_BUTTFALL
NULL, // STATE_BUTTLAND
2001-05-11 22:56:43 +02:00
NULL, // STATE_BUTTBOUNCEUP
2001-04-03 18:47:07 +02:00
NULL, // STATE_DUCK
NULL, // STATE_SOAKUP
&s_stateGetUp, // STATE_GETUP
2001-05-29 17:54:26 +02:00
&s_stateLookDown, // STATE_LOOKDOWN
&s_stateLookDownRelax, // STATE_LOOKDOWNRELAX
2001-05-11 21:49:41 +02:00
&s_stateJumpBack, // STATE_JUMPBACK
2001-04-03 18:47:07 +02:00
};
static PlayerMetrics s_playerMetrics=
2001-03-30 18:09:02 +02:00
{ {
2001-05-16 17:48:45 +02:00
DEFAULT_PLAYER_JUMP_VELOCITY, // PM__JUMP_VELOCITY
2001-04-08 20:55:20 +02:00
DEFAULT_PLAYER_MAX_JUMP_FRAMES, // PM__MAX_JUMP_FRAMES
2001-03-30 18:09:02 +02:00
DEFAULT_PLAYER_MAX_SAFE_FALL_FRAMES, // PM__MAX_SAFE_FALL_FRAMES
2001-05-16 17:48:45 +02:00
DEFAULT_PLAYER_MAX_RUN_VELOCITY, // PM__MAX_RUN_VELOCITY
DEFAULT_PLAYER_RUN_SPEEDUP/3, // PM__RUN_SPEEDUP
DEFAULT_PLAYER_RUN_REVERSESLOWDOWN/3, // PM__RUN_REVERSESLOWDOWN
DEFAULT_PLAYER_RUN_SLOWDOWN/3, // PM__RUN_SLOWDOWN
2001-03-30 18:09:02 +02:00
DEFAULT_PLAYER_PLAYER_GRAVITY, // PM__GRAVITY
DEFAULT_PLAYER_TERMINAL_VELOCITY, // PM__TERMINAL_VELOCITY
2001-04-11 17:48:16 +02:00
DEFAULT_BUTT_FALL_VELOCITY, // PM__BUTT_FALL_VELOCITY
2001-05-11 21:49:41 +02:00
DEFAULT_HITREACT_XVELOCITY, // PM__HITREACT_XVELOCITY
DEFAULT_HITREACT_YVELOCITY, // PM__HITREACT_YVELOCITY
DEFAULT_HITREACT_FRAMES, // PM__HITREACT_FRAMES
2001-03-30 18:09:02 +02:00
} };
/*----------------------------------------------------------------------
Function:
Purpose:
Params:
Returns:
---------------------------------------------------------------------- */
void CPlayerModeCoralBlower::enter()
{
2001-05-13 21:28:48 +02:00
CPlayerModeBase::enter();
2001-03-31 20:43:06 +02:00
m_blowerState=BLOWER_STATE__EMPTY;
2001-03-30 18:09:02 +02:00
}
/*----------------------------------------------------------------------
Function:
Purpose:
Params:
Returns:
---------------------------------------------------------------------- */
2001-05-05 00:11:44 +02:00
DVECTOR blowerCatchPos={-110,-20};
DVECTOR blowerCatchSize={180,150};
2001-05-24 00:03:53 +02:00
DVECTOR blowerSuckUpPoint={-20,-20};
DVECTOR blowerLaunchPoint={-20,-20};
2001-03-30 18:09:02 +02:00
void CPlayerModeCoralBlower::think()
{
CPlayerModeBase::think();
2001-03-30 19:47:00 +02:00
switch(m_blowerState)
2001-03-30 18:09:02 +02:00
{
2001-03-30 19:47:00 +02:00
case BLOWER_STATE__EMPTY:
2001-05-11 16:52:35 +02:00
if(getPadInputDown()&PI_CATCH&&getState()==STATE_IDLE)
2001-03-30 19:47:00 +02:00
{
m_blowerState=BLOWER_STATE__SUCKING;
2001-05-05 00:11:44 +02:00
m_enemy=NULL;
2001-03-30 19:47:00 +02:00
}
break;
case BLOWER_STATE__SUCKING:
2001-05-11 16:52:35 +02:00
if(!(getPadInputHeld()&PI_CATCH&&getState()==STATE_IDLE))
2001-03-30 19:47:00 +02:00
{
m_blowerState=BLOWER_STATE__EMPTY;
}
2001-05-05 00:11:44 +02:00
else if(m_enemy==NULL)
{
// Search for an enemy..
DVECTOR playerPos;
int playerFacing;
CRECT suckRect;
CThing *thing;
playerPos=m_player->getPos();
playerFacing=m_player->getFacing();
suckRect.x1=playerPos.vx+(blowerCatchPos.vx*playerFacing)-(blowerCatchSize.vx/2);
suckRect.y1=playerPos.vy+blowerCatchPos.vy-(blowerCatchSize.vy/2);
suckRect.x2=suckRect.x1+blowerCatchSize.vx;
suckRect.y2=suckRect.y1+blowerCatchSize.vy;
#ifdef __USER_paul__
{
CRECT area=suckRect;
DVECTOR ofs=CLevel::getCameraPos();
area.x1-=ofs.vx;
area.y1-=ofs.vy;
area.x2-=ofs.vx;
area.y2-=ofs.vy;
DrawLine(area.x1,area.y1,area.x2,area.y1,255,255,255,0);
DrawLine(area.x2,area.y1,area.x2,area.y2,255,255,255,0);
DrawLine(area.x2,area.y2,area.x1,area.y2,255,255,255,0);
DrawLine(area.x1,area.y2,area.x1,area.y1,255,255,255,0);
}
#endif
thing=CThingManager::checkCollisionAreaAgainstThings(&suckRect,CThing::TYPE_ENEMY,false);
while(thing)
{
if(((CNpcEnemy*)thing)->canBeSuckedUp())
{
m_enemy=(CNpcEnemy*)thing;
thing=NULL;
}
else
{
thing=CThingManager::checkCollisionAreaAgainstThings(&suckRect,CThing::TYPE_ENEMY,true);
}
}
}
else
{
// Got an enemy.. suck him up
if(m_enemy->suckUp(getSuckUpPoint(),1))
{
2001-05-16 23:15:50 +02:00
m_enemyFrame = m_enemy->getFrame();
2001-05-05 00:11:44 +02:00
m_blowerState=BLOWER_STATE__FULL;
}
}
2001-03-30 19:47:00 +02:00
break;
case BLOWER_STATE__FULL:
2001-05-10 00:12:00 +02:00
if(getPadInputDown()&PI_FIRE&&getState()==STATE_IDLE)
2001-03-30 19:47:00 +02:00
{
m_blowerState=BLOWER_STATE__AIMING;
2001-05-24 00:03:53 +02:00
m_launchHeading=0;
m_launchHeadingChangeSpeed=0;
2001-03-30 19:47:00 +02:00
}
break;
case BLOWER_STATE__AIMING:
2001-03-31 20:22:38 +02:00
if(getState()!=STATE_IDLE)
2001-03-30 19:47:00 +02:00
{
2001-03-31 20:22:38 +02:00
m_blowerState=BLOWER_STATE__FULL;
2001-03-30 19:47:00 +02:00
}
2001-05-10 00:12:00 +02:00
else if(!(getPadInputHeld()&PI_FIRE))
2001-03-30 19:47:00 +02:00
{
// Fire!
m_blowerState=BLOWER_STATE__EMPTY;
2001-05-09 22:46:22 +02:00
2001-05-24 00:03:53 +02:00
DVECTOR launchPos=m_player->getPos();
int facing=m_player->getFacing();
int launchHeading;
launchPos.vx+=blowerLaunchPoint.vx*facing;
launchPos.vy+=blowerLaunchPoint.vy;
2001-05-09 22:46:22 +02:00
2001-05-24 00:03:53 +02:00
launchHeading=(-((m_launchHeading+1024)*facing)-1024)&4095;
2001-05-09 22:46:22 +02:00
2001-05-16 21:45:43 +02:00
CEnemyAsSpriteProjectile *projectile;
2001-06-14 18:07:48 +02:00
projectile = CEnemyAsSpriteProjectile::Create();
2001-05-24 00:03:53 +02:00
projectile->init( launchPos,
launchHeading,//1024+(1024*facing),
2001-05-09 22:46:22 +02:00
CPlayerProjectile::PLAYER_PROJECTILE_DUMBFIRE,
CPlayerProjectile::PLAYER_PROJECTILE_FINITE_LIFE,
5*60);
2001-05-25 20:43:47 +02:00
2001-05-09 22:46:22 +02:00
2001-05-16 21:45:43 +02:00
//CActorGfx *projectileGfx;
//projectileGfx=CActorPool::GetActor((FileEquate)ACTORS_SHELL_SBK);
//projectile->setGraphic( projectileGfx );
2001-05-16 23:15:50 +02:00
projectile->setGraphic( m_enemyFrame );
2001-05-16 21:45:43 +02:00
projectile->setHasRGB( false );
2001-03-30 19:47:00 +02:00
}
2001-05-24 00:03:53 +02:00
else
{
int padHeld;
padHeld=getPadInputHeld();
if(padHeld&PI_UP)
{
if(m_launchHeadingChangeSpeed>-BLOWER_AIM_SPEED_INITIAL)
{
m_launchHeadingChangeSpeed=-BLOWER_AIM_SPEED_INITIAL;
}
else
{
if(m_launchHeadingChangeSpeed>-BLOWER_AIM_SPEED_MAXIMUM)
{
m_launchHeadingChangeSpeed--;
}
}
m_launchHeading+=m_launchHeadingChangeSpeed;
if(m_launchHeading<BLOWER_MINIMUM_AIM_ANGLE)
{
m_launchHeading=BLOWER_MINIMUM_AIM_ANGLE;
}
}
else if(padHeld&PI_DOWN)
{
if(m_launchHeadingChangeSpeed<BLOWER_AIM_SPEED_INITIAL)
{
m_launchHeadingChangeSpeed=BLOWER_AIM_SPEED_INITIAL;
}
else
{
if(m_launchHeadingChangeSpeed<BLOWER_AIM_SPEED_MAXIMUM)
{
m_launchHeadingChangeSpeed++;
}
}
m_launchHeading+=m_launchHeadingChangeSpeed;
if(m_launchHeading>BLOWER_MAXIMUM_AIM_ANGLE)
{
m_launchHeading=BLOWER_MAXIMUM_AIM_ANGLE;
}
}
else
{
m_launchHeadingChangeSpeed=0;
}
}
2001-03-30 19:47:00 +02:00
break;
2001-03-30 18:09:02 +02:00
}
}
2001-03-31 20:22:38 +02:00
/*----------------------------------------------------------------------
Function:
Purpose:
Params:
Returns:
---------------------------------------------------------------------- */
void CPlayerModeCoralBlower::renderModeUi()
{
SpriteBank *sb;
sFrameHdr *fh;
2001-05-11 16:52:35 +02:00
// char buf[4];
2001-03-31 20:22:38 +02:00
2001-05-25 20:43:47 +02:00
sb=CGameScene::getSpriteBank();
2001-03-31 20:22:38 +02:00
fh=sb->getFrameHeader(FRM__BLOWER);
if(m_blowerState==BLOWER_STATE__FULL||m_blowerState==BLOWER_STATE__AIMING)
{
// Blower has a creature/object inside
2001-05-02 22:27:49 +02:00
sb->printFT4Scaled(FRM__BLOWER,CPlayer::POWERUPUI_ICONX,CPlayer::POWERUPUI_ICONY,0,0,CPlayer::POWERUPUI_OT,256+128);
2001-05-24 00:03:53 +02:00
if(m_blowerState==BLOWER_STATE__AIMING)
{
// Draw aiming cursor
int facing,heading;
DVECTOR screenOfs,launchPos,targetPos;
facing=m_player->getFacing();
heading=((m_launchHeading+1024)*facing)&4095;
screenOfs=CLevel::getCameraPos();
launchPos=m_player->getPlayerPos();
launchPos.vx+=(blowerLaunchPoint.vx*facing)-screenOfs.vx;
launchPos.vy+=blowerLaunchPoint.vy-screenOfs.vy;
targetPos.vx=launchPos.vx-((msin(heading)*BLOWER_TARGET_DISTANCE)>>12);
targetPos.vy=launchPos.vy-((mcos(heading)*BLOWER_TARGET_DISTANCE)>>12);
heading=((m_launchHeading+1024)*-facing+1024)&4095;
sb->printRotatedScaledSprite(FRM__AIM_ARROW,targetPos.vx,targetPos.vy,8192,8192,heading,0);
}
2001-03-31 20:22:38 +02:00
}
else
{
2001-05-24 00:03:53 +02:00
// Blower is empty
2001-05-02 22:27:49 +02:00
sb->printFT4(fh,CPlayer::POWERUPUI_ICONX,CPlayer::POWERUPUI_ICONY,0,0,CPlayer::POWERUPUI_OT);
2001-03-31 20:22:38 +02:00
}
2001-05-11 16:52:35 +02:00
// sprintf(buf,"x%d",0);
// m_player->getFontBank()->print(CPlayer::POWERUPUI_TEXTX,CPlayer::POWERUPUI_TEXTY,buf);
2001-03-31 20:22:38 +02:00
}
2001-05-24 00:03:53 +02:00
/*----------------------------------------------------------------------
Function:
Purpose:
Params:
Returns:
---------------------------------------------------------------------- */
int CPlayerModeCoralBlower::canDoLookAround()
{
return m_blowerState!=BLOWER_STATE__AIMING;
}
2001-03-30 18:09:02 +02:00
/*----------------------------------------------------------------------
Function:
Purpose:
Params:
Returns:
---------------------------------------------------------------------- */
const struct PlayerMetrics *CPlayerModeCoralBlower::getPlayerMetrics()
{
return &s_playerMetrics;
}
2001-04-03 18:47:07 +02:00
/*----------------------------------------------------------------------
Function:
Purpose:
Params:
Returns:
---------------------------------------------------------------------- */
CPlayerState **CPlayerModeCoralBlower::getStateTable()
{
return s_stateTable;
}
2001-05-05 00:11:44 +02:00
/*----------------------------------------------------------------------
Function:
Purpose:
Params:
Returns:
---------------------------------------------------------------------- */
DVECTOR *CPlayerModeCoralBlower::getSuckUpPoint()
{
static DVECTOR suckUpPoint;
suckUpPoint=getPlayerPos();
suckUpPoint.vx+=blowerSuckUpPoint.vx*m_player->getFacing();
suckUpPoint.vy+=blowerSuckUpPoint.vy;
return &suckUpPoint;
}
2001-03-30 18:09:02 +02:00
/*===========================================================================
end */