From 1f1174bcc5bad35d88a10b04c33899763787f886 Mon Sep 17 00:00:00 2001 From: Charles Date: Tue, 1 May 2001 13:28:11 +0000 Subject: [PATCH] --- source/game/game.cpp | 17 +++++ source/hazard/hazard.cpp | 151 ++++++++++++++++++++++++++++++++++--- source/hazard/hazard.h | 22 +++++- source/hazard/hboat.cpp | 16 ---- source/hazard/hpendulm.cpp | 55 +++++++++++++- source/hazard/hpendulm.h | 2 + tools/Data/bin/MkLevel.ini | 7 +- tools/MapEdit/Hazard.ini | 4 +- 8 files changed, 241 insertions(+), 33 deletions(-) diff --git a/source/game/game.cpp b/source/game/game.cpp index 04e7169d6..f8928a9e1 100644 --- a/source/game/game.cpp +++ b/source/game/game.cpp @@ -35,6 +35,10 @@ #include "platform\platform.h" #endif +#ifndef __HAZARD_HAZARD_H__ +#include "hazard\hazard.h" +#endif + #ifndef __PROJECTL_PROJECTL_H__ #include "projectl\projectl.h" #endif @@ -309,6 +313,7 @@ void CGameScene::initLevel() // Init actors (needs moving and tidying int actorNum; int platformNum; + int hazardNum; sThingActor **actorList = Level.getActorList(); if (actorList) @@ -356,6 +361,18 @@ void CGameScene::initLevel() } } + sThingHazard **hazardList = Level.getHazardList(); + if (hazardList) + { + for ( hazardNum = 0 ; hazardNum < Level.getHazardCount() ; hazardNum++ ) + { + sThingHazard *ThisHazard = hazardList[hazardNum]; + CNpcHazard *hazard; + hazard = CNpcHazard::Create( ThisHazard ); + hazard->setLayerCollision( Level.getCollisionLayer() ); + } + } + // Song is loaded/dumped by the level, and played from here. This just gives some // better timing over when it starts (pkg) CSoundMediator::playSong(); diff --git a/source/hazard/hazard.cpp b/source/hazard/hazard.cpp index 3b61a1c7a..983b38a9b 100644 --- a/source/hazard/hazard.cpp +++ b/source/hazard/hazard.cpp @@ -23,22 +23,143 @@ #include "system\vid.h" #endif +#ifndef __UTILS_HEADER__ +#include "utils\utils.h" +#endif + +#ifndef __HAZARD_HFALLING_H__ +#include "hazard\hfalling.h" +#endif + +#ifndef __HAZARD_HPENDULM_H__ +#include "hazard\hpendulm.h" +#endif + +#ifndef __HAZARD_HBOAT_H__ +#include "hazard\hboat.h" +#endif + +//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + +CNpcHazard::NPC_HAZARD_UNIT_TYPE CNpcHazard::mapEditConvertTable[NPC_HAZARD_TYPE_MAX] = +{ + NPC_FALLING_HAZARD, + NPC_PENDULUM_HAZARD, + NPC_BOAT_HAZARD, +}; + +//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + +CNpcHazard *CNpcHazard::Create(sThingHazard *ThisHazard) +{ + CNpcHazard *hazard; + + NPC_HAZARD_UNIT_TYPE hazardType = getTypeFromMapEdit( ThisHazard->Type ); + + switch( hazardType ) + { + case NPC_FALLING_HAZARD: + { + hazard = new ("falling hazard") CNpcFallingHazard; + break; + } + + case NPC_PENDULUM_HAZARD: + { + hazard = new ("pendulum hazard") CNpcPendulumHazard; + break; + } + + case NPC_BOAT_HAZARD: + { + hazard = new ("boat hazard") CNpcBoatHazard; + break; + } + + default: + { + hazard = NULL; + break; + } + } + + ASSERT( hazard ); + + hazard->init(); + hazard->setWaypoints( ThisHazard ); + hazard->setGraphic( ThisHazard ); + + return( hazard ); +} + +//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + +void CNpcHazard::setWaypoints( sThingHazard *ThisHazard ) +{ + int pointNum; + + u16 *PntList=(u16*)MakePtr(ThisHazard,sizeof(sThingHazard)); + + u16 newXPos, newYPos; + + newXPos = (u16) *PntList; + PntList++; + newYPos = (u16) *PntList; + PntList++; + + DVECTOR startPos; + startPos.vx = newXPos << 4; + startPos.vy = newYPos << 4; + + Pos = startPos; + m_base = Pos; + + addWaypoint( newXPos, newYPos ); + + if ( ThisHazard->PointCount > 1 ) + { + for ( pointNum = 1 ; pointNum < ThisHazard->PointCount ; pointNum++ ) + { + newXPos = (u16) *PntList; + PntList++; + newYPos = (u16) *PntList; + PntList++; + + addWaypoint( newXPos, newYPos ); + } + } +} + +//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + +void CNpcHazard::addWaypoint( s32 xPos, s32 yPos ) +{ + DVECTOR newPos; + + newPos.vx = xPos << 4; + newPos.vy = yPos << 4; + + m_npcPath.addWaypoint( newPos ); +} + +//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + +CNpcHazard::NPC_HAZARD_UNIT_TYPE CNpcHazard::getTypeFromMapEdit( u16 newType ) +{ + return( mapEditConvertTable[newType] ); +} + //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// void CNpcHazard::init() { CHazardThing::init(); - m_actorGfx=CActorPool::GetActor( (FileEquate) ACTORS_CLAM_SBK ); - m_spriteBank=0; + //m_actorGfx=CActorPool::GetActor( (FileEquate) ACTORS_CLAM_SBK ); + //m_spriteBank=0; m_npcPath.initPath(); - Pos.vx = 300; - Pos.vy = 300; - - m_base = Pos; - m_timer = 0; m_timerActive = false; m_isActive = true; @@ -50,14 +171,23 @@ void CNpcHazard::init() //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +void CNpcHazard::setGraphic( sThingHazard *ThisHazard ) +{ + m_modelGfx = new ("ModelGfx") CModelGfx; + m_modelGfx->SetModel( ThisHazard->Gfx ); +} + +//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + void CNpcHazard::shutdown() { - if (m_spriteBank) m_spriteBank->dump(); delete m_spriteBank; + delete m_modelGfx; + //if (m_spriteBank) m_spriteBank->dump(); delete m_spriteBank; // remove waypoints m_npcPath.removeAllWaypoints(); - if (m_actorGfx) delete m_actorGfx; + //if (m_actorGfx) delete m_actorGfx; CHazardThing::shutdown(); } @@ -119,7 +249,8 @@ void CNpcHazard::render() { if ( renderPos.vy >= 0 && renderPos.vy <= VidGetScrH() ) { - m_actorGfx->Render(renderPos,0,0,0); + m_modelGfx->Render(renderPos); + //m_actorGfx->Render(renderPos,0,0,0); } } } diff --git a/source/hazard/hazard.h b/source/hazard/hazard.h index 725be1a08..b5076cd1c 100644 --- a/source/hazard/hazard.h +++ b/source/hazard/hazard.h @@ -34,11 +34,26 @@ class CNpcHazard : public CHazardThing { public: + enum NPC_HAZARD_UNIT_TYPE + { + NPC_FALLING_HAZARD = 0, + NPC_PENDULUM_HAZARD = 1, + NPC_BOAT_HAZARD, + + NPC_HAZARD_TYPE_MAX, + }; + virtual void init(); + void setGraphic( sThingHazard *ThisHazard ); void shutdown(); void think(int _frames); void render(); void setLayerCollision( class CLayerCollision *_layer ) {m_layerCollision=_layer;} + virtual void setWaypoints( sThingHazard *ThisHazard ); + void addWaypoint( s32 xPos, s32 yPos ); + + static NPC_HAZARD_UNIT_TYPE getTypeFromMapEdit( u16 newType ); + static CNpcHazard *Create(sThingHazard *ThisHazard); protected: enum @@ -54,8 +69,8 @@ protected: virtual void processMovement( int _frames ); virtual void processTimer( int _frames ); CNpcPath m_npcPath; - CActorGfx *m_actorGfx; - SpriteBank *m_spriteBank; + //CActorGfx *m_actorGfx; + //SpriteBank *m_spriteBank; DVECTOR m_base; s32 m_timer; bool m_timerActive; @@ -64,6 +79,9 @@ protected: s32 m_extension; bool m_extendDir; s32 m_heading; + CModelGfx *m_modelGfx; + + static NPC_HAZARD_UNIT_TYPE mapEditConvertTable[NPC_HAZARD_TYPE_MAX]; }; #endif diff --git a/source/hazard/hboat.cpp b/source/hazard/hboat.cpp index b3a816559..9c29d8817 100644 --- a/source/hazard/hboat.cpp +++ b/source/hazard/hboat.cpp @@ -25,22 +25,6 @@ void CNpcBoatHazard::init() { CNpcHazard::init(); - DVECTOR newPos; - - Pos.vx = 100; - Pos.vy = 100; - m_base = Pos; - - newPos.vx = 600; - newPos.vy = 100; - - m_npcPath.addWaypoint( newPos ); - - newPos.vx = 50; - newPos.vy = 100; - - m_npcPath.addWaypoint( newPos ); - m_npcPath.setPathType( CNpcPath::PONG_PATH ); } diff --git a/source/hazard/hpendulm.cpp b/source/hazard/hpendulm.cpp index 186ad23ca..17c936f7b 100644 --- a/source/hazard/hpendulm.cpp +++ b/source/hazard/hpendulm.cpp @@ -15,6 +15,10 @@ #include "hazard\hpendulm.h" #endif +#ifndef __UTILS_HEADER__ +#include "utils\utils.h" +#endif + //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// void CNpcPendulumHazard::init() @@ -29,11 +33,58 @@ void CNpcPendulumHazard::init() //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +void CNpcPendulumHazard::setWaypoints( sThingHazard *ThisHazard ) +{ + int pointNum; + + u16 *PntList=(u16*)MakePtr(ThisHazard,sizeof(sThingHazard)); + + u16 newXPos, newYPos; + + newXPos = (u16) *PntList; + PntList++; + newYPos = (u16) *PntList; + PntList++; + + DVECTOR startPos; + startPos.vx = newXPos << 4; + startPos.vy = newYPos << 4; + + if ( ThisHazard->PointCount > 1 ) + { + newXPos = (u16) *PntList; + PntList++; + newYPos = (u16) *PntList; + PntList++; + + DVECTOR pivotPos; + pivotPos.vx = newXPos << 4; + pivotPos.vy = newYPos << 4; + + s32 xDist = startPos.vx - pivotPos.vx; + s32 yDist = startPos.vy - pivotPos.vy; + + m_maxExtension = 1024 - ratan2( abs( yDist ), abs( xDist ) ); + + m_length = isqrt2( ( xDist * xDist ) + ( yDist * yDist ) ); + + Pos = pivotPos; + } + else + { + Pos = startPos; + } + + m_base = Pos; +} + +//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + void CNpcPendulumHazard::processMovement( int _frames ) { if ( m_extendDir == EXTEND_LEFT ) { - if ( m_extension > 512 ) + if ( m_extension > m_maxExtension ) { m_extendDir = EXTEND_RIGHT; } @@ -44,7 +95,7 @@ void CNpcPendulumHazard::processMovement( int _frames ) } else { - if ( m_extension < -512 ) + if ( m_extension < -m_maxExtension ) { m_extendDir = EXTEND_LEFT; } diff --git a/source/hazard/hpendulm.h b/source/hazard/hpendulm.h index 2c75ce669..cf9a84bc5 100644 --- a/source/hazard/hpendulm.h +++ b/source/hazard/hpendulm.h @@ -23,9 +23,11 @@ class CNpcPendulumHazard : public CNpcHazard public: void init(); protected: + virtual void setWaypoints( sThingHazard *ThisHazard ); void processMovement( int _frames ); s32 m_length; + s32 m_maxExtension; }; #endif \ No newline at end of file diff --git a/tools/Data/bin/MkLevel.ini b/tools/Data/bin/MkLevel.ini index 564cabd78..59393b07c 100644 --- a/tools/Data/bin/MkLevel.ini +++ b/tools/Data/bin/MkLevel.ini @@ -100,6 +100,11 @@ Restart_Point=1 Ch1L1_Plat1=0 Ch1L1_Plat2=1 - +################################################ +# Hazards +[Hazard] +Acorn=0 +HeartPendulum=1 +Tugboat=2 diff --git a/tools/MapEdit/Hazard.ini b/tools/MapEdit/Hazard.ini index 07409aaa7..0611c98a2 100644 --- a/tools/MapEdit/Hazard.ini +++ b/tools/MapEdit/Hazard.ini @@ -22,7 +22,7 @@ Respawn=1 [HeartPendulum] Gfx=..\..\graphics\hazards\HeartPendulum\HeartPendulum.gin -WayPoints=0 +WayPoints=1 Speed=0 TurnRate=0 Collision=0 @@ -32,7 +32,7 @@ Respawn=2 [Tugboat] Gfx=..\..\graphics\hazards\Tugboat\Tugboat.gin -WayPoints=0 +WayPoints=16 Speed=0 TurnRate=0 Collision=0