SBSPSS/source/player/pmnet.cpp

316 lines
7.0 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__
#include "utils\utils.h"
#endif
2001-04-08 21:03:08 +02:00
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-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()
{
m_netting=false;
m_netState=NET_STATE__EMPTY;
}
/*----------------------------------------------------------------------
Function:
Purpose:
Params:
Returns:
---------------------------------------------------------------------- */
2001-05-01 21:10:10 +02:00
DVECTOR netCatchPos={0,-80};
DVECTOR netCatchSize={30,30};
2001-04-08 21:03:08 +02:00
DVECTOR netLaunchPos={-10,-70};
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 ;)
if(m_netting)
{
setAnimNo(m_savedAnimNo);
setAnimFrame(m_savedAnimFrame);
}
CPlayerModeBase::think();
// Start to net?
if(!m_netting&&getPadInputDown()&PI_ACTION&&canSwingNetFromThisState())
{
m_netFrame=0;
m_netting=true;
2001-04-06 23:25:18 +02:00
}
// Netting?
if(m_netting)
{
2001-03-31 19:39:17 +02:00
switch(m_netState)
{
case NET_STATE__EMPTY:
2001-04-06 23:25:18 +02:00
{
DVECTOR playerPos;
int playerFacing;
CRECT netRect;
CThing *thing;
playerPos=m_player->getPos();
playerFacing=m_player->getFacing();
2001-05-01 21:10:10 +02:00
netRect.x1=playerPos.vx+(netCatchPos.vx*playerFacing)-(netCatchSize.vx/2);
netRect.y1=playerPos.vy+netCatchPos.vy-(netCatchSize.vy/2);
netRect.x2=netRect.x1+netCatchSize.vx;
netRect.y2=netRect.y1+netCatchSize.vy;
#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-04-06 23:25:18 +02:00
thing=CThingManager::checkCollisionAreaAgainstThings(&netRect,CThing::TYPE_ENEMY,false);
while(thing)
{
2001-04-07 00:21:01 +02:00
if(((CNpcEnemy*)thing)->canBeCaughtByNet())
2001-04-06 23:25:18 +02:00
{
2001-04-07 00:21:01 +02:00
((CNpcEnemy*)thing)->caughtWithNet();
2001-04-06 23:25:18 +02:00
m_netState=NET_STATE__JUST_CAUGHT_SOMETHING;
thing=NULL;
2001-05-01 01:01:55 +02:00
m_netSin=0;
2001-04-06 23:25:18 +02:00
}
else
{
thing=CThingManager::checkCollisionAreaAgainstThings(&netRect,CThing::TYPE_ENEMY,true);
}
}
}
break;
case NET_STATE__JUST_CAUGHT_SOMETHING:
2001-03-31 19:39:17 +02:00
break;
2001-04-06 23:25:18 +02:00
2001-03-31 19:39:17 +02:00
case NET_STATE__FULL:
2001-04-06 23:25:18 +02:00
if(m_netFrame==0)
{
// Launch projectile at halfway through the swing..
2001-04-07 00:21:01 +02:00
CPlayerProjectile *projectile;
2001-04-08 21:03:08 +02:00
int playerFacing;
int fireHeading;
DVECTOR launchPos;
2001-04-07 00:21:01 +02:00
2001-04-08 21:03:08 +02:00
playerFacing=m_player->getFacing();
2001-05-02 22:42:32 +02:00
fireHeading=1024+(800*playerFacing);
2001-04-08 21:03:08 +02:00
launchPos=m_player->getPos();
launchPos.vx+=netLaunchPos.vx*playerFacing;
launchPos.vy+=netLaunchPos.vy;
2001-04-07 00:21:01 +02:00
projectile = new( "user projectile" ) CPlayerProjectile;
2001-04-08 21:03:08 +02:00
projectile->init( launchPos,
2001-04-07 00:21:01 +02:00
fireHeading,
CPlayerProjectile::PLAYER_PROJECTILE_DUMBFIRE,
CPlayerProjectile::PLAYER_PROJECTILE_FINITE_LIFE,
2001-04-08 21:03:08 +02:00
5*60);
2001-04-12 18:33:48 +02:00
projectile->setLayerCollision( m_player->getLayerCollision() );
2001-04-07 00:21:01 +02:00
2001-04-06 23:25:18 +02:00
m_netState=NET_STATE__JUST_LAUNCHED_SOMETHING;
}
break;
case NET_STATE__JUST_LAUNCHED_SOMETHING:
2001-03-31 19:39:17 +02:00
break;
}
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);
m_netting=false;
2001-04-06 23:25:18 +02:00
if(m_netState==NET_STATE__JUST_CAUGHT_SOMETHING)
{
m_netState=NET_STATE__FULL;
}
else if(m_netState==NET_STATE__JUST_LAUNCHED_SOMETHING)
{
m_netState=NET_STATE__EMPTY;
}
2001-03-31 19:39:17 +02:00
}
}
2001-05-01 01:01:55 +02:00
if(m_netState==NET_STATE__FULL)
{
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;
sb=m_player->getSpriteBank();
fh=sb->getFrameHeader(FRM__NET);
2001-05-01 17:06:27 +02:00
if(m_netState==NET_STATE__FULL)
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-01 01:01:55 +02:00
int size=256+128+((msin(m_netSin)*npsize)>>12);
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);
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-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;
}
/*----------------------------------------------------------------------
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:
case STATE_DUCK:
case STATE_SOAKUP:
case STATE_GETUP:
break;
}
return ret;
}
/*===========================================================================
end */