SBSPSS/source/game/game.cpp

915 lines
20 KiB
C++
Raw Normal View History

2001-08-07 21:09:29 +02:00
int counter=0;
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-05-10 16:09:06 +02:00
#ifndef __JELLFISH_JELLFISH_H__
#include "jellfish\jellfish.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-03-29 18:13:50 +02:00
#ifndef __SOUND_SOUND_H__
#include "sound\sound.h"
#endif
2001-06-11 18:16:04 +02:00
#ifndef __MAP_MAP_H__
#include "map\map.h"
#endif
2001-06-12 01:30:23 +02:00
#ifndef __SHOP_SHOP_H__
#include "shop\shop.h"
#endif
2001-06-11 20:24:32 +02:00
#ifndef __FMA_FMA_H__
#include "fma\fma.h"
#endif
2001-07-10 20:15:12 +02:00
#ifndef __BACKEND_GAMEOVER_H__
#include "backend\gameover.h"
#endif
2001-06-12 20:56:40 +02:00
#ifndef __GAME_GAMESLOT_H__
#include "game\gameslot.h"
#endif
2001-06-14 23:08:42 +02:00
#ifndef __GAME_HEALTH_MANAGER_H__
#include "game\healthman.h"
#endif
2001-07-02 21:12:27 +02:00
#ifndef __LOCALE_TEXTDBASE_H__
#include "locale\textdbase.h"
#endif
2001-08-02 17:46:19 +02:00
#ifndef __SAVE_SAVE_H__
#include "save\save.h"
#endif
2001-06-11 20:24:32 +02:00
2001-08-03 18:15:46 +02:00
#ifndef __GAME_BOSSTEXT_H__
#include "game\bosstext.h"
#endif
2001-04-01 22:22:49 +02:00
#include "gfx\actor.h"
2001-03-29 18:13:50 +02:00
2000-08-29 21:54:22 +02:00
/*****************************************************************************/
2001-05-25 20:43:47 +02:00
FontBank *CGameScene::s_genericFont;
SpriteBank *CGameScene::s_GlobalSpritebank;
CLayerCollision *CGameScene::s_GlobalCollision;
2001-06-14 23:08:42 +02:00
CHealthManager *CGameScene::m_HealthManager;
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-06-28 22:21:02 +02:00
int s_globalLevelSelectThing=0;
int CGameScene::s_readyToExit;
int CGameScene::s_levelFinished;
2001-06-11 18:16:04 +02:00
#ifdef __VERSION_DEBUG__
2001-06-28 22:21:02 +02:00
int CGameScene::s_skipToNextLevel;
2001-06-11 18:16:04 +02:00
#endif
2001-06-28 22:21:02 +02:00
int CGameScene::s_restartLevel;
int CGameScene::s_bossHasBeenKilled;
int CGameScene::s_justHitBossArenaTrigger;
DVECTOR CGameScene::s_CamShake={0,0};
2001-08-07 21:09:29 +02:00
int CGameScene::s_showBossTextOnRespawn;
2001-02-21 18:09:19 +01:00
2001-07-02 21:12:27 +02:00
2001-08-03 18:15:46 +02:00
// Evil global pointer to the boss character
CThing *g_bossThing;
2001-06-27 17:59:15 +02:00
2001-07-02 21:12:27 +02:00
2001-06-27 17:59:15 +02:00
/*****************************************************************************/
2001-02-12 17:06:24 +01:00
2000-08-29 21:54:22 +02:00
CGameScene GameScene;
/*****************************************************************************/
2000-09-12 01:41:29 +02:00
void CGameScene::init()
2001-04-19 01:12:24 +02:00
{
2001-07-02 16:26:38 +02:00
setCameraMtx();
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-01-23 22:05:48 +01:00
2001-06-26 17:24:17 +02:00
m_scalableFont=new ("CountdownTimerFont") ScalableFontBank();
2001-06-12 23:27:53 +02:00
m_scalableFont->initialise(&standardFont);
m_scalableFont->setColour(255,255,255);
m_scalableFont->setScale(511);
2001-04-20 13:32:52 +02:00
2001-06-12 23:27:53 +02:00
VidSetClearScreen(0);
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-06-14 23:08:42 +02:00
m_HealthManager= new ("Health Manager") CHealthManager();
m_HealthManager->init();
2001-02-12 18:18:17 +01:00
s_readyToExit=false;
2001-05-11 01:20:45 +02:00
s_restartLevel=false;
2001-03-05 21:01:25 +01:00
2001-08-03 18:15:46 +02:00
m_bossText=new ("BossText") CBossText();
2001-08-03 20:09:54 +02:00
m_bossText->init();
2001-08-03 18:15:46 +02:00
2001-03-06 23:14:15 +01:00
CFader::setFadingIn();
2001-07-05 23:26:39 +02:00
CLevel::setIsBossRespawn(false);
2001-03-06 23:14:15 +01:00
initLevel();
2001-01-17 22:53:31 +01:00
2001-06-21 22:51:55 +02:00
m_gamestate=GAMESTATE_SHOWING_LIVES;
m_showingLivesTimer=0;
2001-08-03 18:15:46 +02:00
2001-08-07 21:09:29 +02:00
s_showBossTextOnRespawn=false;
2001-08-10 22:14:50 +02:00
m_playingBossMusic=false;
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();
2001-05-29 20:40:38 +02:00
m_player->setThingSubType(0);
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()
{
2001-06-21 22:51:55 +02:00
return m_gamestate==GAMESTATE_PLAYING;
2001-02-12 18:24:58 +01:00
}
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-08-03 18:15:46 +02:00
m_bossText->shutdown(); delete m_bossText;
2001-04-19 01:04:03 +02:00
shutdownLevel();
2001-03-29 18:13:50 +02:00
2001-04-03 23:28:56 +02:00
m_pauseMenu->shutdown(); delete m_pauseMenu;
2001-06-12 23:27:53 +02:00
m_scalableFont->dump(); delete m_scalableFont;
2001-04-03 23:28:56 +02:00
s_genericFont->dump(); delete s_genericFont;
2001-06-14 23:08:42 +02:00
m_HealthManager->shutdown();delete m_HealthManager;
2000-08-29 21:54:22 +02:00
}
/*****************************************************************************/
2000-09-12 01:41:29 +02:00
void CGameScene::render()
2001-06-21 22:51:55 +02:00
{
switch(m_gamestate)
{
case GAMESTATE_SHOWING_LIVES:
2001-08-04 22:58:56 +02:00
case GAMESTATE_SHOWING_LIVES_BUT_GOING_TO_BOSS_TEXT:
2001-06-21 22:51:55 +02:00
render_showing_lives();
break;
case GAMESTATE_PLAYING:
2001-06-25 23:47:22 +02:00
case GAMESTATE_FADING_INTO_BOSS_INTRO:
2001-08-04 21:16:11 +02:00
case GAMESTATE_TELEPORT_START:
case GAMESTATE_TELEPORT_END:
2001-06-21 22:51:55 +02:00
render_playing();
break;
2001-06-25 23:47:22 +02:00
case GAMESTATE_BOSS_INTRO:
2001-08-03 18:15:46 +02:00
m_bossText->render();
2001-06-25 23:47:22 +02:00
break;
2001-06-21 22:51:55 +02:00
}
}
/*****************************************************************************/
void CGameScene::render_showing_lives()
{
int colour;
2001-07-10 20:15:12 +02:00
char buf[20];
2001-06-21 22:51:55 +02:00
POLY_F4 *f4;
POLY_FT3 *ft3;
colour=m_showingLivesTimer-TIME_TO_DISPLAY_LIVES_COUNT;
if(colour<0)
{
colour=0;
}
else
{
colour*=SPEED_OF_FADE;
if(colour>255)
{
colour=255;
}
}
colour=255-colour;
// Text
2001-08-02 18:24:35 +02:00
m_scalableFont->setPrintArea(0,0,512,256);
2001-06-21 22:51:55 +02:00
s_genericFont->setJustification(FontBank::JUST_CENTRE);
s_genericFont->setColour(colour,colour,colour);
s_genericFont->setTrans(1);
s_genericFont->setSMode(1);
s_genericFont->print(256,50,"Now entering:");
s_genericFont->print(256,80,Level.getChapterLoadingText());
s_genericFont->print(256,100,Level.getLevelLoadingText());
2001-07-10 20:15:12 +02:00
sprintf(buf,"Lives x %d",CGameSlotManager::getSlotData()->m_lives);
s_genericFont->print(256,140,buf);
2001-06-21 22:51:55 +02:00
// Black background
f4=GetPrimF4();
setXYWH(f4,0,0,512,256);
setRGB0(f4,colour,colour,colour);
setShadeTex(f4,0);
setSemiTrans(f4,1);
AddPrimToList(f4,0);
ft3=GetPrimFT3();
setPolyFT3(ft3);
setShadeTex(ft3,1);
setSemiTrans(ft3,1);
ft3->tpage=2<<5;
setXY3(ft3,512,512,512,512,512,512);
AddPrimToList(ft3,0);
2001-08-04 22:58:56 +02:00
if(m_gamestate==GAMESTATE_SHOWING_LIVES_BUT_GOING_TO_BOSS_TEXT)
{
m_bossText->render();
}
else
{
render_playing();
}
2001-06-21 22:51:55 +02:00
}
/*****************************************************************************/
void CGameScene::render_playing()
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-06-12 23:27:53 +02:00
if(m_levelHasTimer)
{
int timerValue;
char buf[10];
timerValue=m_timer/55;
if(timerValue<0)timerValue=0;
sprintf(buf,"%d",timerValue);
2001-08-02 21:19:01 +02:00
if(timerValue<=5)
{
m_scalableFont->setColour(255,0,0);
}
else
{
m_scalableFont->setColour(255,255,255);
}
2001-08-10 18:05:05 +02:00
m_scalableFont->setScale(511);
2001-06-21 21:19:15 +02:00
m_scalableFont->print(VidGetScrW()/2,30,buf);
2001-06-12 23:27:53 +02: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
2001-07-02 16:26:38 +02:00
setCameraMtx();
2001-04-25 18:41:16 +02:00
2001-01-12 23:49:25 +01:00
Level.render();
2001-06-14 23:08:42 +02:00
m_HealthManager->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)
2001-06-21 22:51:55 +02:00
{
2001-08-04 21:16:11 +02:00
//#if defined (__USER_paul__)
//if(PadGetDown(0)&PAD_UP)
//{
//}
//#endif
2001-07-03 22:28:04 +02:00
if(!m_musicStarted&&!CFader::isFading())
{
// 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-07-09 17:32:51 +02:00
CSoundMediator::setCanPlaySfx(true);
2001-07-03 22:28:04 +02:00
m_musicStarted=true;
}
2001-06-21 22:51:55 +02:00
switch(m_gamestate)
{
case GAMESTATE_SHOWING_LIVES:
think_showing_lives(_frames);
break;
2001-08-04 22:58:56 +02:00
case GAMESTATE_SHOWING_LIVES_BUT_GOING_TO_BOSS_TEXT:
think_showing_lives(_frames);
break;
2001-06-21 22:51:55 +02:00
case GAMESTATE_PLAYING:
think_playing(_frames);
break;
2001-06-25 23:47:22 +02:00
case GAMESTATE_FADING_INTO_BOSS_INTRO:
if(!CFader::isFading())
{
2001-08-03 18:15:46 +02:00
m_bossText->select();
2001-06-25 23:47:22 +02:00
m_gamestate=GAMESTATE_BOSS_INTRO;
CFader::setFadingIn();
}
break;
case GAMESTATE_BOSS_INTRO:
2001-08-03 18:15:46 +02:00
m_bossText->think(_frames);
if(m_bossText->isReadyToExit())
2001-06-25 23:47:22 +02:00
{
m_gamestate=GAMESTATE_PLAYING;
2001-08-10 22:14:50 +02:00
if(!m_playingBossMusic)
{
CSoundMediator::playSong();
m_playingBossMusic=true;
}
2001-08-03 18:15:46 +02:00
sendEvent( BOSS_FOUND_EVENT, NULL );
2001-06-25 23:47:22 +02:00
CFader::setFadingIn();
}
break;
2001-08-04 21:16:11 +02:00
case GAMESTATE_TELEPORT_START:
if(!CFader::isFading())
{
think_playing(1); // Let the teleport happen..
think_playing(1);
think_playing(1);
m_gamestate=GAMESTATE_TELEPORT_END;
2001-08-06 17:56:40 +02:00
CFader::setFadingIn();
2001-08-04 21:16:11 +02:00
}
break;
case GAMESTATE_TELEPORT_END:
if(!CFader::isFading())
{
m_gamestate=GAMESTATE_PLAYING;
}
break;
2001-06-21 22:51:55 +02:00
}
2001-07-31 18:33:11 +02:00
#ifdef __VERSION_DEBUG__
2001-08-01 16:02:08 +02:00
#if defined (__USER_paul__) || defined (__USER_daveo__) || defined (__USER_charles__)
2001-07-31 18:33:11 +02:00
char buf[20];
sprintf(buf,"Frames: %d",_frames);
m_scalableFont->setTrans(0);
m_scalableFont->setSMode(0);
m_scalableFont->setColour(128,128,128);
m_scalableFont->setScale(300);
m_scalableFont->print(40,200,buf);
#endif
2001-08-01 16:02:08 +02:00
#endif
2001-08-07 21:09:29 +02:00
counter+=_frames;
2001-06-21 22:51:55 +02:00
}
/*****************************************************************************/
void CGameScene::think_showing_lives(int _frames)
{
2001-08-04 22:58:56 +02:00
if(m_gamestate!=GAMESTATE_SHOWING_LIVES_BUT_GOING_TO_BOSS_TEXT)
2001-06-21 22:51:55 +02:00
{
2001-08-04 22:58:56 +02:00
if(m_showingLivesTimer==0)
{
think_playing(0);
}
else if((m_showingLivesTimer-TIME_TO_DISPLAY_LIVES_COUNT)*SPEED_OF_FADE>128)
{
think_playing(_frames);
}
2001-06-21 22:51:55 +02:00
}
if(PadGetDown(0)&PAD_CROSS&&m_showingLivesTimer<TIME_TO_DISPLAY_LIVES_COUNT)
{
m_showingLivesTimer=TIME_TO_DISPLAY_LIVES_COUNT;
m_player->ignoreNewlyPressedButtonsOnPadThisThink();
}
if(_frames>2)
{
_frames=2;
}
m_showingLivesTimer+=_frames;
if((m_showingLivesTimer-TIME_TO_DISPLAY_LIVES_COUNT)*SPEED_OF_FADE>255)
{
2001-08-04 22:58:56 +02:00
if(m_gamestate!=GAMESTATE_SHOWING_LIVES_BUT_GOING_TO_BOSS_TEXT)
{
m_gamestate=GAMESTATE_PLAYING;
}
else
{
m_gamestate=GAMESTATE_BOSS_INTRO;
}
2001-06-21 22:51:55 +02:00
}
}
/*****************************************************************************/
void CGameScene::think_playing(int _frames)
2000-08-29 21:54:22 +02:00
{
2001-06-21 00:57:27 +02:00
if(s_readyToExit)
{
return;
}
2001-01-16 18:34:38 +01:00
2001-08-04 22:58:56 +02:00
if(s_justHitBossArenaTrigger)
2001-06-25 23:47:22 +02:00
{
2001-08-04 22:58:56 +02:00
if(m_gamestate==GAMESTATE_SHOWING_LIVES)
{
m_bossText->select();
m_gamestate=GAMESTATE_SHOWING_LIVES_BUT_GOING_TO_BOSS_TEXT;
s_justHitBossArenaTrigger=false;
}
else if(m_gamestate==GAMESTATE_PLAYING)
{
m_gamestate=GAMESTATE_FADING_INTO_BOSS_INTRO;
CFader::setFadingOut();
s_justHitBossArenaTrigger=false;
}
2001-06-25 23:47:22 +02:00
}
2001-06-12 23:27:53 +02:00
// Auto-timer stuff
2001-07-10 21:21:36 +02:00
if(m_levelHasTimer&&
!CConversation::isActive()&&!m_pauseMenu->isActive())
2001-06-12 23:27:53 +02:00
{
2001-08-02 21:19:01 +02:00
int oldTimer;
oldTimer=m_timer/55;
2001-06-12 23:27:53 +02:00
m_timer-=_frames;
2001-08-02 21:19:01 +02:00
if(oldTimer>m_timer/55)
{
CSoundMediator::playSfx(oldTimer>6?CSoundMediator::SFX_BEEP3:CSoundMediator::SFX_BEEP7);
}
2001-06-12 23:27:53 +02:00
if(m_timer<0)
{
s_levelFinished=true;
}
}
2001-06-21 00:57:27 +02:00
if(s_levelFinished)
2001-03-06 23:14:15 +01:00
{
2001-06-12 20:56:40 +02:00
// Do the gameslot stuff..
CGameSlotManager::GameSlot *gameSlot;
int level,chapter;
int openNextLevel,levelToOpen,chapterToOpen;
gameSlot=CGameSlotManager::getSlotData();
level=getLevelNumber();
chapter=getChapterNumber();
2001-06-14 17:19:57 +02:00
// Open next level?
2001-06-12 20:56:40 +02:00
gameSlot->levelHasBeenCompleted(chapter-1,level-1);
if(level!=5&& // Don't open any levels after finishing a bonus level
!(level==4&&chapter==5)) // Don't open any levels after finishing final level
{
if(level!=4)
{
// Open next level in this chapter..
levelToOpen=level+1;
chapterToOpen=chapter;
}
else
{
// Open first level in next chapter
levelToOpen=1;
chapterToOpen=chapter+1;
}
gameSlot->levelIsNowOpen(chapterToOpen-1,levelToOpen-1);
2001-06-13 16:28:41 +02:00
CMapScene::setLevelToStartOn(chapterToOpen-1,levelToOpen-1);
2001-06-12 20:56:40 +02:00
}
2001-06-14 17:19:57 +02:00
// New hi-spatula-count?
if(m_player->getSpatulasHeld()>gameSlot->getSpatulaCollectedCount(chapter-1,level-1))
{
gameSlot->setSpatulaCollectedCount(chapter-1,level-1,m_player->getSpatulasHeld(),getTotalSpatCountForThisLevel());
}
2001-06-11 20:24:32 +02:00
// Level finished - go to map or fma
2001-06-22 22:06:39 +02:00
CFmaScene::FMA_SCRIPT_NUMBER fma;
fma=Level.getFMAToFollow();
if(fma!=CFmaScene::FMA_SCRIPT__NONE)
2001-06-11 20:24:32 +02:00
{
2001-06-22 22:06:39 +02:00
FmaScene.selectFma(fma);
2001-06-11 20:24:32 +02:00
GameState::setNextScene(&FmaScene);
2001-08-02 17:46:19 +02:00
// After the last FMA it goes to save. We then need to make it go to PARTY
SaveScene.setNextScene(CSaveScene::NEXTSCENE_PARTY);
2001-06-11 20:24:32 +02:00
}
2001-06-12 20:56:40 +02:00
else if(level==5)
2001-06-12 01:30:23 +02:00
{
GameState::setNextScene(&ShopScene);
}
2001-06-11 20:24:32 +02:00
else
{
GameState::setNextScene(&MapScene);
}
2001-06-11 18:16:04 +02:00
s_readyToExit=true;
2001-06-21 00:57:27 +02:00
s_levelFinished=false;
CFader::setFadingOut();
2001-06-11 18:16:04 +02:00
}
#ifdef __VERSION_DEBUG__
else if(s_skipToNextLevel)
{
// Skip to next level
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-06-11 18:16:04 +02:00
s_skipToNextLevel=false;
2001-03-06 23:14:15 +01:00
}
2001-06-11 18:16:04 +02:00
#endif
2001-05-11 01:20:45 +02:00
else if (s_restartLevel)
{
2001-07-31 23:01:04 +02:00
if(getLevelNumber()==5)
{
// Bonus level.. go back to map after death
GameState::setNextScene(&MapScene);
s_readyToExit=true;
s_levelFinished=false;
CFader::setFadingOut();
}
else if(m_player->getLivesLeft()>=0)
2001-05-11 23:35:08 +02:00
{
respawnLevel();
}
else
{
s_readyToExit=true;
2001-07-10 20:15:12 +02:00
GameState::setNextScene(&GameOverScene);
2001-06-21 00:57:27 +02:00
CFader::setFadingOut();
2001-05-11 23:35:08 +02:00
}
2001-05-11 01:20:45 +02:00
s_restartLevel=false;
}
2001-03-06 23:14:15 +01:00
2001-04-19 01:12:24 +02:00
2001-07-04 22:01:43 +02:00
if(canPause()&&!m_pauseMenu->isActive())
2001-02-09 22:41:55 +01:00
{
2001-07-04 22:01:43 +02:00
if(PadGetDown(0)&PAD_START||!PadIsConnected(0))
{
m_pauseMenu->select();
}
2001-02-09 22:41:55 +01:00
}
2001-06-20 21:32:03 +02:00
// Conversation think ( with pad debounce stuff.. )
if(CConversation::isActive())m_player->ignoreNewlyPressedButtonsOnPadThisThink();
2001-07-24 17:06:30 +02:00
if(!m_pauseMenu->isActive())
{
CConversation::think(_frames);
}
else
{
// Must be a better way to do this? :/
CConversation::ignoreNewlyPressedButtonsOnPadThisThink();
}
2001-06-20 21:32:03 +02:00
// Pause menu think ( with pad debounce stuff.. )
if(m_pauseMenu->isActive())m_player->ignoreNewlyPressedButtonsOnPadThisThink();
2001-06-11 18:16:04 +02:00
m_pauseMenu->think(_frames);
2001-06-20 21:32:03 +02:00
if(!CConversation::isActive()&&!m_pauseMenu->isActive())
2001-01-16 18:34:38 +01:00
{
2001-07-23 21:26:37 +02:00
DVECTOR camPos;
2001-05-10 16:09:06 +02:00
CJellyfishGenerator::think( _frames, &Level );
2001-06-11 18:16:04 +02:00
CThingManager::thinkAllThings(_frames);
camPos=m_player->getCameraPos();
CBubicleFactory::setMapOffset(&camPos);
Level.setCameraCentre(camPos);
Level.think(_frames);
2001-06-28 22:21:02 +02:00
thinkCameraShake(_frames);
2001-06-14 23:08:42 +02:00
m_HealthManager->think(_frames);
m_HealthManager->checkPlayerCol(getPlayer());
2001-02-21 18:09:19 +01:00
2001-06-11 18:16:04 +02:00
#ifdef __VERSION_DEBUG__
2001-02-21 18:09:19 +01:00
if(PadGetDown(0)&PAD_R2)
{
2001-06-11 18:16:04 +02:00
s_skipToNextLevel=true;
2001-02-21 18:09:19 +01:00
}
2001-06-11 18:16:04 +02:00
#endif
2001-01-16 18:34:38 +01:00
}
2000-08-29 21:54:22 +02:00
}
2001-06-25 23:47:22 +02:00
2000-08-29 21:54:22 +02:00
/*****************************************************************************/
2000-10-26 18:50:54 +02:00
int CGameScene::readyToShutdown()
{
2001-06-21 00:57:27 +02:00
return s_readyToExit&&!CFader::isFading();
2000-10-26 18:50:54 +02:00
}
/*****************************************************************************/
2001-01-16 20:00:08 +01:00
CPlayer * CGameScene::getPlayer()
{
return( m_player );
}
2001-05-13 23:06:26 +02:00
/*****************************************************************************/
int CGameScene::getChapterNumber()
{
return Level.getCurrentChapter();
}
int CGameScene::getLevelNumber()
{
return Level.getCurrentChapterLevel();
}
int CGameScene::getTotalSpatCountForThisLevel()
{
return Level.getTotalSpatCount();
}
2001-08-04 21:16:11 +02:00
/*****************************************************************************/
int CGameScene::triggerTeleportEffect()
{
2001-08-16 21:20:30 +02:00
if(m_gamestate==GAMESTATE_PLAYING)
2001-08-04 21:16:11 +02:00
{
m_gamestate=GAMESTATE_TELEPORT_START;
2001-08-06 17:56:40 +02:00
CFader::setFadingOut();
2001-08-04 21:16:11 +02:00
return true;
}
return false;
}
2001-05-04 21:34:09 +02:00
/*****************************************************************************/
void CGameScene::respawnLevel()
{
2001-07-09 17:32:51 +02:00
CSoundMediator::setCanPlaySfx(false);
2001-05-11 01:20:45 +02:00
m_player->respawn();
2001-05-04 21:34:09 +02:00
Level.respawnLevel();
2001-08-07 21:09:29 +02:00
if(!s_showBossTextOnRespawn)
{
m_gamestate=GAMESTATE_SHOWING_LIVES;
}
else
{
m_gamestate=GAMESTATE_SHOWING_LIVES_BUT_GOING_TO_BOSS_TEXT;
2001-08-10 22:14:50 +02:00
m_bossText->select(m_playingBossMusic);
2001-08-07 21:09:29 +02:00
}
2001-06-21 22:51:55 +02:00
m_showingLivesTimer=0;
2001-07-09 17:32:51 +02:00
CSoundMediator::setCanPlaySfx(true);
2001-05-04 21:34:09 +02:00
}
2001-01-16 20:00:08 +01:00
/*****************************************************************************/
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
2001-06-21 00:57:27 +02:00
/*****************************************************************************/
void CGameScene::setReadyToExit()
{
s_readyToExit=true;
GameState::setNextScene(&FrontEndScene);
2001-07-29 20:39:42 +02:00
CFrontEndScene::setStartMode(CFrontEndScene::MODE__CHOOSE_SLOT);
2001-06-21 00:57:27 +02:00
CFader::setFadingOut();
}
2001-08-09 17:21:08 +02:00
/*****************************************************************************/
void CGameScene::setBossHasBeenKilled()
{
s_bossHasBeenKilled=true;
s_showBossTextOnRespawn=false;
}
2001-06-25 23:47:22 +02:00
/*****************************************************************************/
void CGameScene::hitBossArenaTrigger()
{
2001-08-16 21:20:30 +02:00
if(!s_showBossTextOnRespawn)
2001-08-07 21:09:29 +02:00
{
s_justHitBossArenaTrigger=true;
s_showBossTextOnRespawn=true;
}
2001-06-25 23:47:22 +02:00
}
2001-03-06 23:14:15 +01:00
/*****************************************************************************/
void CGameScene::initLevel()
{
2001-08-03 18:15:46 +02:00
g_bossThing=NULL;
2001-07-09 17:32:51 +02:00
CSoundMediator::setCanPlaySfx(false);
2001-07-28 18:45:46 +02:00
Level.DisplayLoadingScreen(s_globalLevelSelectThing);
2001-07-09 17:32:51 +02:00
2001-05-25 20:43:47 +02:00
SYSTEM_DBGMSG("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-06-11 18:16:04 +02:00
#ifdef __VERSION_DEBUG__
s_skipToNextLevel=false;
#endif
2001-07-05 23:26:39 +02:00
CActorPool::Reset();
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();
2001-08-08 20:46:51 +02:00
m_player->setFacing(Level.getPlayerStartFacing());
2001-06-12 23:45:33 +02:00
if(getLevelNumber()==5)
{
m_player->setCanExitLevelNow();
}
2001-08-15 16:14:13 +02:00
DVECTOR const &mapSize=Level.getMapSize();
2001-05-04 03:35:52 +02:00
CPlayer::CameraBox camBox={0,0,mapSize.vx<<4,mapSize.vy<<4};
2001-05-03 20:42:56 +02:00
m_player->setCameraBox(camBox);
2001-03-29 18:13:50 +02:00
2001-06-12 17:41:47 +02:00
s_bossHasBeenKilled=false;
2001-06-25 23:47:22 +02:00
s_justHitBossArenaTrigger=false;
2001-06-12 17:41:47 +02:00
2001-08-02 15:39:25 +02:00
if(getLevelNumber()==5&&getChapterNumber()==1)
2001-06-12 23:27:53 +02:00
{
m_levelHasTimer=true;
m_timer=30*55;
}
else
{
m_levelHasTimer=false;
}
2001-04-25 18:41:16 +02:00
CActorPool::SetUpCache();
2001-07-03 22:28:04 +02:00
m_musicStarted=false;
2001-07-26 18:14:58 +02:00
SetPadRescan();
2001-07-03 22:28:04 +02:00
2001-08-03 20:09:54 +02:00
StopLoad();
2001-05-25 20:43:47 +02:00
SYSTEM_DBGMSG("InitLevelDone\n");
2001-03-06 23:14:15 +01:00
}
2001-08-16 20:34:51 +02:00
/*****************************************************************************/
void CGameScene::initHealth()
{
m_HealthManager->init();
}
2001-06-14 23:08:42 +02:00
/*****************************************************************************/
2001-07-23 21:26:37 +02:00
void CGameScene::dropHealth(DVECTOR const &Pos,int Amount,int Vel)
2001-06-14 23:08:42 +02:00
{
2001-06-15 00:03:03 +02:00
m_HealthManager->drop(Pos,Amount,Vel);
2001-06-14 23:08:42 +02:00
}
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
{
2001-05-04 17:22:57 +02:00
CSoundMediator::dumpSong();
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-06-28 22:21:02 +02:00
/*****************************************************************************/
void CGameScene::setCameraShake(s16 X,s16 Y)
{
s_CamShake.vx=X;
s_CamShake.vy=Y;
}
/*****************************************************************************/
void CGameScene::shakeCamera(DVECTOR &CamPos)
{
CamPos.vx+=s_CamShake.vx;
CamPos.vy+=s_CamShake.vy;
}
/*****************************************************************************/
void CGameScene::thinkCameraShake(int _frames)
{
if (s_CamShake.vx)
{
if (s_CamShake.vx<0)
{
s_CamShake.vx=-(s_CamShake.vx+1);
}
else
{
s_CamShake.vx=-(s_CamShake.vx-1);
}
}
if (s_CamShake.vy)
{
if (s_CamShake.vy<0)
{
s_CamShake.vy=-(s_CamShake.vy+1);
}
else
{
s_CamShake.vy=-(s_CamShake.vy-1);
}
}
}
2001-07-02 16:26:38 +02:00
/*****************************************************************************/
void CGameScene::setCameraMtx()
{
MATRIX CamMtx;
2001-08-03 23:07:41 +02:00
SetIdentTrans(&CamMtx,0,0,RENDER_Z);
SetGeomScreen(RENDER_Z);
2001-07-02 16:26:38 +02:00
SetRotMatrix(&CamMtx);
SetTransMatrix(&CamMtx);
}