SBSPSS/source/player/pmnet.cpp

454 lines
10 KiB
C++
Raw Normal View History

2001-03-31 19:39:17 +02:00
/*=========================================================================
pmnet.cpp
Author: PKG
Created:
Project: Spongebob
Purpose:
Copyright (c) 2001 Climax Development Ltd
===========================================================================*/
/*----------------------------------------------------------------------
Includes
-------- */
#include "player\pmnet.h"
2001-03-31 20:22:38 +02:00
#ifndef __GFX_SPRBANK_H__
#include "gfx\sprbank.h"
#endif
2001-04-08 21:03:08 +02:00
#ifndef __ENEMY_NPC_H__
#include "enemy\npc.h"
#endif
#ifndef __PROJECTL_PROJECTL_H__
#include "projectl\projectl.h"
#endif
#ifndef __GAME_GAME_H__
#include "game\game.h"
#endif
2001-05-01 01:01:55 +02:00
#ifndef __UTILS_HEADER__
2001-05-11 02:36:17 +02:00
#include "utils\utils.h"
#endif
#ifndef __GFX_FONT_H__
#include "gfx\font.h"
2001-05-01 01:01:55 +02:00
#endif
2001-04-08 21:03:08 +02:00
2001-06-21 21:11:35 +02:00
// States
#ifndef __PLAYER__PSBUTT_H__
#include "player\psbutt.h"
#endif
#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__PSDUCK_H__
#include "player\psduck.h"
#endif
#ifndef __PLAYER__PSSPRING_H__
#include "player\psspring.h"
#endif
2001-07-03 00:57:52 +02:00
#ifndef __PLAYER_PSDANCE_H__
#include "player\psdance.h"
#endif
2001-07-03 23:30:32 +02:00
#ifndef __PLAYER_PSSWAL_H__
#include "player\psswal.h"
#endif
2001-03-31 19:39:17 +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-31 19:39:17 +02:00
/*----------------------------------------------------------------------
Tyepdefs && Defines
------------------- */
/*----------------------------------------------------------------------
Structure defintions
-------------------- */
/*----------------------------------------------------------------------
Function Prototypes
------------------- */
/*----------------------------------------------------------------------
Vars
---- */
2001-06-21 21:11:35 +02:00
static CPlayerState *s_stateTable[]=
{
&s_stateNetIdle, // 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
NULL, // STATE_CART
NULL, // STATE_FLOAT
2001-07-03 00:57:52 +02:00
&s_stateDance, // STATE_CELEBRATE
2001-07-03 23:30:32 +02:00
&s_stateSwallow, // STATE_SWALLOW
2001-06-21 21:11:35 +02:00
};
2001-05-01 01:01:55 +02:00
// Net pulse
int npspeed=150;
int npsize=40;
2001-03-31 19:39:17 +02:00
/*----------------------------------------------------------------------
Function:
Purpose:
Params:
Returns:
---------------------------------------------------------------------- */
void CPlayerModeNet::enter()
{
2001-05-13 21:28:48 +02:00
CPlayerModeBase::enter();
2001-05-11 02:36:17 +02:00
m_netState=NET_STATE__INERT;
2001-03-31 19:39:17 +02:00
}
/*----------------------------------------------------------------------
Function:
Purpose:
Params:
Returns:
---------------------------------------------------------------------- */
2001-05-15 22:17:51 +02:00
DVECTOR netCatchPos[17]= // Oh.. why not, eh?
{
{ 64-42, -128+102 },
{ 64-15, -128+86 },
{ 64-42, -128+33 },
{ 64-42, -128+33 },
{ 64-42, -128+33 },
{ 64-80, -128+35 },
{ 64-80, -128+35 },
{ 64-95, -128+64 },
{ 64-95, -128+64 },
{ 64-114, -128+110 },
{ 64-114, -128+110 },
{ 64-114, -128+110 },
{ 64-95, -128+64 },
{ 64-80, -128+35 },
{ 64-42, -128+33 },
{ 64-15, -128+86 },
{ 64-42, -128+102 },
};
2001-05-11 02:36:17 +02:00
DVECTOR netCatchSize={50,30};
DVECTOR netLaunchPos={-15,-90};
2001-03-31 19:39:17 +02:00
void CPlayerModeNet::think()
{
// If we're netting 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 ;)
2001-05-11 02:36:17 +02:00
if(m_netState!=NET_STATE__INERT)
2001-03-31 19:39:17 +02:00
{
setAnimNo(m_savedAnimNo);
setAnimFrame(m_savedAnimFrame);
}
CPlayerModeBase::think();
2001-04-06 23:25:18 +02:00
// Netting?
2001-05-11 02:36:17 +02:00
switch(m_netState)
2001-04-06 23:25:18 +02:00
{
2001-05-11 02:36:17 +02:00
case NET_STATE__INERT:
{
int padDown;
padDown=getPadInputDown();
if(padDown&(PI_CATCH|PI_FIRE)&&canSwingNetFromThisState())
2001-04-06 23:25:18 +02:00
{
2001-05-16 18:47:29 +02:00
if(padDown&PI_CATCH&&!m_player->isJellyFishAmmoFull())
2001-05-01 21:10:10 +02:00
{
2001-05-11 02:36:17 +02:00
m_netState=NET_STATE__CATCHING;
2001-05-01 21:10:10 +02:00
}
2001-05-16 18:47:29 +02:00
else if(padDown&PI_FIRE&&m_player->getJellyFishAmmo())
2001-04-06 23:25:18 +02:00
{
2001-05-11 02:36:17 +02:00
m_netState=NET_STATE__LAUNCHING;
2001-04-06 23:25:18 +02:00
}
2001-05-11 02:36:17 +02:00
m_netFrame=0;
2001-04-06 23:25:18 +02:00
}
2001-05-11 02:36:17 +02:00
}
break;
2001-04-06 23:25:18 +02:00
2001-05-11 02:36:17 +02:00
case NET_STATE__CATCHING:
{
2001-07-23 21:26:37 +02:00
// DVECTOR catchPos;
// DVECTOR playerPos;
2001-05-11 02:36:17 +02:00
int playerFacing;
CRECT netRect;
CThing *thing;
2001-04-07 00:21:01 +02:00
2001-05-15 22:17:51 +02:00
ASSERT(m_netFrame<(int)(sizeof(netCatchPos)/sizeof(DVECTOR)));
2001-07-23 21:26:37 +02:00
DVECTOR const &catchPos=netCatchPos[m_netFrame];
DVECTOR const &playerPos=m_player->getPos();
2001-05-11 02:36:17 +02:00
playerFacing=m_player->getFacing();
2001-04-07 00:21:01 +02:00
2001-05-15 22:17:51 +02:00
netRect.x1=playerPos.vx+(catchPos.vx*playerFacing)-(netCatchSize.vx/2);
netRect.y1=playerPos.vy+catchPos.vy-(netCatchSize.vy/2);
2001-05-11 02:36:17 +02:00
netRect.x2=netRect.x1+netCatchSize.vx;
netRect.y2=netRect.y1+netCatchSize.vy;
2001-04-07 00:21:01 +02:00
2001-05-15 22:17:51 +02:00
/*
2001-05-11 02:36:17 +02:00
#ifdef __USER_paul__
{
CRECT area=netRect;
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
2001-05-15 22:17:51 +02:00
*/
2001-04-07 00:21:01 +02:00
2001-05-11 02:36:17 +02:00
thing=CThingManager::checkCollisionAreaAgainstThings(&netRect,CThing::TYPE_ENEMY,false);
while(thing)
{
if(((CNpcEnemy*)thing)->canBeCaughtByNet())
{
m_netState=NET_STATE__JUST_CAUGHT_SOMETHING;
2001-05-16 18:47:29 +02:00
if(m_player->getJellyFishAmmo()==0)
2001-05-11 02:36:17 +02:00
{
m_netSin=0;
}
2001-07-12 18:47:11 +02:00
m_player->giveJellyFishAmmo();
2001-05-29 16:51:59 +02:00
((CNpcEnemy*)thing)->caughtWithNet();
thing=NULL;
2001-05-11 02:36:17 +02:00
}
else
{
thing=CThingManager::checkCollisionAreaAgainstThings(&netRect,CThing::TYPE_ENEMY,true);
}
}
}
break;
2001-05-11 00:35:39 +02:00
2001-05-11 02:36:17 +02:00
case NET_STATE__JUST_CAUGHT_SOMETHING:
break;
2001-04-07 00:21:01 +02:00
2001-05-11 02:36:17 +02:00
case NET_STATE__LAUNCHING:
// Launch projectile at halfway through the swing..
if(m_netFrame==4)
{
CPlayerProjectile *projectile;
int playerFacing;
int fireHeading;
DVECTOR launchPos;
playerFacing=m_player->getFacing();
fireHeading=1024+(512*playerFacing);
launchPos=m_player->getPos();
launchPos.vx+=netLaunchPos.vx*playerFacing;
launchPos.vy+=netLaunchPos.vy;
2001-06-14 18:07:48 +02:00
projectile = CPlayerProjectile::Create();
2001-05-11 02:36:17 +02:00
projectile->init( launchPos,
fireHeading,
2001-06-11 17:42:07 +02:00
CPlayerProjectile::PLAYER_PROJECTILE_BOUNCING,
2001-05-11 02:36:17 +02:00
CPlayerProjectile::PLAYER_PROJECTILE_FINITE_LIFE,
5*60);
2001-05-25 20:43:47 +02:00
2001-05-11 02:36:17 +02:00
projectile->updateCollisionArea();
2001-07-12 18:47:11 +02:00
projectile->setRGB(255+(128<<8)+(255<<16));
2001-05-11 02:36:17 +02:00
m_netState=NET_STATE__JUST_LAUNCHED_SOMETHING;
2001-05-16 18:47:29 +02:00
m_player->useOneJellyFishAmmo();
2001-05-11 02:36:17 +02:00
}
break;
2001-04-06 23:25:18 +02:00
2001-05-11 02:36:17 +02:00
case NET_STATE__JUST_LAUNCHED_SOMETHING:
break;
}
2001-03-31 19:39:17 +02:00
2001-05-11 02:36:17 +02:00
if(m_netState!=NET_STATE__INERT)
{
2001-04-09 22:08:56 +02:00
m_player->setAnimNo(ANIM_SPONGEBOB_SWIPE);
2001-03-31 19:39:17 +02:00
m_player->setAnimFrame(m_netFrame);
m_netFrame++;
if(m_netFrame>=m_player->getAnimFrameCount())
{
m_player->setAnimNo(m_savedAnimNo);
m_player->setAnimFrame(m_savedAnimFrame);
2001-04-06 23:25:18 +02:00
2001-05-11 02:36:17 +02:00
m_netState=NET_STATE__INERT;
2001-03-31 19:39:17 +02:00
}
}
2001-05-01 01:01:55 +02:00
2001-05-16 18:47:29 +02:00
if(m_player->getJellyFishAmmo())
2001-05-01 01:01:55 +02:00
{
m_netSin=(m_netSin+npspeed)&4095;
}
2001-03-31 19:39:17 +02:00
}
2001-03-31 20:22:38 +02:00
/*----------------------------------------------------------------------
Function:
Purpose:
Params:
Returns:
---------------------------------------------------------------------- */
2001-05-03 22:17:44 +02:00
void CPlayerModeNet::renderModeUi()
2001-03-31 20:22:38 +02:00
{
SpriteBank *sb;
sFrameHdr *fh;
2001-05-11 02:36:17 +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-07-16 22:55:33 +02:00
fh=sb->getFrameHeader(FRM__SMALL_NET);
2001-05-16 18:47:29 +02:00
if(m_player->getJellyFishAmmo())
2001-03-31 20:22:38 +02:00
{
2001-05-03 22:17:44 +02:00
POLY_FT4 *ft4;
2001-03-31 20:22:38 +02:00
// Net has a jellyfish inside
2001-05-29 16:51:59 +02:00
int size=256+128+((msin(m_netSin)*npsize)>>12);
u32 colour;
2001-05-02 22:27:49 +02:00
sb->printFT4Scaled(fh,CPlayer::POWERUPUI_ICONX,CPlayer::POWERUPUI_ICONY,0,0,CPlayer::POWERUPUI_OT,size);
2001-05-03 22:17:44 +02:00
ft4=sb->printFT4Scaled(FRM__NETBLOB,CPlayer::POWERUPUI_ICONX+17,CPlayer::POWERUPUI_ICONY,0,0,CPlayer::POWERUPUI_OT,size);
setShadeTex(ft4,0);
2001-07-12 18:47:11 +02:00
setRGB0(ft4,255,128,255);
2001-03-31 20:22:38 +02:00
}
2001-05-01 17:06:27 +02:00
else
{
2001-05-02 22:27:49 +02:00
sb->printFT4(fh,CPlayer::POWERUPUI_ICONX,CPlayer::POWERUPUI_ICONY,0,0,CPlayer::POWERUPUI_OT);
2001-05-01 17:06:27 +02:00
}
2001-05-11 02:36:17 +02:00
2001-05-16 18:47:29 +02:00
sprintf(buf,"x%d",m_player->getJellyFishAmmo());
2001-05-11 02:36:17 +02:00
m_player->getFontBank()->print(CPlayer::POWERUPUI_TEXTX,CPlayer::POWERUPUI_TEXTY,buf);
2001-03-31 20:22:38 +02:00
}
2001-03-31 19:39:17 +02:00
/*----------------------------------------------------------------------
Function:
Purpose:
Params:
Returns:
---------------------------------------------------------------------- */
void CPlayerModeNet::setAnimNo(int _animNo)
{
CPlayerModeBase::setAnimNo(_animNo);
m_savedAnimNo=_animNo;
}
void CPlayerModeNet::setAnimFrame(int _animFrame)
{
CPlayerModeBase::setAnimFrame(_animFrame);
m_savedAnimFrame=_animFrame;
}
2001-06-21 21:11:35 +02:00
/*----------------------------------------------------------------------
Function:
Purpose:
Params:
Returns:
---------------------------------------------------------------------- */
CPlayerState **CPlayerModeNet::getStateTable()
{
return s_stateTable;
}
2001-03-31 19:39:17 +02:00
/*----------------------------------------------------------------------
Function:
Purpose:
Params:
Returns:
---------------------------------------------------------------------- */
int CPlayerModeNet::canSwingNetFromThisState()
{
int ret=false;
switch(getState())
{
case STATE_IDLE:
case STATE_IDLETEETER:
case STATE_JUMP:
case STATE_RUN:
case STATE_FALL:
ret=true;
break;
2001-05-01 20:39:41 +02:00
case STATE_SPRINGUP:
2001-03-31 19:39:17 +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-03-31 19:39:17 +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-03-31 19:39:17 +02:00
break;
}
return ret;
}
/*===========================================================================
end */