SBSPSS/source/fx/fx.cpp

412 lines
9.2 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-05-31 22:07:48 +02:00
#include "FX\FXBaseEmitter.h"
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-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-05-05 20:12:30 +02:00
2001-05-31 22:07:48 +02:00
#include "FX\FXNrgBar.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
{127,255,127}, // Acid
{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-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-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-06-19 23:19:01 +02:00
FRM__EXPLOSION0001,FRM__EXPLOSION0006,1,
FX_FLAG_NO_THINK_KILL,
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-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,
FX_FLAG_LOOP | FX_FLAG_COLLIDE_KILL | FX_FLAG_NO_THINK_KILL,
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
int FXType=(CFX::FX_TYPE)CFX::FX_TYPE_GEYSER_WATER;
2001-06-14 23:17:10 +02:00
#include "game\game.h"
2001-06-18 18:31:24 +02:00
2001-06-12 01:37:59 +02:00
void TestFX(DVECTOR Pos,CThing *Parent)
2001-05-23 21:27:05 +02:00
{
2001-06-19 23:19:01 +02:00
CFX::Create((CFX::FX_TYPE)FXType,Pos);
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
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_SMOKE:
ASSERT(!"FX_TYPE_SMOKE");
break;
case FX_TYPE_GAS:
ASSERT(!"FX_TYPE_GAS");
break;
case FX_TYPE_FLAMES:
NewFX=new ("FXFlames") CFXBaseAnim();
NewFX->setBaseData(&FXFireBaseData);
2001-05-31 00:05:41 +02:00
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-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
}
/*****************************************************************************/
/*****************************************************************************/
/*****************************************************************************/
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-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-05-05 20:12:30 +02:00
}
/*****************************************************************************/
void CFX::think(int _frames)
{
CFXThing::think(_frames);
2001-05-31 22:07:48 +02:00
2001-05-23 00:30:36 +02:00
if (Life>0)
{
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;
if (Flags & FX_FLAG_COLLIDE_KILL)
{
CLayerCollision *ColLayer=CGameScene::getCollision();
int DistY = ColLayer->getHeightFromGround( Pos.vx, Pos.vy, 16 );
if (DistY<=0)
{
Pos.vy-=DistY;
killFX();
}
}
}
/*****************************************************************************/
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-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
}