SBSPSS/source/triggers/trigger.cpp

263 lines
6.4 KiB
C++
Raw Normal View History

2001-05-29 21:25:37 +02:00
/*=========================================================================
trigger source file
Author: Davey Boy
Created:
Project: Spongebob
Purpose:
Copyright (c) 2001 Climax Development Ltd
===========================================================================*/
#ifndef __TRIGGER_TRIGGER_HEADER__
#include "triggers\trigger.h"
#endif
#ifndef __TRIGGERS_TLEVEXIT_H__
#include "triggers\tlevexit.h"
#endif
#ifndef __TRIGGERS_TRESTART_H__
#include "triggers\trestart.h"
#endif
#ifndef __TRIGGERS_TTELEPRT_H__
#include "triggers\tteleprt.h"
#endif
#ifndef __TRIGGERS_TCAMLOCK_H__
#include "triggers\tcamlock.h"
#endif
#ifndef __TRIGGERS_TWATER_H__
#include "triggers\twater.h"
#endif
2001-05-30 18:52:52 +02:00
#ifndef __TRIGGERS_TPLATFRM_H__
#include "triggers\tplatfrm.h"
#endif
2001-05-30 22:24:02 +02:00
#ifndef __TRIGGERS_TGARYGO_H__
#include "triggers\tgarygo.h"
#endif
2001-06-02 00:03:24 +02:00
#ifndef __TRIGGERS_TFEMIT_H__
#include "triggers\tfemit.h"
#endif
#ifndef __TRIGGERS_TIFEMIT_H__
#include "triggers\tifemit.h"
#endif
2001-06-04 16:04:39 +02:00
#ifndef __TRIGGERS_TBEMIT_H__
#include "triggers\tbemit.h"
#endif
2001-06-04 14:54:44 +02:00
#ifndef __TRIGGERS_TGGLEFT_H__
#include "triggers\tggleft.h"
#endif
2001-06-04 15:20:30 +02:00
#ifndef __TRIGGERS_TGGRIGHT_H__
#include "triggers\tggright.h"
#endif
2001-06-04 14:54:44 +02:00
#ifndef __TRIGGERS_TGSTOP_H__
#include "triggers\tgstop.h"
#endif
2001-06-04 21:01:17 +02:00
#ifndef __TRIGGERS_THAZARD_H__
#include "triggers\thazard.h"
#endif
2001-06-05 16:38:11 +02:00
#ifndef __TRIGGERS_TBGEYSER_H__
#include "triggers\tbgeyser.h"
#endif
2001-05-29 21:25:37 +02:00
#ifndef __GAME_GAME_H__
#include "game\game.h"
#endif
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
CTrigger *CTrigger::Create(int Type)
{
CTrigger *trigger;
2001-05-29 22:31:02 +02:00
2001-05-29 21:25:37 +02:00
trigger = (CTrigger*)CThingManager::GetThing(CThing::TYPE_TRIGGER,Type);
if (!trigger)
switch( Type )
{
// Exit trigger
case TRIGGER_EXIT:
trigger=(CTrigger*)new ("LevelExitTrigger") CLevelExitTrigger();
break;
// Level respawn trigger
case TRIGGER_RESPAWN:
trigger=(CRestartPointTrigger*)new ("RestartTrigger") CRestartPointTrigger();
break;
// Teleport trigger
case TRIGGER_TELEPORT:
trigger=(CTeleportTrigger*)new ("TeleportTrigger") CTeleportTrigger();
break;
// Camera lock trigger
case TRIGGER_CAMLOCK:
2001-05-29 22:31:02 +02:00
trigger=(CCameraLockTrigger*)new ("CameraLockTrigger") CCameraLockTrigger();
2001-05-29 21:25:37 +02:00
break;
// In/Out of water triggers
2001-05-29 22:31:02 +02:00
case TRIGGER_INWATER:
2001-05-29 21:25:37 +02:00
trigger=(CInWaterTrigger*)new ("InWaterTrigger") CInWaterTrigger();
break;
2001-05-29 22:31:02 +02:00
case TRIGGER_OUTWATER:
2001-05-29 21:25:37 +02:00
trigger=(COutOfWaterTrigger*)new ("OutOfWaterTrigger") COutOfWaterTrigger();
break;
2001-05-30 18:52:52 +02:00
2001-05-30 22:24:02 +02:00
// Gary start trigger
2001-06-05 16:38:11 +02:00
case TRIGGER_GARY_START:
2001-06-04 14:54:44 +02:00
trigger=(CGaryStartTrigger*)new("GaryStartTrigger") CGaryStartTrigger();
2001-05-30 22:24:02 +02:00
break;
2001-06-04 14:54:44 +02:00
// Gary stop trigger
2001-06-05 16:38:11 +02:00
case TRIGGER_GARY_STOP:
2001-06-04 14:54:44 +02:00
trigger=(CGaryStopTrigger*)new("GaryStopTrigger") CGaryStopTrigger();
break;
// Gary go left trigger
2001-06-05 16:38:11 +02:00
case TRIGGER_GARY_GO_LEFT:
2001-06-04 14:54:44 +02:00
trigger=(CGaryGoLeftTrigger*)new("GaryGoLeftTrigger") CGaryGoLeftTrigger();
break;
2001-06-04 15:20:30 +02:00
// Gary go right trigger
2001-06-05 16:38:11 +02:00
case TRIGGER_GARY_GO_RIGHT:
2001-06-04 15:20:30 +02:00
trigger=(CGaryGoRightTrigger*)new("GaryGoRightTrigger") CGaryGoRightTrigger();
break;
2001-06-04 16:04:39 +02:00
// Flame emitter
2001-06-05 16:38:11 +02:00
case TRIGGER_FLAME_EMITTER:
2001-06-04 16:04:39 +02:00
trigger=(CFlameEmitterTrigger*)new( "FlameEmitterTrigger") CFlameEmitterTrigger();
break;
2001-06-05 16:38:11 +02:00
case TRIGGER_INTERMITTENT_FLAME_EMITTER:
case TRIGGER_INTERMITTENT_LEFT_FLAME_EMITTER:
case TRIGGER_INTERMITTENT_DOWN_FLAME_EMITTER:
2001-06-02 00:03:24 +02:00
trigger=(CIntermittentFlameEmitterTrigger*)new( "IntermittentFlameEmitterTrigger") CIntermittentFlameEmitterTrigger();
break;
2001-06-04 16:04:39 +02:00
// Bubble emitter
2001-06-05 16:38:11 +02:00
case TRIGGER_BUBBLE_EMITTER:
2001-06-04 16:04:39 +02:00
trigger=(CBubbleEmitterTrigger*)new( "BubbleEmitterTrigger") CBubbleEmitterTrigger();
break;
2001-06-05 16:38:11 +02:00
// Bubble geyser emitter
case TRIGGER_BUBBLE_GEYSER_EMITTER:
trigger=(CBubbleGeyserEmitterTrigger*)new( "BubbleGeyserEmitterTrigger") CBubbleGeyserEmitterTrigger();
break;
2001-05-30 18:52:52 +02:00
case TRIGGER_PLATFORM:
trigger = (CPlatformTrigger*)new ("PlatformTrigger") CPlatformTrigger();
break;
2001-06-04 21:01:17 +02:00
case TRIGGER_HAZARD:
trigger = (CHazardTrigger*)new("HazardTrigger") CHazardTrigger();
break;
2001-05-29 21:25:37 +02:00
default:
trigger=NULL;
}
ASSERT( trigger);
trigger->setThingSubType(Type);
trigger->init();
return( trigger);
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
CTrigger *CTrigger::Create(sThingTrigger *ThisTrigger)
{
CTrigger *trigger=Create(ThisTrigger->Type);
2001-06-04 21:01:17 +02:00
2001-05-29 21:25:37 +02:00
trigger->setPositionAndSize(ThisTrigger->Pos.X<<4,ThisTrigger->Pos.Y<<4,ThisTrigger->Width<<4,ThisTrigger->Height<<4);
trigger->setTargetBox(ThisTrigger->TargetPos.X<<4,ThisTrigger->TargetPos.Y<<4,ThisTrigger->TargetSize.X<<4,ThisTrigger->TargetSize.Y<<4);
2001-06-04 21:01:17 +02:00
switch( ThisTrigger->Type )
{
2001-06-05 16:38:11 +02:00
case TRIGGER_INTERMITTENT_LEFT_FLAME_EMITTER:
2001-06-04 21:01:17 +02:00
{
CIntermittentFlameEmitterTrigger *m_flameEmitter = (CIntermittentFlameEmitterTrigger *) trigger;
m_flameEmitter->setHeading( 3072 );
m_flameEmitter->setSize( ThisTrigger->Height<<4, ThisTrigger->Width<<4 );
break;
}
2001-06-05 16:38:11 +02:00
case TRIGGER_INTERMITTENT_DOWN_FLAME_EMITTER:
2001-06-04 21:01:17 +02:00
{
CIntermittentFlameEmitterTrigger *m_flameEmitter = (CIntermittentFlameEmitterTrigger *) trigger;
m_flameEmitter->setHeading( 2048 );
break;
}
default:
break;
}
2001-05-29 21:25:37 +02:00
return( trigger);
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void CTrigger::init()
{
2001-05-29 22:31:02 +02:00
CTriggerThing::init();
2001-05-29 21:25:37 +02:00
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void CTrigger::shutdown()
{
2001-05-29 22:31:02 +02:00
CTriggerThing::shutdown();
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void CTrigger::think(int _frames)
{
CTriggerThing::think(_frames);
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void CTrigger::render()
{
CTriggerThing::render();
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void CTrigger::setPositionAndSize(int _x,int _y,int _w,int _h)
{
Pos.vx=_x+(_w/2);
Pos.vy=_y+(_h/2);
setCollisionSize(_w,_h);
2001-05-29 21:25:37 +02:00
}
2001-05-29 22:31:02 +02:00
/*----------------------------------------------------------------------
Function:
Purpose:
Params:
Returns:
---------------------------------------------------------------------- */
void CTrigger::setTargetBox(int _x,int _y,int _w,int _h)
{
m_boxX1=_x;
m_boxY1=_y;
m_boxX2=_x+_w;
m_boxY2=_y+_h;
}