SBSPSS/source/game/game.cpp

391 lines
9.6 KiB
C++
Raw Normal View History

2000-08-29 21:54:22 +02:00
/**********************/
/*** Main Game File ***/
/**********************/
#include "system\global.h"
#include "fileio\fileio.h"
#include "pad\pads.h"
#include "system\vid.h"
#include "gfx\prim.h"
#include "utils\utils.h"
2000-12-07 16:56:20 +01:00
#include "level\level.h"
2000-08-29 21:54:22 +02:00
#include "game\game.h"
#include "system\gstate.h"
#include "gfx\font.h"
#include "gfx\fdata.h"
2001-01-22 21:57:39 +01:00
#ifndef __GAME_CONVO_H__
#include "game\convo.h"
#endif
2001-01-16 17:20:45 +01:00
#ifndef __PLAYER_PLAYER_H__
#include "player\player.h"
#endif
2001-02-09 18:01:04 +01:00
#include "player\demoplay.h"
2001-01-16 17:20:45 +01:00
2001-02-28 20:49:12 +01:00
#ifndef __ENEMY_NPC_H__
#include "enemy\npc.h"
2001-01-16 17:20:45 +01:00
#endif
2001-04-27 17:09:10 +02:00
#ifndef __FRIEND_FRIEND_H__
#include "friend\friend.h"
#endif
2001-04-23 22:40:13 +02:00
#ifndef __PLATFORM_PLATFORM_H__
#include "platform\platform.h"
2001-03-08 21:12:47 +01:00
#endif
2001-05-01 15:28:11 +02:00
#ifndef __HAZARD_HAZARD_H__
#include "hazard\hazard.h"
#endif
2001-01-22 17:02:38 +01:00
#ifndef __PROJECTL_PROJECTL_H__
#include "projectl\projectl.h"
#endif
2001-01-15 23:02:25 +01:00
#ifndef __GFX_FADER_H__
#include "gfx\fader.h"
#endif
2000-10-18 20:37:39 +02:00
#ifndef __GFX_BUBICLES__
#include "gfx\bubicles.h"
#endif
2001-04-20 16:53:35 +02:00
#ifndef __SPR_SPRITES_H__
#include <sprites.h>
2000-10-31 17:41:02 +01:00
#endif
2001-02-09 18:01:04 +01:00
#ifndef _ANIMTEX_HEADER_
#include "gfx\animtex.h"
#endif
2000-10-18 20:37:39 +02:00
2001-02-09 22:41:55 +01:00
#ifndef __GAME_PAUSE_H__
#include "game\pause.h"
#endif
2001-02-12 18:18:17 +01:00
#ifndef __FRONTEND_FRONTEND_H__
#include "frontend\frontend.h"
#endif
2001-02-21 18:09:19 +01:00
#ifndef __PICKUPS_PICKUP_H__
#include "pickups\pickup.h"
#endif
2001-02-12 18:18:17 +01:00
2000-08-29 21:54:22 +02:00
2001-03-29 18:13:50 +02:00
#ifndef __SOUND_SOUND_H__
#include "sound\sound.h"
#endif
2001-04-01 22:22:49 +02:00
#include "gfx\actor.h"
2001-03-29 18:13:50 +02:00
2001-04-20 13:32:52 +02:00
int RenderZ=256;
2001-01-15 16:22:33 +01:00
2000-08-29 21:54:22 +02:00
/*****************************************************************************/
2001-01-15 16:22:33 +01:00
FontBank *CGameScene::s_genericFont;
MATRIX CGameScene::CamMtx;
2000-10-18 20:37:39 +02:00
2001-04-25 18:41:16 +02:00
/*****************************************************************************/
2001-04-27 23:12:31 +02:00
CGameScene::ACTOR_TYPE CGameScene::actorType[40] =
2001-04-25 18:41:16 +02:00
{
ACTOR_PLAYER, //SpongeBob=0
ACTOR_FRIEND_NPC, //BarnacleBoy=1
ACTOR_FRIEND_NPC, //Gary=2
ACTOR_FRIEND_NPC, //Krusty=3
ACTOR_FRIEND_NPC, //MermaidMan=4
ACTOR_FRIEND_NPC, //Patrick=5
ACTOR_FRIEND_NPC, //Sandy=6
ACTOR_FRIEND_NPC, //Squidward=7
ACTOR_FRIEND_NPC, //Plankton=8
ACTOR_UNKNOWN,
ACTOR_ENEMY_NPC, //SmallJellyfish-Level1=10
ACTOR_ENEMY_NPC, //SmallJellyfish-Level2=11
ACTOR_ENEMY_NPC, //Motherjellyfish=12
ACTOR_ENEMY_NPC, //Anenome-Level1=13
ACTOR_ENEMY_NPC, //SpikeyAnenome=14
ACTOR_ENEMY_NPC, //Anenome-Level3=15
ACTOR_ENEMY_NPC, //BabyOctopus=16
ACTOR_ENEMY_NPC, //Ballblob=17
ACTOR_ENEMY_NPC, //Boogermonster=18
ACTOR_ENEMY_NPC, //Caterpillar=19
ACTOR_ENEMY_NPC, //Clam-Level1=20
ACTOR_ENEMY_NPC, //Clam-Level2=21
ACTOR_ENEMY_NPC, //Eyeball=22
ACTOR_ENEMY_NPC, //Flamingskull=23
ACTOR_ENEMY_NPC, //FlyingDutchman=24
ACTOR_ENEMY_NPC, //Ghost=25
ACTOR_ENEMY_NPC, //GiantWorm=26
ACTOR_ENEMY_NPC, //HermitCrab=27
ACTOR_ENEMY_NPC, //IronDogFish=28
ACTOR_ENEMY_NPC, //PuffaFish=29
ACTOR_ENEMY_NPC, //SeaSnake=30
ACTOR_ENEMY_NPC, //Sharkman=31
ACTOR_ENEMY_NPC, //SharkSub=32
ACTOR_ENEMY_NPC, //Skeletalfish=33
ACTOR_ENEMY_NPC, //SpiderCrab=34
ACTOR_ENEMY_NPC, //Squiddart=35
ACTOR_ENEMY_NPC, //Stomper=36
ACTOR_ENEMY_NPC, //DustDevil=37
ACTOR_ENEMY_NPC, //SiderCrabSpawner=38
2001-04-27 23:12:31 +02:00
ACTOR_ENEMY_NPC, //Shell=39
2001-04-25 18:41:16 +02:00
};
2000-08-29 21:54:22 +02:00
/*****************************************************************************/
2001-02-12 17:06:24 +01:00
int s_globalLevelSelectThing=0;
2001-02-12 18:18:17 +01:00
int CGameScene::s_readyToExit;
2001-03-05 21:01:25 +01:00
int CGameScene::s_levelFinished;
2001-02-21 18:09:19 +01:00
2001-02-12 17:06:24 +01:00
/*****************************************************************************/
2000-08-29 21:54:22 +02:00
CGameScene GameScene;
2001-04-17 22:57:00 +02:00
/*****************************************************************************/
void CGameScene::AspectCorrectCamera()
{
const s32 Scale = (512<<12)/(256);
CamMtx.m[0][0] = ((s32)CamMtx.m[0][0] * Scale)>>12;
CamMtx.m[0][1] = ((s32)CamMtx.m[0][1] * Scale)>>12;
CamMtx.m[0][2] = ((s32)CamMtx.m[0][2] * Scale)>>12;
CamMtx.t[0] = (CamMtx.t[0] * Scale)>>12;
}
2000-08-29 21:54:22 +02:00
/*****************************************************************************/
2000-09-12 01:41:29 +02:00
void CGameScene::init()
2001-04-19 01:12:24 +02:00
{
2001-04-17 22:57:00 +02:00
// Setup Constant Camera Matrix
2001-04-25 18:41:16 +02:00
SetIdentTrans(&CamMtx,0,0,RenderZ);
2001-04-20 13:32:52 +02:00
SetGeomScreen(RenderZ);
2001-04-25 18:41:16 +02:00
SetTransMatrix(&CamMtx);
2001-01-30 19:46:07 +01:00
2000-12-07 16:56:20 +01:00
s_genericFont=new ("CGameScene::Init") FontBank();
s_genericFont->initialise( &standardFont );
s_genericFont->setColour( 255, 255 , 0 );
2001-03-09 00:02:47 +01:00
VidSetClearScreen(0);
2001-01-23 22:05:48 +01:00
2001-04-20 13:32:52 +02:00
2001-01-16 18:34:38 +01:00
2001-02-09 22:41:55 +01:00
m_pauseMenu=new ("Pause Menu") CPauseMenu();
m_pauseMenu->init();
2001-02-12 18:18:17 +01:00
s_readyToExit=false;
2001-03-05 21:01:25 +01:00
2001-03-06 23:14:15 +01:00
CFader::setFadingIn();
initLevel();
2001-01-17 22:53:31 +01:00
2001-04-25 18:41:16 +02:00
}
2001-02-09 18:01:04 +01:00
/*****************************************************************************/
// This is a seperate funtion ( and virtual ) so that we can overload it for
// the demo mode (pkg)
// NB: This function should *only* include the new function - Don't add anything else here!
void CGameScene::createPlayer()
{
m_player=new ("player") CPlayer();
2000-08-29 21:54:22 +02:00
}
2001-02-12 18:24:58 +01:00
// This is also to be overloaded for demomode.. to stop the pause menu appearing
int CGameScene::canPause()
{
return true;
}
2001-02-09 18:01:04 +01:00
2000-08-29 21:54:22 +02:00
/*****************************************************************************/
2000-12-07 16:56:20 +01:00
void CGameScene::shutdown()
2000-08-29 21:54:22 +02:00
{
2001-04-19 01:04:03 +02:00
shutdownLevel();
2001-04-19 01:12:24 +02:00
CSoundMediator::dumpSong();
2001-03-29 18:13:50 +02:00
2001-04-03 23:28:56 +02:00
m_pauseMenu->shutdown(); delete m_pauseMenu;
s_genericFont->dump(); delete s_genericFont;
2000-08-29 21:54:22 +02:00
}
/*****************************************************************************/
2000-09-12 01:41:29 +02:00
void CGameScene::render()
2000-08-29 21:54:22 +02:00
{
2001-04-17 22:57:00 +02:00
// CamMtx.t[2]=ZPos; // Temp
2001-01-15 16:22:33 +01:00
2001-02-09 22:41:55 +01:00
m_pauseMenu->render();
2001-01-22 21:57:39 +01:00
CConversation::render();
2001-02-26 21:42:25 +01:00
CThingManager::renderAllThings();
2001-04-25 18:41:16 +02:00
SetIdentTrans(&CamMtx,0,0,RenderZ);
SetGeomScreen(RenderZ);
SetRotMatrix(&CamMtx);
SetTransMatrix(&CamMtx);
2001-01-12 23:49:25 +01:00
Level.render();
2001-04-27 22:28:47 +02:00
CActorPool::CleanUpCache();
2000-08-29 21:54:22 +02:00
}
/*****************************************************************************/
2000-10-19 17:40:24 +02:00
void CGameScene::think(int _frames)
2000-08-29 21:54:22 +02:00
{
2001-04-19 01:12:24 +02:00
//#ifdef __USER_paul__
2001-02-09 18:01:04 +01:00
// if(!CConversation::isActive()&&PadGetDown(0)&PAD_START)
// {
// CConversation::trigger(SCRIPTS_SPEECHTEST_DAT);
// }
//#endif
2001-01-16 18:34:38 +01:00
2001-03-06 23:14:15 +01:00
if(s_readyToExit)
{
// Temporarily.. exiting game scene always goes back to the front end (pkg)
GameState::setNextScene(&FrontEndScene);
}
else if(s_levelFinished)
{
2001-05-02 22:42:07 +02:00
bool Finished=Level.GetNextLevel(s_globalLevelSelectThing);
2001-04-19 01:04:03 +02:00
shutdownLevel();
2001-03-06 23:14:15 +01:00
initLevel();
2001-05-02 22:42:07 +02:00
s_levelFinished=false;
2001-03-06 23:14:15 +01:00
}
2001-04-19 01:12:24 +02:00
2001-02-12 18:24:58 +01:00
if(!m_pauseMenu->isActive()&&PadGetDown(0)&PAD_START&&canPause())
2001-02-09 22:41:55 +01:00
{
m_pauseMenu->select();
}
2001-04-10 01:22:29 +02:00
/* if (!s_levelFinished) */CConversation::think(_frames);
/* if (!s_levelFinished) */m_pauseMenu->think(_frames);
if(!CConversation::isActive()&& !m_pauseMenu->isActive())
2001-01-16 18:34:38 +01:00
{
2001-01-25 16:25:46 +01:00
DVECTOR camPos;
2001-04-10 01:22:29 +02:00
/* if (!s_levelFinished) */CThingManager::thinkAllThings(_frames);
/* if (!s_levelFinished) */camPos=m_player->getCameraPos();
/* if (!s_levelFinished) */CBubicleFactory::setMapOffset(&camPos);
/* if (!s_levelFinished) */Level.setCameraCentre(camPos);
/* if (!s_levelFinished) */Level.think(_frames);
2001-02-21 18:09:19 +01:00
if(PadGetDown(0)&PAD_R2)
{
2001-03-05 21:01:25 +01:00
levelFinished();
2001-02-21 18:09:19 +01:00
}
2001-01-16 18:34:38 +01:00
}
2001-04-10 01:22:29 +02:00
// s_levelFinished=false;
2000-08-29 21:54:22 +02:00
}
2001-04-10 01:22:29 +02:00
2000-08-29 21:54:22 +02:00
/*****************************************************************************/
2000-10-26 18:50:54 +02:00
int CGameScene::readyToShutdown()
{
2001-02-12 18:18:17 +01:00
return s_readyToExit;
2000-10-26 18:50:54 +02:00
}
/*****************************************************************************/
2001-01-16 20:00:08 +01:00
CPlayer * CGameScene::getPlayer()
{
return( m_player );
}
/*****************************************************************************/
2001-01-16 21:55:44 +01:00
void CGameScene::sendEvent( GAME_EVENT evt, CThing *sourceThing )
{
2001-02-26 21:42:25 +01:00
CThingManager::processEventAllThings(evt, sourceThing);
2001-01-16 21:55:44 +01:00
}
2001-03-06 23:14:15 +01:00
/*****************************************************************************/
void CGameScene::initLevel()
{
2001-04-10 01:22:29 +02:00
printf("InitLevel\n");
2001-03-06 23:14:15 +01:00
CThingManager::init();
CConversation::init();
2001-05-03 00:49:59 +02:00
CConversation::registerConversationLevelScripts( s_globalLevelSelectThing );
2001-03-06 23:14:15 +01:00
s_levelFinished=false;
2001-04-19 01:04:03 +02:00
Level.init(s_globalLevelSelectThing);
2001-03-06 23:14:15 +01:00
createPlayer();
2001-03-07 22:29:07 +01:00
m_player->setRespawnPos(Level.getPlayerSpawnPos());
2001-03-06 23:14:15 +01:00
m_player->init();
m_player->setLayerCollision(Level.getCollisionLayer());
m_player->setMapSize(Level.getMapSize());
2001-03-29 18:13:50 +02:00
2001-04-03 23:28:56 +02:00
// Init actors (needs moving and tidying
2001-04-02 21:21:46 +02:00
int actorNum;
2001-04-08 22:46:34 +02:00
int platformNum;
2001-05-01 15:28:11 +02:00
int hazardNum;
2001-04-02 21:21:46 +02:00
2001-04-04 02:16:26 +02:00
sThingActor **actorList = Level.getActorList();
if (actorList)
{
2001-04-04 18:51:04 +02:00
for ( actorNum = 0 ; actorNum < Level.getActorCount() ; actorNum++ )
2001-04-02 21:21:46 +02:00
{
2001-04-20 17:43:35 +02:00
sThingActor *ThisActor=actorList[actorNum];
2001-04-25 18:41:16 +02:00
CGameScene::ACTOR_TYPE actorType = CGameScene::getActorType( actorList[actorNum]->Type );
2001-04-04 18:51:04 +02:00
switch ( actorType )
{
2001-04-25 18:41:16 +02:00
case CGameScene::ACTOR_ENEMY_NPC:
2001-04-20 00:09:59 +02:00
{
2001-04-20 17:43:35 +02:00
CNpcEnemy *enemy;
enemy=CNpcEnemy::Create(ThisActor);
enemy->setLayerCollision( Level.getCollisionLayer() );
2001-04-20 18:25:35 +02:00
enemy->setupWaypoints( ThisActor );
2001-04-20 17:43:35 +02:00
enemy->postInit();
}
2001-04-19 01:12:24 +02:00
break;
2001-04-27 17:09:10 +02:00
case CGameScene::ACTOR_FRIEND_NPC:
{
CNpcFriend *friendNpc;
friendNpc=CNpcFriend::Create(ThisActor);
friendNpc->setLayerCollision( Level.getCollisionLayer() );
2001-05-03 00:49:59 +02:00
friendNpc->postInit();
2001-04-27 17:09:10 +02:00
}
break;
2001-04-04 18:51:04 +02:00
default:
break;
2001-04-02 21:21:46 +02:00
}
}
2001-04-04 02:16:26 +02:00
}
2001-04-08 22:46:34 +02:00
sThingPlatform **platformList = Level.getPlatformList();
if (platformList)
{
for ( platformNum = 0 ; platformNum < Level.getPlatformCount() ; platformNum++ )
{
2001-04-23 22:40:13 +02:00
sThingPlatform *ThisPlatform = platformList[platformNum];
2001-04-08 22:46:34 +02:00
CNpcPlatform *platform;
2001-04-23 22:40:13 +02:00
platform = CNpcPlatform::Create( ThisPlatform );
2001-04-08 22:46:34 +02:00
platform->setLayerCollision( Level.getCollisionLayer() );
2001-04-23 22:40:13 +02:00
platform->postInit();
2001-04-08 22:46:34 +02:00
}
}
2001-05-01 15:28:11 +02:00
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() );
}
}
2001-03-29 18:13:50 +02:00
// Song is loaded/dumped by the level, and played from here. This just gives some
// better timing over when it starts (pkg)
CSoundMediator::playSong();
2001-04-25 18:41:16 +02:00
CActorPool::SetUpCache();
2001-04-10 01:22:29 +02:00
printf("InitLevelDone\n");
2001-03-06 23:14:15 +01:00
}
/*****************************************************************************/
2001-04-19 01:04:03 +02:00
void CGameScene::shutdownLevel()
2001-03-06 23:14:15 +01:00
{
CConversation::shutdown();
CThingManager::shutdown();
2001-04-19 01:04:03 +02:00
Level.shutdown();
2001-03-06 23:14:15 +01:00
}
2001-04-19 01:12:24 +02:00
/*****************************************************************************/