This commit is contained in:
parent
6745c970e9
commit
b462cc1e7a
@ -38,6 +38,10 @@
|
||||
#include "sound\sound.h"
|
||||
#endif
|
||||
|
||||
#ifndef __ACTOR_HEADER__
|
||||
#include "gfx\actor.h"
|
||||
#endif
|
||||
|
||||
|
||||
/* Std Lib
|
||||
------- */
|
||||
@ -45,14 +49,102 @@
|
||||
/* Data
|
||||
---- */
|
||||
|
||||
#ifndef __ANIM_SPONGEBOB_HEADER__
|
||||
#include "actor_spongebob_anim.h"
|
||||
#endif
|
||||
|
||||
#ifndef __ANIM_MERMAIDMAN_HEADER__
|
||||
#include "actor_mermaidman_anim.h"
|
||||
#endif
|
||||
|
||||
#ifndef __ANIM_BARNACLEBOY_HEADER__
|
||||
#include "actor_barnacleboy_anim.h"
|
||||
#endif
|
||||
|
||||
#ifndef __ANIM_GARY_HEADER__
|
||||
#include "actor_gary_anim.h"
|
||||
#endif
|
||||
|
||||
|
||||
/*----------------------------------------------------------------------
|
||||
Tyepdefs && Defines
|
||||
------------------- */
|
||||
|
||||
// Available actors
|
||||
enum
|
||||
{
|
||||
ACTOR_SPONGEBOB,
|
||||
ACTOR_MM,
|
||||
ACTOR_BB,
|
||||
ACTOR_GARY,
|
||||
|
||||
NUM_ACTORS
|
||||
};
|
||||
|
||||
// Actor animation types
|
||||
enum
|
||||
{
|
||||
ANIM_IDLE,
|
||||
ANIM_WALK,
|
||||
|
||||
NUM_ANIMS,
|
||||
};
|
||||
|
||||
// Available script commands
|
||||
typedef enum
|
||||
{
|
||||
SC_SNAP_CAMERA_TO, // x,y
|
||||
SC_MOVE_CAMERA_TO, // x,y,frames
|
||||
|
||||
SC_REGISTER_CONVERSATION, // scriptId
|
||||
|
||||
SC_WAIT_ON_TIMER, // frames (nonblocking)
|
||||
SC_WAIT_ON_ACTOR_STOP, // actor (nonblocking)
|
||||
SC_WAIT_ON_CAMERA_STOP, // (nonblocking)
|
||||
SC_WAIT_ON_CONVERSATION, // scriptId (nonblocking)
|
||||
|
||||
SC_SET_ACTOR_VISIBILITY, // actor,on/off
|
||||
SC_SET_ACTOR_POSITION, // actor,x,y
|
||||
SC_SET_ACTOR_FACING, // actor,facing
|
||||
SC_SET_ACTOR_ANIM_STATE, // actor,state
|
||||
SC_WALK_ACTOR_TO_POSITION, // actor,x,y,frames
|
||||
|
||||
SC_STOP, //
|
||||
} SCRIPT_COMMAND;
|
||||
|
||||
|
||||
/*----------------------------------------------------------------------
|
||||
Structure defintions
|
||||
-------------------- */
|
||||
|
||||
// Data for an actors graphics
|
||||
typedef struct
|
||||
{
|
||||
FileEquate m_file;
|
||||
int m_anims[NUM_ANIMS];
|
||||
|
||||
} ACTOR_GRAPHICS_DATA;
|
||||
|
||||
// Actor data
|
||||
typedef struct
|
||||
{
|
||||
CActorGfx *m_gfx;
|
||||
u8 m_active;
|
||||
|
||||
u8 m_animState,m_animFrame;
|
||||
|
||||
DVECTOR m_pos;
|
||||
|
||||
u16 m_startMoveFrame;
|
||||
DVECTOR m_startMovePos;
|
||||
u16 m_endMoveFrame;
|
||||
DVECTOR m_endMovePos;
|
||||
u8 m_moving;
|
||||
|
||||
u8 m_facing;
|
||||
} ACTOR_DATA;
|
||||
|
||||
|
||||
/*----------------------------------------------------------------------
|
||||
Function Prototypes
|
||||
------------------- */
|
||||
@ -64,12 +156,48 @@
|
||||
CFmaScene FmaScene;
|
||||
|
||||
|
||||
// A test script..
|
||||
int s_testScript[]=
|
||||
{
|
||||
SC_REGISTER_CONVERSATION, SCRIPTS_CH1L1_01_DAT,
|
||||
SC_SNAP_CAMERA_TO, 0,0,
|
||||
SC_SET_ACTOR_VISIBILITY, ACTOR_SPONGEBOB,true,
|
||||
SC_SET_ACTOR_POSITION, ACTOR_SPONGEBOB,100,100,
|
||||
|
||||
SC_MOVE_CAMERA_TO, 100,100,150+(60*2),
|
||||
SC_WALK_ACTOR_TO_POSITION, ACTOR_SPONGEBOB,200,100,10,
|
||||
SC_WAIT_ON_CAMERA_STOP,
|
||||
|
||||
SC_WAIT_ON_CONVERSATION, SCRIPTS_CH1L1_01_DAT,
|
||||
|
||||
SC_WAIT_ON_TIMER, 60,
|
||||
|
||||
SC_SET_ACTOR_ANIM_STATE, ACTOR_SPONGEBOB,ANIM_WALK,
|
||||
SC_SET_ACTOR_FACING, ACTOR_SPONGEBOB,1,
|
||||
SC_WALK_ACTOR_TO_POSITION, ACTOR_SPONGEBOB,250,200,5,
|
||||
SC_WAIT_ON_ACTOR_STOP, ACTOR_SPONGEBOB,
|
||||
|
||||
SC_WAIT_ON_TIMER, 60*5,
|
||||
|
||||
SC_STOP
|
||||
};
|
||||
|
||||
|
||||
// Actor graphics data
|
||||
const ACTOR_GRAPHICS_DATA s_actorGraphicsData[NUM_ACTORS]=
|
||||
{
|
||||
{ ACTORS_SPONGEBOB_SBK, { ANIM_SPONGEBOB_IDLEBREATH, ANIM_SPONGEBOB_RUN } }, // ACTOR_SPONGEBOB
|
||||
{ ACTORS_MERMAIDMAN_SBK, { ANIM_MERMAIDMAN_IDLEBREATHE,ANIM_MERMAIDMAN_IDLEBREATHE } }, // ACTOR_MM
|
||||
{ ACTORS_BARNACLEBOY_SBK, { ANIM_BARNACLEBOY_IDLE, ANIM_BARNACLEBOY_IDLE } }, // ACTOR_BB
|
||||
{ ACTORS_GARY_SBK, { ANIM_GARY_IDLE, ANIM_GARY_SLITHER } }, // ACTOR_GARY
|
||||
};
|
||||
|
||||
|
||||
ACTOR_DATA m_actorData[NUM_ACTORS];
|
||||
|
||||
#include "pad\pads.h"
|
||||
|
||||
#include "pad\pads.h"
|
||||
#include "gfx\font.h"
|
||||
|
||||
|
||||
/*----------------------------------------------------------------------
|
||||
@ -80,17 +208,42 @@ CFmaScene FmaScene;
|
||||
---------------------------------------------------------------------- */
|
||||
void CFmaScene::init()
|
||||
{
|
||||
int i;
|
||||
ACTOR_DATA *actor;
|
||||
|
||||
|
||||
CThingManager::init();
|
||||
CConversation::init();
|
||||
|
||||
CConversation::registerConversationScript(SCRIPTS_CH1L1_01_DAT);
|
||||
|
||||
m_level=new ("FMALevel") CLevel();
|
||||
m_level->init(25);
|
||||
|
||||
m_cameraPos.vx=-30;
|
||||
m_cameraPos.vx=30;
|
||||
m_cameraPos.vy=280;
|
||||
m_cameraMoving=false;
|
||||
m_readyToShutdown=false;
|
||||
|
||||
CActorPool::Reset();
|
||||
actor=m_actorData;
|
||||
for(i=0;i<NUM_ACTORS;i++)
|
||||
{
|
||||
actor->m_gfx=CActorPool::GetActor(s_actorGraphicsData[i].m_file);
|
||||
actor->m_active=false;
|
||||
actor->m_animState=ANIM_IDLE;
|
||||
actor->m_animFrame=0;
|
||||
actor->m_pos.vx=0;
|
||||
actor->m_pos.vy=0;
|
||||
actor->m_moving=false;
|
||||
actor->m_facing=0;
|
||||
actor++;
|
||||
}
|
||||
CActorPool::SetUpCache();
|
||||
CActorPool::CleanUpCache();
|
||||
|
||||
m_frameCount=0;
|
||||
|
||||
m_scriptRunning=true;
|
||||
m_pc=s_testScript;
|
||||
}
|
||||
|
||||
|
||||
@ -102,6 +255,12 @@ void CFmaScene::init()
|
||||
---------------------------------------------------------------------- */
|
||||
void CFmaScene::shutdown()
|
||||
{
|
||||
for(int i=0;i<NUM_ACTORS;i++)
|
||||
{
|
||||
delete m_actorData[i].m_gfx;
|
||||
}
|
||||
CActorPool::Reset();
|
||||
|
||||
m_level->shutdown(); delete m_level;
|
||||
CSoundMediator::dumpSong();
|
||||
|
||||
@ -118,9 +277,38 @@ void CFmaScene::shutdown()
|
||||
---------------------------------------------------------------------- */
|
||||
void CFmaScene::render()
|
||||
{
|
||||
int i;
|
||||
ACTOR_DATA *actor;
|
||||
|
||||
CThingManager::renderAllThings();
|
||||
CConversation::render();
|
||||
m_level->render();
|
||||
|
||||
actor=m_actorData;
|
||||
for(i=0;i<NUM_ACTORS;i++)
|
||||
{
|
||||
if(actor->m_active)
|
||||
{
|
||||
DVECTOR pos;
|
||||
pos.vx=actor->m_pos.vx-m_cameraPos.vx;
|
||||
pos.vy=actor->m_pos.vy-m_cameraPos.vy;
|
||||
actor->m_gfx->Render(pos,s_actorGraphicsData[i].m_anims[actor->m_animState],actor->m_animFrame,actor->m_facing);
|
||||
}
|
||||
actor++;
|
||||
}
|
||||
|
||||
CActorPool::CleanUpCache();
|
||||
|
||||
#if defined (__USER_paul__) || defined (__USER_daveo__)
|
||||
FontBank *font;
|
||||
char buf[20];
|
||||
font=new ("Font") FontBank();
|
||||
font->initialise(&standardFont);
|
||||
sprintf(buf,"%d,%d",m_cameraPos.vx,m_cameraPos.vy);
|
||||
font->print(400,30,buf);
|
||||
font->dump();
|
||||
delete font;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
@ -132,7 +320,7 @@ void CFmaScene::render()
|
||||
---------------------------------------------------------------------- */
|
||||
void CFmaScene::think(int _frames)
|
||||
{
|
||||
#ifdef __USER_paul__
|
||||
#if defined (__USER_paul__) || defined (__USER_daveo__)
|
||||
if(PadGetHeld(0)&PAD_UP)
|
||||
{
|
||||
m_cameraPos.vy-=10*_frames;
|
||||
@ -150,11 +338,96 @@ void CFmaScene::think(int _frames)
|
||||
m_cameraPos.vx+=10*_frames;
|
||||
}
|
||||
#endif
|
||||
if(PadGetDown(0)&(PAD_CROSS|PAD_START))
|
||||
if(m_scriptRunning==false&&PadGetDown(0)&(PAD_CROSS|PAD_START))
|
||||
{
|
||||
startShutdown();
|
||||
}
|
||||
|
||||
for(int i=0;i<_frames;i++)
|
||||
{
|
||||
if(m_scriptRunning)
|
||||
{
|
||||
int i;
|
||||
ACTOR_DATA *actor;
|
||||
|
||||
actor=m_actorData;
|
||||
for(i=0;i<NUM_ACTORS;i++)
|
||||
{
|
||||
if(actor->m_active)
|
||||
{
|
||||
// Move actor?
|
||||
if(actor->m_moving)
|
||||
{
|
||||
int totalFrames,currentFrame;
|
||||
totalFrames=actor->m_endMoveFrame-actor->m_startMoveFrame;
|
||||
currentFrame=totalFrames-(actor->m_endMoveFrame-m_frameCount);
|
||||
if(currentFrame==0)
|
||||
{
|
||||
actor->m_pos=actor->m_startMovePos;
|
||||
}
|
||||
else if(currentFrame==totalFrames)
|
||||
{
|
||||
actor->m_pos=actor->m_endMovePos;
|
||||
actor->m_moving=false;
|
||||
}
|
||||
else
|
||||
{
|
||||
actor->m_pos.vx=actor->m_startMovePos.vx+(((actor->m_endMovePos.vx-actor->m_startMovePos.vx)*currentFrame)/totalFrames);
|
||||
actor->m_pos.vy=actor->m_startMovePos.vy+(((actor->m_endMovePos.vy-actor->m_startMovePos.vy)*currentFrame)/totalFrames);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Anim
|
||||
actor->m_animFrame++;
|
||||
if(actor->m_animFrame>=actor->m_gfx->getFrameCount(s_actorGraphicsData[i].m_anims[actor->m_animState]))
|
||||
{
|
||||
actor->m_animFrame=0;
|
||||
}
|
||||
|
||||
actor++;
|
||||
}
|
||||
|
||||
// Move Camera
|
||||
if(m_cameraMoving)
|
||||
{
|
||||
int totalFrames,currentFrame;
|
||||
totalFrames=m_endCameraFrame-m_startCameraFrame;
|
||||
currentFrame=totalFrames-(m_endCameraFrame-m_frameCount);
|
||||
if(currentFrame==0)
|
||||
{
|
||||
m_cameraPos=m_startCameraPos;
|
||||
}
|
||||
else if(currentFrame==totalFrames)
|
||||
{
|
||||
m_cameraPos=m_endCameraPos;
|
||||
m_cameraMoving=false;
|
||||
}
|
||||
else
|
||||
{
|
||||
m_cameraPos.vx=m_startCameraPos.vx+(((m_endCameraPos.vx-m_startCameraPos.vx)*currentFrame)/totalFrames);
|
||||
m_cameraPos.vy=m_startCameraPos.vy+(((m_endCameraPos.vy-m_startCameraPos.vy)*currentFrame)/totalFrames);
|
||||
}
|
||||
}
|
||||
|
||||
// Process script
|
||||
do
|
||||
{
|
||||
if(!m_stillProcessingCommand)
|
||||
{
|
||||
startNextScriptCommand();
|
||||
}
|
||||
if(m_stillProcessingCommand)
|
||||
{
|
||||
processCurrentScriptCommand();
|
||||
}
|
||||
}
|
||||
while(!m_doOtherProcessing);
|
||||
}
|
||||
|
||||
m_frameCount++;
|
||||
}
|
||||
|
||||
CThingManager::thinkAllThings(_frames);
|
||||
CConversation::think(_frames);
|
||||
m_level->setCameraCentre(m_cameraPos);
|
||||
@ -187,5 +460,198 @@ void CFmaScene::startShutdown()
|
||||
}
|
||||
|
||||
|
||||
/*----------------------------------------------------------------------
|
||||
Function:
|
||||
Purpose:
|
||||
Params:
|
||||
Returns:
|
||||
---------------------------------------------------------------------- */
|
||||
void CFmaScene::startNextScriptCommand()
|
||||
{
|
||||
m_stillProcessingCommand=false;
|
||||
m_doOtherProcessing=false;
|
||||
|
||||
switch(*m_pc)
|
||||
{
|
||||
case SC_SNAP_CAMERA_TO: // x,y
|
||||
m_pc++;
|
||||
m_cameraPos.vx=*m_pc++;
|
||||
m_cameraPos.vy=*m_pc++;
|
||||
break;
|
||||
|
||||
case SC_MOVE_CAMERA_TO: // x,y,frames
|
||||
m_pc++;
|
||||
m_cameraMoving=true;
|
||||
m_startCameraPos=m_cameraPos;
|
||||
m_startCameraFrame=m_frameCount;
|
||||
m_endCameraPos.vx=*m_pc++;
|
||||
m_endCameraPos.vy=*m_pc++;
|
||||
m_endCameraFrame=m_frameCount+*m_pc++;
|
||||
break;
|
||||
|
||||
case SC_REGISTER_CONVERSATION: // scriptId
|
||||
m_pc++;
|
||||
CConversation::registerConversationScript((FileEquate)*(m_pc++));
|
||||
break;
|
||||
|
||||
case SC_WAIT_ON_TIMER: // frames
|
||||
m_timer=*(m_pc+1);
|
||||
m_stillProcessingCommand=true;
|
||||
break;
|
||||
|
||||
case SC_WAIT_ON_ACTOR_STOP: // actor
|
||||
m_stillProcessingCommand=true;
|
||||
break;
|
||||
|
||||
case SC_WAIT_ON_CAMERA_STOP: //
|
||||
m_stillProcessingCommand=true;
|
||||
break;
|
||||
|
||||
case SC_WAIT_ON_CONVERSATION: // scriptId
|
||||
CConversation::trigger((FileEquate)*(m_pc+1));
|
||||
m_stillProcessingCommand=true;
|
||||
break;
|
||||
|
||||
case SC_SET_ACTOR_VISIBILITY: // actor,on/off
|
||||
{
|
||||
ACTOR_DATA *actor;
|
||||
m_pc++;
|
||||
actor=&m_actorData[*m_pc++];
|
||||
actor->m_active=*m_pc++;
|
||||
}
|
||||
break;
|
||||
|
||||
case SC_SET_ACTOR_POSITION: // actor,x,y
|
||||
{
|
||||
ACTOR_DATA *actor;
|
||||
m_pc++;
|
||||
actor=&m_actorData[*m_pc++];
|
||||
actor->m_pos.vx=*m_pc++;
|
||||
actor->m_pos.vy=*m_pc++;
|
||||
}
|
||||
break;
|
||||
|
||||
case SC_SET_ACTOR_FACING: // actor,facing
|
||||
{
|
||||
ACTOR_DATA *actor;
|
||||
m_pc++;
|
||||
actor=&m_actorData[*m_pc++];
|
||||
actor->m_facing=*m_pc++;
|
||||
}
|
||||
break;
|
||||
|
||||
case SC_SET_ACTOR_ANIM_STATE: // actor,state
|
||||
{
|
||||
ACTOR_DATA *actor;
|
||||
m_pc++;
|
||||
actor=&m_actorData[*m_pc++];
|
||||
actor->m_animState=*m_pc++;
|
||||
}
|
||||
break;
|
||||
|
||||
case SC_WALK_ACTOR_TO_POSITION: // actor,x,y,frames
|
||||
{
|
||||
ACTOR_DATA *actor;
|
||||
m_pc++;
|
||||
actor=&m_actorData[*m_pc++];
|
||||
actor->m_startMoveFrame=m_frameCount;
|
||||
actor->m_startMovePos=actor->m_pos;
|
||||
actor->m_endMovePos.vx=*m_pc++;
|
||||
actor->m_endMovePos.vy=*m_pc++;
|
||||
actor->m_endMoveFrame=m_frameCount+*m_pc++;
|
||||
actor->m_moving=true;
|
||||
}
|
||||
break;
|
||||
|
||||
case SC_STOP: //
|
||||
m_scriptRunning=false;
|
||||
m_doOtherProcessing=true;
|
||||
break;
|
||||
|
||||
default:
|
||||
ASSERT(!"Bad script command");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*----------------------------------------------------------------------
|
||||
Function:
|
||||
Purpose:
|
||||
Params:
|
||||
Returns:
|
||||
---------------------------------------------------------------------- */
|
||||
void CFmaScene::processCurrentScriptCommand()
|
||||
{
|
||||
switch(*m_pc)
|
||||
{
|
||||
case SC_SNAP_CAMERA_TO: // x,y
|
||||
case SC_MOVE_CAMERA_TO: // x,y,frames
|
||||
case SC_REGISTER_CONVERSATION: // scriptId
|
||||
case SC_SET_ACTOR_VISIBILITY: // actor,on/off
|
||||
case SC_SET_ACTOR_POSITION: // actor,x,y
|
||||
case SC_SET_ACTOR_FACING: // actor,facing
|
||||
case SC_SET_ACTOR_ANIM_STATE: // actor,state
|
||||
case SC_WALK_ACTOR_TO_POSITION: // actor,x,y,frames
|
||||
case SC_STOP: //
|
||||
ASSERT(!"Shouldn't be here..");
|
||||
break;
|
||||
|
||||
case SC_WAIT_ON_TIMER: // frames
|
||||
if(m_timer--==0)
|
||||
{
|
||||
m_pc+=2;
|
||||
m_stillProcessingCommand=false;
|
||||
}
|
||||
else
|
||||
{
|
||||
m_doOtherProcessing=true;
|
||||
}
|
||||
break;
|
||||
|
||||
case SC_WAIT_ON_ACTOR_STOP: // actor
|
||||
if(!m_actorData[*(m_pc+1)].m_moving)
|
||||
{
|
||||
m_pc+=2;
|
||||
m_stillProcessingCommand=false;
|
||||
}
|
||||
else
|
||||
{
|
||||
m_doOtherProcessing=true;
|
||||
}
|
||||
break;
|
||||
|
||||
case SC_WAIT_ON_CAMERA_STOP: //
|
||||
if(!m_cameraMoving)
|
||||
{
|
||||
m_pc++;
|
||||
m_stillProcessingCommand=false;
|
||||
}
|
||||
else
|
||||
{
|
||||
m_doOtherProcessing=true;
|
||||
}
|
||||
break;
|
||||
|
||||
|
||||
case SC_WAIT_ON_CONVERSATION: // scriptId
|
||||
if(!CConversation::isActive())
|
||||
{
|
||||
m_pc+=2;
|
||||
m_stillProcessingCommand=false;
|
||||
}
|
||||
else
|
||||
{
|
||||
m_doOtherProcessing=true;
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
ASSERT(!"Bad script command");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*===========================================================================
|
||||
end */
|
@ -51,14 +51,29 @@ public:
|
||||
private:
|
||||
void startShutdown();
|
||||
|
||||
void startNextScriptCommand();
|
||||
void processCurrentScriptCommand();
|
||||
|
||||
|
||||
|
||||
class CLevel *m_level;
|
||||
|
||||
DVECTOR m_cameraPos;
|
||||
|
||||
int m_cameraMoving;
|
||||
int m_startCameraFrame;
|
||||
DVECTOR m_startCameraPos;
|
||||
int m_endCameraFrame;
|
||||
DVECTOR m_endCameraPos;
|
||||
|
||||
int *m_pc;
|
||||
int m_scriptRunning;
|
||||
int m_stillProcessingCommand;
|
||||
int m_doOtherProcessing;
|
||||
int m_timer;
|
||||
int m_frameCount;
|
||||
|
||||
int m_readyToShutdown;
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user