SBSPSS/source/hazard/hcheck.cpp

193 lines
4.3 KiB
C++
Raw Normal View History

2001-07-17 21:34:40 +02:00
/*=========================================================================
hcheck.h
Author: CRB
Created:
Project: Spongebob
Purpose:
Copyright (c) 2001 Climax Development Ltd
===========================================================================*/
#ifndef __HAZARD_HCHECK_H__
#include "hazard\hcheck.h"
#endif
#ifndef __PLAYER_PLAYER_H__
#include "player\player.h"
#endif
2001-07-17 22:15:28 +02:00
#ifndef __SPR_SPRITES_H__
#include <sprites.h>
#endif
#ifndef __GAME_GAME_H__
#include "game\game.h"
#endif
2001-08-03 23:04:12 +02:00
#ifndef __VID_HEADER_
#include "system\vid.h"
#endif
2001-07-17 21:34:40 +02:00
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void CNpcCheckpointHazard::init()
{
CNpcHazard::init();
m_triggered = false;
2001-08-03 21:23:11 +02:00
// m_spriteFrame = FRM__CHECKPOINT;
m_spriteFrame = 0; // Change by dave cos the checkpoint gfx aint there no more
2001-07-17 22:30:13 +02:00
m_timer = 0;
2001-08-03 23:44:31 +02:00
m_flick = 0;
2001-08-03 23:04:12 +02:00
m_scalableFont=new ("CheckpointFont") ScalableFontBank();
m_scalableFont->initialise(&standardFont);
2001-08-04 18:18:33 +02:00
m_scalableFont->setColour(255,255,0);
2001-08-03 23:04:12 +02:00
m_scalableFont->setScale(511);
if ( CLevel::getCurrentCheckpoint() == this )
{
m_triggered = true;
}
2001-07-17 22:30:13 +02:00
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void CNpcCheckpointHazard::think(int _frames)
{
2001-08-03 23:04:12 +02:00
if ( m_flick )
2001-07-17 22:30:13 +02:00
{
2001-08-03 23:04:12 +02:00
m_timer -= _frames;
2001-07-17 22:30:13 +02:00
2001-08-03 23:04:12 +02:00
if ( m_timer <= 0 )
{
2001-08-03 23:44:31 +02:00
m_flick = 0;
2001-08-03 23:04:12 +02:00
}
else
{
2001-08-03 23:44:31 +02:00
int HF=GameState::getOneSecondInFrames()>>1;
if (m_timer<HF) m_flick^=2;
if (m_flick & 2)
{
m_scalableFont->setJustification(FontBank::JUST_CENTRE);
m_scalableFont->print( 256, 50, "Checkpoint!" );
}
2001-08-03 23:04:12 +02:00
}
2001-07-17 22:30:13 +02:00
}
2001-07-17 21:34:40 +02:00
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
2001-08-03 23:04:12 +02:00
void CNpcCheckpointHazard::shutdown()
{
m_scalableFont->dump(); delete m_scalableFont;
CNpcHazard::shutdown();
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
2001-08-04 18:18:33 +02:00
static const int CPXO=18;
static const int CPYO=8;
static const int CPOT=13;
static const int CPA=3;
static const int CPZ=50;
2001-08-03 23:04:12 +02:00
2001-07-17 21:34:40 +02:00
void CNpcCheckpointHazard::render()
{
2001-07-17 22:15:28 +02:00
sFrameHdr *frameHdr;
2001-07-17 22:30:13 +02:00
POLY_FT4 *Ft4;
2001-07-17 22:15:28 +02:00
if ( m_isActive )
{
CHazardThing::render();
if (canRender())
{
DVECTOR &renderPos=getRenderPos();
m_modelGfx->Render(renderPos);
2001-08-03 23:04:12 +02:00
if ( CLevel::getCurrentCheckpoint() == this )
2001-07-17 22:15:28 +02:00
{
2001-08-03 23:04:12 +02:00
int scrnWidth = VidGetScrW();
int scrnHeight = VidGetScrH();
sBBox boundingBox = m_modelGfx->GetBBox();
CRECT polyArea;
2001-08-03 23:44:31 +02:00
polyArea.x1 = boundingBox.XMin;
polyArea.y1 = boundingBox.YMin;
polyArea.x2 = boundingBox.XMax;
polyArea.y2 = boundingBox.YMax;
polyArea.x1+=CPXO;
polyArea.x2-=CPXO;
polyArea.y1+=CPYO;
u8 *PrimPtr=GetPrimPtr();
TPOLY_F4 *F4=(TPOLY_F4 *)PrimPtr;
PrimPtr+=sizeof(TPOLY_F4);
SetPrimPtr((u8*)PrimPtr);
setTPolyF4(F4);
2001-08-04 18:18:33 +02:00
// F4->x0 = polyArea.x1; F4->y0 = polyArea.y1;
// F4->x1 = polyArea.x2; F4->y1 = polyArea.y1;
// F4->x2 = polyArea.x1; F4->y2 = polyArea.y2;
// F4->x3 = polyArea.x2; F4->y3 = polyArea.y2;
2001-08-03 23:44:31 +02:00
long Tmp;
SVECTOR I;
I.vz=CPZ;
2001-08-04 18:18:33 +02:00
I.vy=polyArea.y1;
I.vx=polyArea.x1; RotTransPers(&I,(long*)&F4->x0,&Tmp,&Tmp);
I.vx=polyArea.x2; RotTransPers(&I,(long*)&F4->x1,&Tmp,&Tmp);
I.vy=polyArea.y2;
I.vx=polyArea.x1; RotTransPers(&I,(long*)&F4->x2,&Tmp,&Tmp);
I.vx=polyArea.x2; RotTransPers(&I,(long*)&F4->x3,&Tmp,&Tmp);
2001-08-03 23:44:31 +02:00
setTSemiTrans(F4,1);
setTABRMode(F4,CPA);
setRGB0( F4, 255, 255, 0 );
AddPrimToList( F4, CPOT );
2001-07-17 22:15:28 +02:00
}
}
}
2001-07-17 21:34:40 +02:00
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void CNpcCheckpointHazard::collidedWith(CThing *_thisThing)
{
2001-08-04 18:18:33 +02:00
// if ( m_isActive && !m_triggered )
if ( m_isActive && CLevel::getCurrentCheckpoint() != this )
2001-07-17 21:34:40 +02:00
{
switch(_thisThing->getThingType())
{
case TYPE_PLAYER:
{
2001-07-23 21:26:37 +02:00
CRECT const &collisionArea=getCollisionArea();
2001-07-17 21:34:40 +02:00
DVECTOR respawnPos;
respawnPos.vx=collisionArea.x1+((collisionArea.x2-collisionArea.x1)/2);
respawnPos.vy=collisionArea.y2;
((CPlayer*)_thisThing)->setRespawnPosAndRingTelephone(respawnPos);
m_triggered = true;
2001-08-03 23:04:12 +02:00
m_timer = GameState::getOneSecondInFrames();
2001-08-03 23:44:31 +02:00
m_flick = 3;
2001-08-03 23:04:12 +02:00
CLevel::setCurrentCheckpoint( this );
2001-07-17 21:34:40 +02:00
break;
}
default:
break;
}
}
}