SBSPSS/source/backend/gameover.cpp

470 lines
10 KiB
C++
Raw Normal View History

2001-01-11 20:40:55 +01:00
/*=========================================================================
gameover.cpp
Author: PKG
Created:
Project: Spongebob
2001-06-04 16:44:19 +02:00
Purpose:
2001-01-11 20:40:55 +01:00
Copyright (c) 2001 Climax Development Ltd
===========================================================================*/
/*----------------------------------------------------------------------
Includes
-------- */
#include "backend\gameover.h"
#ifndef __GFX_FONT_H__
#include "gfx\font.h"
#endif
#ifndef __PAD_PADS_H__
#include "pad\pads.h"
#endif
2001-07-10 20:15:12 +02:00
#ifndef __MAP_MAP_H__
#include "map\map.h"
2001-06-04 23:54:14 +02:00
#endif
2001-01-11 20:40:55 +01:00
#ifndef __FRONTEND_FRONTEND_H__
#include "frontend\frontend.h"
#endif
#ifndef __GFX_FADER_H__
#include "gfx\fader.h"
#endif
2001-05-31 23:17:33 +02:00
#ifndef _FILEIO_HEADER_
#include "fileio\fileio.h"
#endif
#ifndef __VID_HEADER_
#include "system\vid.h"
#endif
#ifndef __MATHTABLE_HEADER__
#include "utils\mathtab.h"
#endif
#ifndef __LOCALE_TEXTDBASE_H__
#include "locale\textdbase.h"
#endif
2001-07-10 20:15:12 +02:00
#ifndef __GAME_GAMESLOT_H__
#include "game\gameslot.h"
#endif
2001-07-11 18:15:44 +02:00
#ifndef __ACTOR_HEADER__
#include "gfx\actor.h"
#endif
#ifndef __SOUND_SOUND_H__
#include "sound\sound.h"
#endif
2001-01-11 20:40:55 +01:00
/* Std Lib
------- */
/* Data
---- */
#ifndef __STRING_ENUMS__
#include <trans.h>
#endif
2001-07-11 18:15:44 +02:00
#ifndef __ANIM_PATRICK_HEADER__
#include <actor_patrick_anim.h>
#endif
2001-01-11 20:40:55 +01:00
/*----------------------------------------------------------------------
Tyepdefs && Defines
------------------- */
/*----------------------------------------------------------------------
Structure defintions
-------------------- */
/*----------------------------------------------------------------------
Function Prototypes
------------------- */
/*----------------------------------------------------------------------
Vars
---- */
CGameOverScene GameOverScene;
/*----------------------------------------------------------------------
Function:
Purpose:
Params:
Returns:
---------------------------------------------------------------------- */
void CGameOverScene::init()
{
2001-05-31 23:17:33 +02:00
m_image=CFileIO::loadFile(BACKDROP_GAMEOVER_GFX);
ASSERT(m_image);
SetScreenImage((u8*)m_image);
m_font=new ("game over font") ScalableFontBank();
2001-01-11 20:40:55 +01:00
m_font->initialise(&standardFont);
2001-05-31 23:17:33 +02:00
m_font->setJustification(ScalableFontBank::JUST_CENTRE);
2001-04-24 18:18:42 +02:00
m_font->setOt(5);
2001-01-11 20:40:55 +01:00
2001-07-11 18:15:44 +02:00
CActorPool::Reset();
2001-07-11 22:05:02 +02:00
m_anotherGfx=CActorPool::GetActor(ACTORS_SPONGEBOB_SBK);
2001-07-11 18:15:44 +02:00
m_patrickGfx=CActorPool::GetActor(ACTORS_PATRICK_SBK);
m_animFrame=0;
CActorPool::SetUpCache();
CActorPool::CleanUpCache();
2001-01-11 20:40:55 +01:00
m_readyToExit=false;
2001-06-21 00:57:27 +02:00
CFader::setFadingIn();
2001-05-31 23:17:33 +02:00
initContinue();
initGameOver();
2001-07-10 20:15:12 +02:00
if(CGameSlotManager::getSlotData()->m_continues>=1)
{
m_state=STATE__CONTINUE;
}
else
{
m_state=STATE__GAME_OVER;
}
2001-07-11 18:15:44 +02:00
m_hasPlayedFirstSpeech=false;
m_hasPlayedSecondSpeech=false;
2001-01-11 20:40:55 +01:00
}
/*----------------------------------------------------------------------
Function:
Purpose:
Params:
Returns:
---------------------------------------------------------------------- */
void CGameOverScene::shutdown()
{
2001-07-11 22:05:02 +02:00
delete m_anotherGfx;
2001-07-11 18:15:44 +02:00
delete m_patrickGfx;
CActorPool::Reset();
2001-01-11 20:40:55 +01:00
m_font->dump(); delete m_font;
2001-05-31 23:17:33 +02:00
MemFree(m_image);
2001-01-11 20:40:55 +01:00
}
/*----------------------------------------------------------------------
Function:
Purpose:
Params:
Returns:
---------------------------------------------------------------------- */
void CGameOverScene::render()
{
2001-05-31 23:17:33 +02:00
switch(m_state)
{
case STATE__CONTINUE:
renderContinue();
break;
case STATE__CONTINUE_TIMED_OUT:
renderContinue();
renderGameOver();
break;
2001-07-11 18:15:44 +02:00
case STATE__SPEECH_BEFORE_EXITING_TO_GAME:
renderContinue();
break;
2001-05-31 23:17:33 +02:00
case STATE__GAME_OVER:
renderGameOver();
break;
2001-06-04 23:54:14 +02:00
case STATE__EXITING_TO_GAME:
renderContinue();
case STATE__EXITING_TO_FRONT_END:
renderGameOver();
break;
2001-05-31 23:17:33 +02:00
}
2001-07-11 18:15:44 +02:00
DVECTOR ppos={255,210};
m_patrickGfx->Render(ppos,0,m_animFrame);
CActorPool::CleanUpCache();
2001-01-11 20:40:55 +01:00
}
/*----------------------------------------------------------------------
Function:
Purpose:
Params:
Returns:
---------------------------------------------------------------------- */
void CGameOverScene::think(int _frames)
{
2001-07-11 18:15:44 +02:00
int animLength;
m_animFrame+=_frames;
animLength=m_patrickGfx->getFrameCount(0);
while(m_animFrame>=animLength)m_animFrame-=animLength;
2001-05-31 23:17:33 +02:00
switch(m_state)
{
case STATE__CONTINUE:
thinkContinue(_frames);
break;
case STATE__CONTINUE_TIMED_OUT:
thinkContinue(_frames);
thinkGameOver(_frames);
break;
case STATE__GAME_OVER:
thinkGameOver(_frames);
break;
2001-07-11 18:15:44 +02:00
case STATE__SPEECH_BEFORE_EXITING_TO_GAME:
thinkContinue(_frames);
break;
2001-06-04 23:54:14 +02:00
case STATE__EXITING_TO_GAME:
thinkContinue(_frames);
break;
case STATE__EXITING_TO_FRONT_END:
break;
2001-05-31 23:17:33 +02:00
}
2001-01-11 20:40:55 +01:00
}
/*----------------------------------------------------------------------
Function:
Purpose:
Params:
Returns:
---------------------------------------------------------------------- */
int CGameOverScene::readyToShutdown()
{
return m_readyToExit&&!CFader::isFading();
}
2001-05-31 23:17:33 +02:00
/*----------------------------------------------------------------------
Function:
Purpose:
Params:
Returns:
---------------------------------------------------------------------- */
void CGameOverScene::initContinue()
{
m_continueFontSin=0;
m_continueFontOffset=100<<2;
2001-06-04 23:54:14 +02:00
m_continueTimer=10*COUNTDOWN_TIME_SECOND_LENGTH;
2001-05-31 23:17:33 +02:00
}
void CGameOverScene::thinkContinue(int _frames)
{
int move;
// Slide the text onscreen
if(m_state==STATE__CONTINUE)
{
if(!CFader::isFading())
{
2001-07-11 18:15:44 +02:00
if(!m_hasPlayedFirstSpeech)
{
CSoundMediator::playSpeech(SPEECH_085);
PAUL_DBGMSG("WHERE IS EVERYBODY?");
m_hasPlayedFirstSpeech=true;
}
2001-05-31 23:17:33 +02:00
if(m_continueFontOffset)
{
move=m_continueFontOffset/10;
if(move==0)
{
move=1;
}
m_continueFontOffset-=move;
if(m_continueFontOffset<0)
{
m_continueFontOffset=0;
}
}
else
{
// Countdown ( wait for text to stop first )
if(m_continueTimer)
{
2001-06-04 23:54:14 +02:00
int pad=PadGetDown(0);
if(pad&PAD_CROSS)
2001-05-31 23:17:33 +02:00
{
2001-06-04 23:54:14 +02:00
m_continueTimer-=m_continueTimer%COUNTDOWN_TIME_SECOND_LENGTH;
}
else if(pad&PAD_START)
{
2001-07-11 18:15:44 +02:00
// m_readyToExit=true;
// CFader::setFadingOut();
// GameState::setNextScene(&MapScene);
// CGameSlotManager::getSlotData()->m_lives=CGameSlotManager::INITIAL_LIVES;
// CGameSlotManager::getSlotData()->m_continues--;
m_state=STATE__SPEECH_BEFORE_EXITING_TO_GAME;
2001-05-31 23:17:33 +02:00
}
else
{
m_continueTimer-=_frames;
}
if(m_continueTimer<=0)
{
m_continueTimer=0;
m_state=STATE__CONTINUE_TIMED_OUT;
}
}
}
}
}
2001-07-11 18:15:44 +02:00
else if(m_state==STATE__SPEECH_BEFORE_EXITING_TO_GAME||m_state==STATE__CONTINUE_TIMED_OUT||STATE__EXITING_TO_GAME)
2001-05-31 23:17:33 +02:00
{
2001-07-11 18:15:44 +02:00
if(m_state==STATE__SPEECH_BEFORE_EXITING_TO_GAME&&!m_hasPlayedSecondSpeech)
{
CSoundMediator::playSpeech(SPEECH_086);
PAUL_DBGMSG("LETS TRY AGAIN!");
m_hasPlayedSecondSpeech=true;
}
2001-05-31 23:17:33 +02:00
// Slide text back off the screen
2001-06-04 23:54:14 +02:00
m_continueFontOffset=(100<<2)-m_continueFontOffset;
2001-05-31 23:17:33 +02:00
move=m_continueFontOffset/10;
if(move==0)
{
move=1;
}
m_continueFontOffset-=move;
2001-06-04 23:54:14 +02:00
if(m_continueFontOffset<0)
2001-05-31 23:17:33 +02:00
{
2001-07-14 00:21:21 +02:00
if(m_state==STATE__SPEECH_BEFORE_EXITING_TO_GAME&&!CSoundMediator::isSpeechPlaying())
2001-07-11 18:15:44 +02:00
{
m_readyToExit=true;
CFader::setFadingOut();
GameState::setNextScene(&MapScene);
CGameSlotManager::getSlotData()->m_lives=CGameSlotManager::INITIAL_LIVES;
CGameSlotManager::getSlotData()->m_continues--;
m_state=STATE__EXITING_TO_GAME;
}
2001-06-04 23:54:14 +02:00
if(m_state==STATE__CONTINUE_TIMED_OUT)
{
m_state=STATE__GAME_OVER;
}
2001-05-31 23:17:33 +02:00
}
2001-06-04 23:54:14 +02:00
m_continueFontOffset=(100<<2)-m_continueFontOffset;
2001-05-31 23:17:33 +02:00
}
// Change the text size
m_continueFontSin=(m_continueFontSin+(_frames*CONTINUE_STROBE_SPEED))&4095;
}
void CGameOverScene::renderContinue()
{
2001-07-10 20:15:12 +02:00
int yOfs;
char buf[100];
2001-05-31 23:17:33 +02:00
2001-07-10 20:15:12 +02:00
m_font->setColour(242/2,245/2,15/2);
yOfs=m_continueFontOffset>>2;
2001-05-31 23:17:33 +02:00
2001-07-10 20:15:12 +02:00
sprintf(buf,TranslationDatabase::getString(STR__BACKEND__CONTINUE));
m_font->setScale(((msin(m_continueFontSin)*CONTINUE_FONT_SCALE)>>12)+CONTINUE_FONT_BASE_SIZE);
m_font->print(256,50-m_font->getStringHeight(buf)-yOfs,buf);
2001-05-31 23:17:33 +02:00
2001-07-10 20:15:12 +02:00
sprintf(buf,"%d",m_continueTimer/COUNTDOWN_TIME_SECOND_LENGTH);
m_font->setScale(CONTINUE_FONT_SCALE+CONTINUE_FONT_BASE_SIZE);
m_font->print(256,80-m_font->getStringHeight(buf)-yOfs,buf);
2001-05-31 23:17:33 +02:00
2001-06-04 23:54:14 +02:00
if(!CFader::isFading())
{
2001-05-31 23:17:33 +02:00
if(m_continueFontSin>512&m_state==STATE__CONTINUE)
{
sprintf(buf,TranslationDatabase::getString(STR__BACKEND__PRESS_START));
m_font->setColour(255,0,0);
m_font->print(256,200-m_font->getStringHeight(buf),buf);
}
}
2001-07-10 20:15:12 +02:00
sprintf(buf,"%s%d",TranslationDatabase::getString(STR__BACKEND__CONTINUES_REMAINING),CGameSlotManager::getSlotData()->m_continues);
m_font->setScale(256);
m_font->setColour(100,100,100);
m_font->print(490-(m_font->getStringWidth(buf)/2),210,buf);
2001-05-31 23:17:33 +02:00
}
/*----------------------------------------------------------------------
Function:
Purpose:
Params:
Returns:
---------------------------------------------------------------------- */
void CGameOverScene::initGameOver()
{
2001-06-04 23:54:14 +02:00
m_gameOverTimer=0;
m_finishedGrowingText=false;
2001-05-31 23:17:33 +02:00
}
void CGameOverScene::thinkGameOver(int _frames)
{
2001-07-10 20:15:12 +02:00
if(!CFader::isFading())
2001-06-04 23:54:14 +02:00
{
2001-07-24 21:19:38 +02:00
m_gameOverTimer+=_frames;
if(m_finishedGrowingText&&!m_readyToExit)
2001-07-10 20:15:12 +02:00
{
2001-07-24 21:19:38 +02:00
if(PadGetDown(0)&(PAD_START|PAD_CROSS)||m_gameOverTimer>GAMEOVER_DISPLAY_TIME)
2001-07-10 20:15:12 +02:00
{
m_readyToExit=true;
CFader::setFadingOut();
GameState::setNextScene(&FrontEndScene);
m_state=STATE__EXITING_TO_FRONT_END;
}
2001-06-04 23:54:14 +02:00
}
}
2001-05-31 23:17:33 +02:00
}
void CGameOverScene::renderGameOver()
{
char buf[100],*bufPtr;
char letter[]=" \0";
int i,len,step,x;
2001-06-04 23:54:14 +02:00
m_font->setColour(80/2,143/2,248/2);
2001-05-31 23:17:33 +02:00
2001-06-04 23:54:14 +02:00
sprintf(buf,TranslationDatabase::getString(STR__BACKEND__GAME_OVER));
2001-05-31 23:17:33 +02:00
bufPtr=buf;
len=strlen(buf);
step=(400<<2)/len;
2001-06-04 23:54:14 +02:00
x=(256<<2)-(((len-1)*step)/2);
2001-05-31 23:17:33 +02:00
for(i=0;i<strlen(buf);i++)
{
2001-06-04 23:54:14 +02:00
int sin,scale;
sin=(m_gameOverTimer*GAMEOVER_FONT_GROWSPEED)-(i*GAMEOVER_FONT_GROWSPACING);
if(sin>0)
{
if(sin>GAMEOVER_FONT_MAXSIN)
{
sin=GAMEOVER_FONT_MAXSIN;
if(i==strlen(buf)-1)
{
m_finishedGrowingText=true;
}
}
scale=(msin(sin)*GAMEOVER_FONT_SCALE)>>12;
if(scale>50)
{
m_font->setScale(scale);
letter[0]=*bufPtr;
m_font->print(x>>2,100,letter);
}
}
bufPtr++;
x+=step;
2001-05-31 23:17:33 +02:00
}
}
2001-01-11 20:40:55 +01:00
/*===========================================================================
end */