SBSPSS/source/fx/fx.cpp

500 lines
11 KiB
C++
Raw Normal View History

2001-05-05 20:12:30 +02:00
/*********************/
/*** FX Base Class ***/
/*********************/
#include "system\global.h"
#include <DStructs.h>
#include "utils\utils.h"
#include "gfx\prim.h"
#include "gfx\sprbank.h"
#include <sprites.h>
#include "level\level.h"
2001-05-09 21:57:57 +02:00
#include "gfx\otpos.h"
2001-06-19 23:19:01 +02:00
#include "player\player.h"
2001-05-05 20:12:30 +02:00
#include "FX\FX.h"
#include "FX\FXjfish.h"
2001-05-23 22:00:25 +02:00
#include "FX\FXBaseTrail.h"
#include "FX\FXBaseAnim.h"
2001-07-03 22:52:09 +02:00
//#include "FX\FXBaseEmitter.h"
2001-05-31 22:07:48 +02:00
2001-06-12 01:37:59 +02:00
2001-06-18 18:31:24 +02:00
#include "FX\FXLaser.h"
2001-06-12 22:20:52 +02:00
#include "FX\FXThwack.h"
2001-06-01 17:10:05 +02:00
#include "FX\FXBubble.h"
2001-07-21 21:06:07 +02:00
#include "FX\FXFire.h"
2001-05-16 21:06:02 +02:00
#include "FX\FXfallingTile.h"
2001-05-18 22:54:43 +02:00
#include "FX\FXSteam.h"
2001-06-19 23:19:01 +02:00
#include "FX\FXGeyser.h"
2001-07-02 21:29:20 +02:00
#include "FX\FXSmoke.h"
2001-05-05 20:12:30 +02:00
2001-05-31 22:07:48 +02:00
#include "FX\FXNrgBar.h"
2001-07-02 21:29:20 +02:00
#include "FX\FXTVExplode.h"
2001-07-05 18:01:05 +02:00
#include "FX\FXZzzz.h"
2001-05-05 20:12:30 +02:00
2001-05-31 22:07:48 +02:00
/*****************************************************************************/
/*****************************************************************************/
/*****************************************************************************/
// Anim Data
2001-06-12 01:37:59 +02:00
2001-06-19 23:19:01 +02:00
CFX::sFXRGB CFX::FXRGBTable[CFX::FX_RGB_MAX]=
2001-05-31 22:07:48 +02:00
{
2001-06-19 23:19:01 +02:00
{127,127,255}, // Water
2001-07-19 20:57:28 +02:00
{0,255,0}, // Acid
2001-06-19 23:19:01 +02:00
{255, 0, 0}, // Lava
{ 64, 64, 64}, // Oil
2001-05-31 22:07:48 +02:00
};
2001-05-05 20:12:30 +02:00
2001-06-19 23:19:01 +02:00
CFX::sFXRGB FXRgbWater={127,127,255};
2001-06-01 00:02:07 +02:00
2001-06-19 23:19:01 +02:00
/*****************************************************************************/
CFXBaseAnim::sFXBaseData FXDropBaseData=
2001-06-01 00:02:07 +02:00
{
2001-06-19 23:19:01 +02:00
FRM__DRIP,FRM__DRIP,1,
FX_FLAG_LOOP | FX_FLAG_COLLIDE_KILL | FX_FLAG_HAS_GRAVITY | FX_FLAG_NO_THINK_KILL,
2001-07-04 22:42:42 +02:00
0,CSoundMediator::SFX_HAZARD__ACID_DROP,
2001-06-01 00:02:07 +02:00
};
2001-06-19 23:19:01 +02:00
CFXBaseAnim::sFXBaseData FXSplashBaseData=
2001-06-01 00:02:07 +02:00
{
2001-06-19 23:19:01 +02:00
FRM__SPLASH001,FRM__SPLASH006,1,
FX_FLAG_NO_THINK_KILL,
2001-07-04 22:42:42 +02:00
0,0,
2001-06-01 00:02:07 +02:00
};
2001-06-19 23:19:01 +02:00
CFXBaseAnim::sFXBaseData FXExplodeBaseData=
2001-06-01 00:02:07 +02:00
{
2001-07-02 21:29:20 +02:00
FRM__EXPLOSION0001,FRM__EXPLOSION0008,1,
2001-06-19 23:19:01 +02:00
FX_FLAG_NO_THINK_KILL,
2001-07-04 22:42:42 +02:00
CSoundMediator::SFX_HAZARD__FIREBALL_LAND,0,
2001-06-01 17:10:05 +02:00
};
2001-06-19 23:19:01 +02:00
CFXBaseAnim::sFXBaseData FXFireBaseData=
2001-06-01 17:10:05 +02:00
{
2001-06-19 23:19:01 +02:00
FRM__FIRE01,FRM__FIRE08,1,
FX_FLAG_LOOP | FX_FLAG_TRANS,
2001-07-04 22:42:42 +02:00
0,0,
2001-06-01 17:10:05 +02:00
};
2001-05-23 21:27:05 +02:00
2001-06-19 23:19:01 +02:00
CFXBaseAnim::sFXBaseData FXBubbleBaseData=
2001-06-12 01:37:59 +02:00
{
2001-06-19 23:19:01 +02:00
FRM__BUBBLE_2,FRM__BUBBLE_2,1,
2001-07-13 21:55:22 +02:00
FX_FLAG_LOOP | FX_FLAG_COLLIDE_KILL | FX_FLAG_NO_THINK_KILL,
2001-07-04 22:42:42 +02:00
0,0,
2001-06-12 01:37:59 +02:00
};
2001-05-21 20:11:30 +02:00
/*****************************************************************************/
2001-06-19 23:19:01 +02:00
/*
2001-06-18 18:31:24 +02:00
CFXLaser *TestFXPtr=0;
void TestFX(DVECTOR Pos,CThing *Parent)
2001-05-21 20:11:30 +02:00
{
if (!TestFXPtr)
{
2001-06-18 18:31:24 +02:00
TestFXPtr=(CFXLaser*)CFX::Create(CFX::FX_TYPE_LASER,Parent);
// TestFXPtr->setLife(32);
// TestFXPtr=0;
2001-05-21 20:11:30 +02:00
}
else
{
2001-05-31 22:07:48 +02:00
TestFXPtr->killFX();
2001-05-21 20:11:30 +02:00
TestFXPtr=0;
}
}
2001-06-19 23:19:01 +02:00
*/
2001-05-23 21:27:05 +02:00
/*****************************************************************************/
2001-06-19 23:19:01 +02:00
2001-07-21 21:06:07 +02:00
int FXType=(CFX::FX_TYPE)CFX::FX_TYPE_FLAMES;
2001-06-18 18:31:24 +02:00
2001-07-05 18:01:05 +02:00
#include "game\game.h"
CFXZZZZ *TFX=0;
2001-06-12 01:37:59 +02:00
void TestFX(DVECTOR Pos,CThing *Parent)
2001-05-23 21:27:05 +02:00
{
2001-07-21 21:06:07 +02:00
/*
2001-07-05 18:01:05 +02:00
if (!TFX)
{
TFX=(CFXZZZZ*)CFX::Create((CFX::FX_TYPE)FXType,Pos);
}
else
{
TFX->killFX();
TFX=0;
}
2001-07-21 21:06:07 +02:00
*/
CFX::Create((CFX::FX_TYPE)FXType,Pos);
2001-06-19 23:19:01 +02:00
2001-05-23 21:27:05 +02:00
}
2001-06-19 23:19:01 +02:00
2001-05-05 20:12:30 +02:00
/*****************************************************************************/
2001-05-16 21:06:02 +02:00
CFX *CFX::Create(const FX_TYPE Type)
2001-05-05 20:12:30 +02:00
{
CFX *NewFX;
2001-05-25 20:43:47 +02:00
NewFX = (CFX*)CThingManager::GetThing(CThing::TYPE_FX,Type);
if (!NewFX)
2001-05-05 20:12:30 +02:00
switch(Type)
{
2001-06-18 18:31:24 +02:00
case FX_TYPE_NONE:
ASSERT(!"FX NONE CANT BE CREATED!");
break;
2001-06-19 23:19:01 +02:00
2001-07-02 21:29:20 +02:00
case FX_TYPE_BASE_ANIM:
NewFX=new ("FXBaseAnim") CFXBaseAnim();
break;
2001-06-19 23:19:01 +02:00
case FX_TYPE_DROP_WATER:
NewFX=new ("FXWaterDrip") CFXBaseAnim();
NewFX->setBaseData(&FXDropBaseData);
NewFX->setRGB(FX_RGB_WATER);
NewFX->setAfterEffect(CFX::FX_TYPE_SPLASH_WATER);
2001-05-16 21:06:02 +02:00
break;
2001-06-19 23:19:01 +02:00
case FX_TYPE_DROP_ACID:
NewFX=new ("FXAcidDrip") CFXBaseAnim();
NewFX->setBaseData(&FXDropBaseData);
NewFX->setRGB(FX_RGB_ACID);
NewFX->setAfterEffect(CFX::FX_TYPE_SPLASH_ACID);
2001-05-23 21:27:05 +02:00
break;
2001-06-19 23:19:01 +02:00
case FX_TYPE_DROP_LAVA:
NewFX=new ("FXLavaDrip") CFXBaseAnim();
NewFX->setBaseData(&FXDropBaseData);
NewFX->setRGB(FX_RGB_LAVA);
NewFX->setAfterEffect(CFX::FX_TYPE_SPLASH_LAVA);
break;
case FX_TYPE_DROP_OIL:
NewFX=new ("FXOilDrip") CFXBaseAnim();
NewFX->setBaseData(&FXDropBaseData);
NewFX->setRGB(FX_RGB_OIL);
NewFX->setAfterEffect(CFX::FX_TYPE_SPLASH_OIL);
break;
2001-05-23 22:43:32 +02:00
case FX_TYPE_SPLASH_WATER:
2001-05-31 22:07:48 +02:00
NewFX=new ("FXWaterSplash") CFXBaseAnim();
2001-06-19 23:19:01 +02:00
NewFX->setBaseData(&FXSplashBaseData);
NewFX->setRGB(FX_RGB_WATER);
2001-05-23 22:43:32 +02:00
break;
case FX_TYPE_SPLASH_ACID:
2001-05-31 22:07:48 +02:00
NewFX=new ("FXAcidSplash") CFXBaseAnim();
2001-06-19 23:19:01 +02:00
NewFX->setBaseData(&FXSplashBaseData);
NewFX->setRGB(FX_RGB_ACID);
2001-05-23 22:43:32 +02:00
break;
case FX_TYPE_SPLASH_LAVA:
2001-05-31 22:07:48 +02:00
NewFX=new ("FXLavaSplash") CFXBaseAnim();
2001-06-19 23:19:01 +02:00
NewFX->setBaseData(&FXSplashBaseData);
NewFX->setRGB(FX_RGB_LAVA);
2001-05-23 22:43:32 +02:00
break;
case FX_TYPE_SPLASH_OIL:
2001-05-31 22:07:48 +02:00
NewFX=new ("FXOilSplash") CFXBaseAnim();
2001-06-19 23:19:01 +02:00
NewFX->setBaseData(&FXSplashBaseData);
NewFX->setRGB(FX_RGB_OIL);
NewFX->setAfterEffect(CFX::FX_TYPE_EXPLODE);
2001-06-01 00:02:07 +02:00
break;
2001-06-12 01:37:59 +02:00
2001-06-01 17:10:05 +02:00
case FX_TYPE_BUBBLE_WATER:
NewFX=new ("FXBubbleWater") CFXBubble();
2001-06-19 23:19:01 +02:00
NewFX->setBaseData(&FXBubbleBaseData);
NewFX->setRGB(FX_RGB_WATER);
2001-06-01 17:10:05 +02:00
break;
case FX_TYPE_BUBBLE_ACID:
NewFX=new ("FXBubbleAcid") CFXBubble();
2001-06-19 23:19:01 +02:00
NewFX->setBaseData(&FXBubbleBaseData);
NewFX->setRGB(FX_RGB_ACID);
2001-06-01 17:10:05 +02:00
break;
case FX_TYPE_BUBBLE_LAVA:
NewFX=new ("FXBubbleLava") CFXBubble();
2001-06-19 23:19:01 +02:00
NewFX->setBaseData(&FXBubbleBaseData);
NewFX->setRGB(FX_RGB_LAVA);
2001-06-01 17:10:05 +02:00
break;
case FX_TYPE_BUBBLE_OIL:
NewFX=new ("FXBubbleOil") CFXBubble();
2001-06-19 23:19:01 +02:00
NewFX->setBaseData(&FXBubbleBaseData);
NewFX->setRGB(FX_RGB_OIL);
2001-06-01 17:10:05 +02:00
break;
2001-05-23 22:43:32 +02:00
2001-06-19 23:19:01 +02:00
case FX_TYPE_GEYSER_WATER:
NewFX=new ("FXWaterGEYSER") CFXGeyser();
NewFX->setRGB(FX_RGB_WATER);
2001-06-12 01:37:59 +02:00
break;
2001-06-19 23:19:01 +02:00
case FX_TYPE_GEYSER_ACID:
NewFX=new ("FXAcidGEYSER") CFXGeyser();
NewFX->setRGB(FX_RGB_ACID);
2001-06-12 01:37:59 +02:00
break;
2001-06-19 23:19:01 +02:00
case FX_TYPE_GEYSER_LAVA:
NewFX=new ("FXLavaGEYSER") CFXGeyser();
NewFX->setRGB(FX_RGB_LAVA);
2001-06-12 01:37:59 +02:00
break;
2001-06-19 23:19:01 +02:00
case FX_TYPE_GEYSER_OIL:
NewFX=new ("FXOilGEYSER") CFXGeyser();
NewFX->setRGB(FX_RGB_OIL);
2001-06-12 01:37:59 +02:00
break;
2001-06-12 22:20:52 +02:00
case FX_TYPE_THWACK:
NewFX=new ("FXThwack") CFXThwack();
break;
2001-06-19 23:19:01 +02:00
case FX_TYPE_LIGHTNING_BOLT:
ASSERT(!"FX_TYPE_LIGHTNING_BOLT");
break;
case FX_TYPE_STEAM:
NewFX=new ("FXSteam") CFXSteam();
break;
case FX_TYPE_GAS:
ASSERT(!"FX_TYPE_GAS");
break;
case FX_TYPE_FLAMES:
2001-07-21 21:06:07 +02:00
NewFX=new ("FXFlames") CFXFire();
2001-06-19 23:19:01 +02:00
NewFX->setBaseData(&FXFireBaseData);
2001-05-31 00:05:41 +02:00
break;
2001-07-02 21:29:20 +02:00
case FX_TYPE_SMOKE:
NewFX=new ("FXSmoke") CFXSmoke();
break;
case FX_TYPE_SMOKE_PUFF:
NewFX=new ("FXSmokePuff") CFXSmokePuff();
break;
2001-05-18 22:54:43 +02:00
case FX_TYPE_JELLYFISH_LEGS:
2001-05-30 22:36:44 +02:00
NewFX=new ("JellyFish Legs") CFXJellyFishLegs();
break;
2001-06-19 23:19:01 +02:00
case FX_TYPE_FALLINGTILE:
NewFX=new ("FXFalling Tile") CFXFallingTile();
break;
case FX_TYPE_EXPLODE:
NewFX=new ("FXExplode") CFXBaseAnim();
NewFX->setBaseData(&FXExplodeBaseData);
break;
case FX_TYPE_NRG_BAR:
NewFX=new ("NRG Bar") CFXNRGBar();
break;
2001-06-18 18:31:24 +02:00
case FX_TYPE_LASER:
NewFX=new ("FX Laser") CFXLaser();
break;
2001-07-02 21:29:20 +02:00
case FX_TYPE_TV_EXPLODE:
NewFX=new ("FX TVExplode") CFXTVExplode();
break;
2001-07-05 18:01:05 +02:00
case FX_TYPE_ZZZZ:
NewFX=new ("FX ZZZZ") CFXZZZZ();
break;
2001-06-18 18:31:24 +02:00
2001-05-05 20:12:30 +02:00
default:
ASSERT(!"UNKNOWN FX TYPE");
return NULL;
2001-06-19 23:19:01 +02:00
}
NewFX->setThingSubType(Type);
return NewFX;
2001-05-16 21:06:02 +02:00
}
2001-05-05 20:12:30 +02:00
2001-05-16 21:06:02 +02:00
/*****************************************************************************/
CFX *CFX::Create(const FX_TYPE Type,CThing *Parent)
{
CFX *NewFX=CFX::Create(Type);
2001-05-15 23:36:31 +02:00
2001-05-18 22:54:43 +02:00
NewFX->init(Parent->getPos());
2001-05-30 22:36:44 +02:00
ASSERT(Parent);
2001-05-18 22:54:43 +02:00
Parent->addChild(NewFX);
2001-05-16 21:06:02 +02:00
return NewFX;
}
/*****************************************************************************/
CFX *CFX::Create(const FX_TYPE Type,DVECTOR const &Pos)
{
CFX *NewFX=CFX::Create(Type);
NewFX->init(Pos);
return NewFX;
2001-05-05 20:12:30 +02:00
}
/*****************************************************************************/
/*****************************************************************************/
2001-07-09 17:32:51 +02:00
/*****************************************************************************/
void CFX::leftThinkZone(int _frames)
{
if(Flags & FX_FLAG_NO_THINK_KILL)
{
killFX();
}
if( m_soundId != NOT_PLAYING )
{
CSoundMediator::stopAndUnlockSfx(m_soundId);
m_soundId=NOT_PLAYING;
}
}
2001-05-05 20:12:30 +02:00
/*****************************************************************************/
void CFX::init()
{
2001-05-09 21:57:57 +02:00
CFXThing::init();
OtPos=OTPOS__ACTOR_POS;
2001-06-19 23:19:01 +02:00
Flags=0;
Velocity.vx=Velocity.vy=0;
2001-07-04 22:42:42 +02:00
m_soundId = NOT_PLAYING;
EndSnd=0;
2001-05-31 22:07:48 +02:00
}
2001-05-23 00:30:36 +02:00
2001-05-31 22:07:48 +02:00
/*****************************************************************************/
void CFX::init(DVECTOR const &_Pos)
{
init();
Pos=_Pos;
2001-05-05 20:12:30 +02:00
}
2001-06-19 23:19:01 +02:00
/*****************************************************************************/
void CFX::setBaseData(void *Data)
{
setRGB(127,127,127);
AfterEffect=FX_TYPE_NONE;
}
2001-05-05 20:12:30 +02:00
/*****************************************************************************/
void CFX::shutdown()
{
2001-05-15 23:36:31 +02:00
CFXThing::shutdown();
2001-07-09 18:30:49 +02:00
if( m_soundId != NOT_PLAYING )
{
CSoundMediator::stopAndUnlockSfx(m_soundId);
m_soundId=NOT_PLAYING;
}
2001-05-05 20:12:30 +02:00
}
/*****************************************************************************/
void CFX::think(int _frames)
{
2001-07-02 21:29:20 +02:00
CThing *Parent=getParent();
if (Parent)
{
Pos=Parent->getPos();
}
2001-05-05 20:12:30 +02:00
CFXThing::think(_frames);
2001-05-31 22:07:48 +02:00
2001-07-03 18:55:37 +02:00
if (Flags & FX_FLAG_HAS_LIFE)
2001-05-23 00:30:36 +02:00
{
2001-05-31 22:07:48 +02:00
Life-=_frames;
if (Life<=0)
2001-05-23 00:30:36 +02:00
{
2001-05-31 22:07:48 +02:00
killFX();
2001-05-23 00:30:36 +02:00
}
}
2001-06-19 23:19:01 +02:00
if (Flags & FX_FLAG_HAS_GRAVITY)
{
Velocity.vy++;
}
Pos.vx+=Velocity.vx;
Pos.vy+=Velocity.vy;
2001-07-04 22:42:42 +02:00
if (Velocity.vy)
if (Flags & FX_FLAG_COLLIDE_KILL || Flags )
2001-06-19 23:19:01 +02:00
{
CLayerCollision *ColLayer=CGameScene::getCollision();
int DistY = ColLayer->getHeightFromGround( Pos.vx, Pos.vy, 16 );
if (DistY<=0)
{
2001-07-02 21:29:20 +02:00
Pos.vy+=DistY;
if (Flags & FX_FLAG_COLLIDE_KILL)
{
killFX();
}
else
{
Velocity.vx/=2;
2001-07-04 22:42:42 +02:00
Velocity.vy=-(Velocity.vy/2);
if (Velocity.vy)
{
CSoundMediator::playSfx(CSoundMediator::SFX_SPONGEBOB_BLINK,false);
}
2001-07-02 21:29:20 +02:00
}
2001-06-19 23:19:01 +02:00
}
}
}
/*****************************************************************************/
void CFX::killFX()
{
setToShutdown();
// If has follow on effect, create it now
if (AfterEffect!=CFX::FX_TYPE_NONE && canThink())
{
CFX::Create((CFX::FX_TYPE)AfterEffect,getPos());
}
2001-07-09 17:32:51 +02:00
if( m_soundId != NOT_PLAYING )
2001-07-04 22:42:42 +02:00
{
2001-07-09 17:32:51 +02:00
CSoundMediator::stopAndUnlockSfx(m_soundId);
m_soundId=NOT_PLAYING;
2001-07-04 22:42:42 +02:00
}
2001-07-09 17:32:51 +02:00
if (EndSnd)
2001-07-04 22:42:42 +02:00
{
2001-07-19 18:43:48 +02:00
CSoundMediator::playSfx( (CSoundMediator::SFXID)EndSnd,false,true);
2001-07-04 22:42:42 +02:00
}
2001-05-05 20:12:30 +02:00
}
2001-06-19 23:19:01 +02:00
2001-05-05 20:12:30 +02:00
/*****************************************************************************/
void CFX::render()
{
2001-05-16 21:06:02 +02:00
CFXThing::render();
2001-05-05 20:12:30 +02:00
}
2001-05-31 22:07:48 +02:00
/*****************************************************************************/
bool CFX::getFXParentPos(DVECTOR &Pos)
{
CThing *Parent=getParent();
if (!Parent) return(false);
2001-06-19 23:19:01 +02:00
if (Flags & FX_FLAG_SCREEN_FX)
2001-05-31 22:07:48 +02:00
{
2001-06-19 23:19:01 +02:00
Pos=getPos();
2001-05-31 22:07:48 +02:00
}
else
{
2001-06-19 23:19:01 +02:00
Pos=Parent->getPos();
2001-05-31 22:07:48 +02:00
}
return(true);
}
/*****************************************************************************/
void CFX::getFXRenderPos(DVECTOR &Pos)
{
2001-06-19 23:19:01 +02:00
if (Flags & FX_FLAG_SCREEN_FX)
2001-05-31 22:07:48 +02:00
{
2001-06-19 23:19:01 +02:00
Pos=getPos();
2001-05-31 22:07:48 +02:00
}
else
{
2001-06-19 23:19:01 +02:00
CFX::render();
Pos=getRenderPos();
2001-05-31 22:07:48 +02:00
}
}
2001-06-07 18:33:19 +02:00
/*****************************************************************************/
void CFX::collidedWith(CThing *_thisThing)
{
2001-06-19 23:19:01 +02:00
ASSERT(canCollide());
switch(_thisThing->getThingType())
{
case TYPE_PLAYER:
{
CPlayer *player = (CPlayer *) _thisThing;
if ( !player->isRecoveringFromHit() )
{
player->takeDamage( DAMAGE__HIT_ENEMY );
}
break;
}
default:
break;
}
2001-06-07 18:33:19 +02:00
}