SBSPSS/source/triggers/trigger.cpp

155 lines
3.9 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-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
case TRIGGER_PLATFORM:
trigger = (CPlatformTrigger*)new ("PlatformTrigger") CPlatformTrigger();
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);
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);
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;
}