2001-04-24 18:15:04 +02:00
|
|
|
/*=========================================================================
|
|
|
|
|
|
|
|
map.cpp
|
|
|
|
|
|
|
|
Author: PKG
|
|
|
|
Created:
|
|
|
|
Project: Spongebob
|
|
|
|
Purpose:
|
|
|
|
|
|
|
|
Copyright (c) 2001 Climax Development Ltd
|
|
|
|
|
|
|
|
===========================================================================*/
|
|
|
|
|
|
|
|
|
|
|
|
/*----------------------------------------------------------------------
|
|
|
|
Includes
|
|
|
|
-------- */
|
|
|
|
|
2001-04-24 21:37:12 +02:00
|
|
|
#include "map\map.h"
|
2001-04-24 18:15:04 +02:00
|
|
|
|
|
|
|
#ifndef __GFX_FONT_H__
|
|
|
|
#include "gfx\font.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef __PAD_PADS_H__
|
|
|
|
#include "pad\pads.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef __PRIM_HEADER__
|
|
|
|
#include "gfx\prim.h"
|
|
|
|
#endif
|
|
|
|
|
2001-04-25 20:15:19 +02:00
|
|
|
#ifndef __GAME_GAME_H__
|
|
|
|
#include "game\game.h"
|
2001-04-24 18:15:04 +02:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef __GFX_FADER_H__
|
|
|
|
#include "gfx\fader.h"
|
|
|
|
#endif
|
|
|
|
|
2001-04-24 21:37:12 +02:00
|
|
|
#ifndef __VID_HEADER_
|
|
|
|
#include "system\vid.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef _FILEIO_HEADER_
|
|
|
|
#include "fileio\fileio.h"
|
|
|
|
#endif
|
|
|
|
|
2001-04-25 01:14:50 +02:00
|
|
|
#ifndef __MATHTABLE_HEADER__
|
|
|
|
#include "utils\mathtab.h"
|
|
|
|
#endif
|
|
|
|
|
2001-04-24 18:15:04 +02:00
|
|
|
|
|
|
|
/* Std Lib
|
|
|
|
------- */
|
|
|
|
|
|
|
|
/* Data
|
|
|
|
---- */
|
|
|
|
|
|
|
|
#ifndef __STRING_ENUMS__
|
|
|
|
#include <trans.h>
|
|
|
|
#endif
|
|
|
|
|
2001-04-25 01:14:50 +02:00
|
|
|
#ifndef __SPR_SPRITES_H__
|
|
|
|
#include <sprites.h>
|
|
|
|
#endif
|
|
|
|
|
2001-04-24 18:15:04 +02:00
|
|
|
|
|
|
|
/*----------------------------------------------------------------------
|
|
|
|
Tyepdefs && Defines
|
|
|
|
------------------- */
|
|
|
|
|
|
|
|
/*----------------------------------------------------------------------
|
|
|
|
Structure defintions
|
|
|
|
-------------------- */
|
|
|
|
|
|
|
|
/*----------------------------------------------------------------------
|
|
|
|
Function Prototypes
|
|
|
|
------------------- */
|
|
|
|
|
|
|
|
/*----------------------------------------------------------------------
|
|
|
|
Vars
|
|
|
|
---- */
|
|
|
|
|
|
|
|
CMapScene MapScene;
|
|
|
|
|
|
|
|
|
2001-04-25 20:15:19 +02:00
|
|
|
CMapScene::sMapLevelData CMapScene::s_mapLevelData[5]=
|
|
|
|
{
|
|
|
|
// Chapter 1
|
|
|
|
{
|
|
|
|
{ MAP_C1_L1_GFX, MAP_C1_L2_GFX, MAP_C1_L3_GFX, MAP_C1_L4_GFX, MAP_C1_BOSS_GFX, MAP_C1_FAIR_GFX },
|
|
|
|
{ 0, 1, 2, 3, -1, 20 },
|
|
|
|
{ FRM__C1_L1_JELLY, FRM__C1_L2_SEAWEED, FRM__C1_L3_SEANUTBUTTER, FRM__C1_L4_BREADSLICE },
|
|
|
|
},
|
|
|
|
// Chapter 2
|
|
|
|
{
|
|
|
|
{ MAP_C2_L1_GFX, MAP_C2_L2_GFX, MAP_C2_L3_GFX, MAP_C2_L4_GFX, MAP_C2_BOSS_GFX, MAP_C2_FAIR_GFX },
|
|
|
|
{ 4, 5, 6, 7, -1, 21 },
|
|
|
|
{ FRM__C2_L1_FALSETEETH, FRM__C2_L2_KELPKREAM, FRM__C2_L3_MUDPACK, FRM__C2_L4_SPONGE },
|
|
|
|
},
|
|
|
|
// Chapter 3
|
|
|
|
{
|
|
|
|
{ MAP_C3_L1_GFX, MAP_C3_L2_GFX, MAP_C3_L3_GFX, MAP_C3_L4_GFX, MAP_C3_BOSS_GFX, MAP_C3_FAIR_GFX },
|
|
|
|
{ 8, 9, 10, 11, -1, 22 },
|
|
|
|
{ FRM__C3_L1_SLIPPERS, FRM__C3_L2_CLAMBRA, FRM__C3_L3_STARFISHMASK, FRM__C3_L4_SUPERPANTZ },
|
|
|
|
},
|
|
|
|
// Chapter 4
|
|
|
|
{
|
|
|
|
{ MAP_C4_L1_GFX, MAP_C4_L2_GFX, MAP_C4_L3_GFX, MAP_C4_L4_GFX, MAP_C4_BOSS_GFX, MAP_C4_FAIR_GFX },
|
|
|
|
{ 12, 13, 14, 15, -1, 23 },
|
|
|
|
{ FRM__C4_COIN, FRM__C4_COIN, FRM__C4_COIN, FRM__C4_KELPBAR },
|
|
|
|
},
|
|
|
|
// Chapter 5
|
|
|
|
{
|
|
|
|
{ MAP_C5_L1_GFX, MAP_C5_L2_GFX, MAP_C5_L3_GFX, MAP_C5_L4_GFX, MAP_C5_BOSS_GFX, MAP_C5_FAIR_GFX },
|
|
|
|
{ 16, 17, 18, 19, -1, 24 },
|
|
|
|
{ FRM__C5_L1_HAMMER, FRM__C5_L2_ARIEL, FRM__C5_L3_OILCAN, FRM__C5_L4_WRENCH },
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
extern int s_globalLevelSelectThing;
|
|
|
|
|
|
|
|
|
2001-04-24 18:15:04 +02:00
|
|
|
/*----------------------------------------------------------------------
|
|
|
|
Function:
|
|
|
|
Purpose:
|
|
|
|
Params:
|
|
|
|
Returns:
|
|
|
|
---------------------------------------------------------------------- */
|
|
|
|
void CMapScene::init()
|
|
|
|
{
|
2001-04-24 21:37:12 +02:00
|
|
|
m_font=new ("map screen font") FontBank();
|
2001-04-24 18:15:04 +02:00
|
|
|
m_font->initialise(&standardFont);
|
|
|
|
m_font->setJustification(FontBank::JUST_CENTRE);
|
2001-04-25 01:14:50 +02:00
|
|
|
m_font->setOt(10);
|
|
|
|
m_font->setColour(0,0,0);
|
|
|
|
m_font->setJustification(FontBank::JUST_LEFT);
|
|
|
|
|
|
|
|
m_spriteBank=new ("map screen sprite") SpriteBank();
|
|
|
|
m_spriteBank->load(SPRITES_SPRITES_SPR);
|
2001-04-24 18:15:04 +02:00
|
|
|
|
2001-04-24 21:37:12 +02:00
|
|
|
|
2001-04-25 20:15:19 +02:00
|
|
|
m_currentChapterSelection=0;
|
|
|
|
m_currentLevelSelection=0;
|
2001-04-24 21:37:12 +02:00
|
|
|
m_screenImage=MemAlloc(512*256*2,"MapScreen");
|
2001-04-25 20:15:19 +02:00
|
|
|
generateMapScreenImage();
|
2001-04-24 21:37:12 +02:00
|
|
|
SetScreenImage((u8*)m_screenImage);
|
2001-04-25 01:14:50 +02:00
|
|
|
|
|
|
|
|
|
|
|
m_readyToExit=false;
|
|
|
|
// CFader::setFadingIn(CFader::BLACK_FADE);
|
2001-04-24 18:15:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*----------------------------------------------------------------------
|
|
|
|
Function:
|
|
|
|
Purpose:
|
|
|
|
Params:
|
|
|
|
Returns:
|
|
|
|
---------------------------------------------------------------------- */
|
|
|
|
void CMapScene::shutdown()
|
|
|
|
{
|
2001-04-24 21:37:12 +02:00
|
|
|
ClearScreenImage();
|
|
|
|
MemFree(m_screenImage);
|
2001-04-25 01:14:50 +02:00
|
|
|
m_spriteBank->dump(); delete m_spriteBank;
|
2001-04-24 18:15:04 +02:00
|
|
|
m_font->dump(); delete m_font;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*----------------------------------------------------------------------
|
|
|
|
Function:
|
|
|
|
Purpose:
|
|
|
|
Params:
|
|
|
|
Returns:
|
|
|
|
---------------------------------------------------------------------- */
|
|
|
|
void CMapScene::render()
|
|
|
|
{
|
2001-04-25 01:14:50 +02:00
|
|
|
int i,x,y,xpos,ypos;
|
|
|
|
int compilerGetsComfused;
|
|
|
|
char spatCount[10];
|
|
|
|
sFrameHdr *fh;
|
|
|
|
POLY_FT4 *ft4;
|
|
|
|
|
|
|
|
// Render spatula counts and quest items
|
|
|
|
i=0;
|
|
|
|
ypos=MAP_PARCHMENT_START_Y+MAP_LEVEL_TOP_BORDER;
|
|
|
|
for(y=0;y<2;y++)
|
|
|
|
{
|
|
|
|
xpos=256-((MAP_LEVEL_WIDTH*3)/2)-MAP_LEVEL_X_SPACING;
|
|
|
|
compilerGetsComfused=y==0?3:1; // 3 on top row, 1 on bottom - put this in the for loop and the complier breaks :o
|
|
|
|
for(x=0;x<compilerGetsComfused;x++)
|
|
|
|
{
|
|
|
|
sprintf(spatCount,"%d/%d",getSpatulaCollectedCount(m_currentChapterSelection,i),getSpatulaAvailableCount(m_currentChapterSelection,i));
|
|
|
|
m_font->print(xpos,ypos,spatCount);
|
2001-04-25 20:15:19 +02:00
|
|
|
fh=m_spriteBank->getFrameHeader(s_mapLevelData[m_currentChapterSelection].m_questItemFrames[i]);
|
2001-04-25 01:14:50 +02:00
|
|
|
ft4=m_spriteBank->printFT4Scaled(fh,xpos+MAP_LEVEL_WIDTH-fh->W,ypos+MAP_LEVEL_HEIGHT-fh->H,0,0,10,128);
|
|
|
|
if(!hasQuestItemBeenCollected(m_currentChapterSelection,i))
|
|
|
|
{
|
|
|
|
setRGB0(ft4,10,10,10);
|
|
|
|
}
|
|
|
|
i++;
|
|
|
|
xpos+=MAP_LEVEL_WIDTH+MAP_LEVEL_X_SPACING;
|
|
|
|
}
|
|
|
|
ypos+=MAP_LEVEL_HEIGHT+MAP_LEVEL_Y_SPACING;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Selection cursor
|
|
|
|
fh=m_spriteBank->getFrameHeader(FRM__MAPPOINTER);
|
|
|
|
m_spriteBank->printFT4(fh,m_pointerPos.vx-(fh->W/2),m_pointerPos.vy-(fh->H/2),0,0,9);
|
2001-04-25 20:15:19 +02:00
|
|
|
|
|
|
|
char buf[100];
|
|
|
|
sprintf(buf,"Chapter %d, Level %d",m_currentChapterSelection+1,m_currentLevelSelection+1);
|
|
|
|
m_font->setColour(0,255,0);
|
|
|
|
m_font->print(24,24,buf);
|
|
|
|
m_font->setColour(0,0,0);
|
|
|
|
m_font->print(25,25,buf);
|
2001-04-24 18:15:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*----------------------------------------------------------------------
|
|
|
|
Function:
|
|
|
|
Purpose:
|
|
|
|
Params:
|
|
|
|
Returns:
|
|
|
|
---------------------------------------------------------------------- */
|
|
|
|
void CMapScene::think(int _frames)
|
|
|
|
{
|
|
|
|
if(!CFader::isFading()&&!m_readyToExit)
|
|
|
|
{
|
2001-04-25 20:15:19 +02:00
|
|
|
// Change chapter
|
|
|
|
if(PadGetDown(0)&PAD_UP)
|
|
|
|
{
|
|
|
|
if(++m_currentChapterSelection>4)m_currentChapterSelection=0;
|
|
|
|
generateMapScreenImage();
|
|
|
|
}
|
|
|
|
else if(PadGetDown(0)&PAD_DOWN)
|
|
|
|
{
|
|
|
|
if(--m_currentChapterSelection<0)m_currentChapterSelection=4;
|
|
|
|
generateMapScreenImage();
|
|
|
|
}
|
|
|
|
|
2001-04-25 01:14:50 +02:00
|
|
|
// Move cursor
|
|
|
|
if(PadGetDown(0)&PAD_LEFT)
|
|
|
|
{
|
|
|
|
do
|
|
|
|
{
|
|
|
|
if(--m_currentLevelSelection<0)m_currentLevelSelection=5;
|
|
|
|
}
|
|
|
|
while(!isLevelOpen(m_currentChapterSelection,m_currentLevelSelection));
|
|
|
|
}
|
|
|
|
else if(PadGetDown(0)&PAD_RIGHT)
|
|
|
|
{
|
|
|
|
do
|
|
|
|
{
|
|
|
|
if(++m_currentLevelSelection>5)m_currentLevelSelection=0;
|
|
|
|
}
|
|
|
|
while(!isLevelOpen(m_currentChapterSelection,m_currentLevelSelection));
|
|
|
|
}
|
|
|
|
|
|
|
|
// Calc where the pointer should be
|
|
|
|
m_pointerSin=(m_pointerSin+(_frames*70))&4095;
|
2001-04-25 20:15:19 +02:00
|
|
|
m_pointerTarget=getPointerTargetPosition();
|
2001-04-25 01:14:50 +02:00
|
|
|
|
|
|
|
// Move the pointer
|
|
|
|
for(int i=0;i<_frames;i++)
|
|
|
|
{
|
|
|
|
int delta;
|
|
|
|
|
|
|
|
delta=m_pointerTarget.vx-m_pointerPos.vx;
|
|
|
|
if(delta<0)
|
|
|
|
{
|
|
|
|
delta/=2;
|
|
|
|
if(!delta)delta=-1;
|
|
|
|
}
|
|
|
|
else if(delta>0)
|
|
|
|
{
|
|
|
|
delta/=2;
|
|
|
|
if(!delta)delta=+1;
|
|
|
|
}
|
|
|
|
m_pointerPos.vx+=delta;
|
|
|
|
|
|
|
|
delta=m_pointerTarget.vy-m_pointerPos.vy;
|
|
|
|
if(delta<0)
|
|
|
|
{
|
|
|
|
delta/=2;
|
|
|
|
if(!delta)delta=-1;
|
|
|
|
}
|
|
|
|
else if(delta>0)
|
|
|
|
{
|
|
|
|
delta/=2;
|
|
|
|
if(!delta)delta=+1;
|
|
|
|
}
|
|
|
|
m_pointerPos.vy+=delta;
|
|
|
|
}
|
|
|
|
|
2001-04-24 18:15:04 +02:00
|
|
|
if(PadGetDown(0)&(PAD_CROSS|PAD_START))
|
|
|
|
{
|
2001-04-25 20:15:19 +02:00
|
|
|
s_globalLevelSelectThing=s_mapLevelData[m_currentChapterSelection].m_globalLevelNumbers[m_currentLevelSelection];
|
2001-04-24 18:15:04 +02:00
|
|
|
m_readyToExit=true;
|
2001-04-24 21:37:12 +02:00
|
|
|
// CFader::setFadingOut(CFader::BLACK_FADE);
|
2001-04-25 20:15:19 +02:00
|
|
|
GameState::setNextScene(&GameScene);
|
2001-04-24 18:15:04 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*----------------------------------------------------------------------
|
|
|
|
Function:
|
|
|
|
Purpose:
|
|
|
|
Params:
|
|
|
|
Returns:
|
|
|
|
---------------------------------------------------------------------- */
|
|
|
|
int CMapScene::readyToShutdown()
|
|
|
|
{
|
|
|
|
return m_readyToExit&&!CFader::isFading();
|
|
|
|
}
|
|
|
|
|
2001-04-25 20:15:19 +02:00
|
|
|
|
|
|
|
/*----------------------------------------------------------------------
|
|
|
|
Function:
|
|
|
|
Purpose:
|
|
|
|
Params:
|
|
|
|
Returns:
|
|
|
|
---------------------------------------------------------------------- */
|
|
|
|
void CMapScene::generateMapScreenImage()
|
|
|
|
{
|
|
|
|
int i,x,y,xpos,ypos;
|
|
|
|
|
|
|
|
|
|
|
|
m_currentLevelSelection=0;
|
|
|
|
memset(m_screenImage,0,512*256*2);
|
|
|
|
copyImageToScreen(MAP_MAP_BACKGROUND_GFX,MAP_PARCHMENT_START_X,MAP_PARCHMENT_START_Y,MAP_PARCHMENT_WIDTH,MAP_PARCHMENT_HEIGHT);
|
|
|
|
i=0;
|
|
|
|
ypos=MAP_PARCHMENT_START_Y+MAP_LEVEL_TOP_BORDER;
|
|
|
|
for(y=0;y<2;y++)
|
|
|
|
{
|
|
|
|
xpos=256-((MAP_LEVEL_WIDTH*3)/2)-MAP_LEVEL_X_SPACING;
|
|
|
|
for(x=0;x<3;x++)
|
|
|
|
{
|
|
|
|
if(isLevelOpen(m_currentChapterSelection,i))
|
|
|
|
{
|
|
|
|
copyImageToScreen(s_mapLevelData[m_currentChapterSelection].m_mapFiles[i],xpos,ypos,MAP_LEVEL_WIDTH,MAP_LEVEL_HEIGHT);
|
|
|
|
}
|
|
|
|
i++;
|
|
|
|
xpos+=MAP_LEVEL_WIDTH+MAP_LEVEL_X_SPACING;
|
|
|
|
}
|
|
|
|
ypos+=MAP_LEVEL_HEIGHT+MAP_LEVEL_Y_SPACING;
|
|
|
|
}
|
|
|
|
|
|
|
|
m_pointerPos=getPointerTargetPosition();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-04-24 21:37:12 +02:00
|
|
|
/*----------------------------------------------------------------------
|
|
|
|
Function:
|
|
|
|
Purpose:
|
|
|
|
Params:
|
|
|
|
Returns:
|
|
|
|
---------------------------------------------------------------------- */
|
|
|
|
void CMapScene::copyImageToScreen(int _file,int _x,int _y,int _w,int _h)
|
|
|
|
{
|
|
|
|
u8 *image;
|
|
|
|
u16 *src,*dst;
|
|
|
|
int x,y;
|
|
|
|
|
|
|
|
image=CFileIO::loadFile((FileEquate)_file);ASSERT(image);
|
|
|
|
src=(u16*)image;
|
|
|
|
dst=(u16*)m_screenImage+(_x+(_y*512));
|
|
|
|
for(y=0;y<_h;y++)
|
|
|
|
{
|
|
|
|
for(x=0;x<_w;x++)
|
|
|
|
{
|
|
|
|
*dst++=*src++;
|
|
|
|
}
|
|
|
|
dst+=512-_w;
|
|
|
|
}
|
|
|
|
MemFree(image);
|
|
|
|
}
|
|
|
|
|
2001-04-25 20:15:19 +02:00
|
|
|
/*----------------------------------------------------------------------
|
|
|
|
Function:
|
|
|
|
Purpose:
|
|
|
|
Params:
|
|
|
|
Returns:
|
|
|
|
---------------------------------------------------------------------- */
|
|
|
|
DVECTOR CMapScene::getPointerTargetPosition()
|
|
|
|
{
|
|
|
|
DVECTOR pos;
|
|
|
|
pos.vx=256-((MAP_LEVEL_WIDTH*3)/2)-MAP_LEVEL_X_SPACING+
|
|
|
|
((m_currentLevelSelection%3)*(MAP_LEVEL_WIDTH+MAP_LEVEL_X_SPACING))+
|
|
|
|
(MAP_LEVEL_WIDTH/2);
|
|
|
|
pos.vy=MAP_PARCHMENT_START_Y+MAP_LEVEL_TOP_BORDER+
|
|
|
|
((m_currentLevelSelection/3)*(MAP_LEVEL_HEIGHT+MAP_LEVEL_Y_SPACING))+
|
|
|
|
(MAP_LEVEL_HEIGHT)+
|
|
|
|
(msin(m_pointerSin)*4>>12);
|
|
|
|
return pos;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-04-25 01:14:50 +02:00
|
|
|
/*----------------------------------------------------------------------
|
|
|
|
Function:
|
|
|
|
Purpose:
|
|
|
|
Params:
|
|
|
|
Returns:
|
|
|
|
---------------------------------------------------------------------- */
|
|
|
|
int CMapScene::isLevelOpen(int _chapter,int _level)
|
|
|
|
{
|
2001-04-25 20:15:19 +02:00
|
|
|
return _level!=4; // no boss levels atm..
|
2001-04-25 01:14:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
int CMapScene::getSpatulaCollectedCount(int _chapter,int _level)
|
|
|
|
{
|
2001-04-25 20:15:19 +02:00
|
|
|
return 0;
|
2001-04-25 01:14:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
int CMapScene::getSpatulaAvailableCount(int _chapter,int _level)
|
|
|
|
{
|
|
|
|
return 30;
|
|
|
|
}
|
|
|
|
|
|
|
|
int CMapScene::hasQuestItemBeenCollected(int _chapter,int _level)
|
|
|
|
{
|
2001-04-25 20:15:19 +02:00
|
|
|
return true;
|
2001-04-25 01:14:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-04-24 18:15:04 +02:00
|
|
|
/*===========================================================================
|
|
|
|
end */
|