SBSPSS/source/pickups/pquest.cpp

323 lines
7.1 KiB
C++
Raw Normal View History

2001-02-21 16:35:38 +01:00
/*=========================================================================
pquest.cpp
Author: PKG
Created:
Project: Spongebob
Purpose:
Copyright (c) 2001 Climax Development Ltd
===========================================================================*/
/*----------------------------------------------------------------------
Includes
-------- */
#ifndef __GFX_SPRBANK_H__
#include "gfx\sprbank.h" // Damnit.. include order! :( (pkg)
#endif
#include "pickups\pquest.h"
#ifndef __MATHTABLE_HEADER__
#include "utils\mathtab.h"
#endif
2001-02-21 18:13:37 +01:00
#ifndef __PRIM_HEADER__
#include "gfx\prim.h"
#endif
2001-04-19 22:46:43 +02:00
#ifndef __GFX_OTPOS_H__
#include "gfx\otpos.h"
#endif
2001-05-24 20:21:14 +02:00
#ifndef __GAME_GAME_H__
#include "game\game.h"
#endif
2001-06-12 23:45:33 +02:00
#ifndef __PLAYER_PLAYER_H__
#include "player\player.h"
#endif
2001-02-21 16:35:38 +01:00
/* Std Lib
------- */
/* Data
---- */
2001-04-20 16:53:35 +02:00
#ifndef __SPR_SPRITES_H__
#include <sprites.h>
2001-02-21 16:35:38 +01:00
#endif
/*----------------------------------------------------------------------
Tyepdefs && Defines
------------------- */
/*----------------------------------------------------------------------
Structure defintions
-------------------- */
2001-05-24 20:21:14 +02:00
typedef struct
{
u8 m_chapter,m_level;
u16 m_gfxFrame;
} sQuestItemMap;
2001-02-21 16:35:38 +01:00
/*----------------------------------------------------------------------
Function Prototypes
------------------- */
/*----------------------------------------------------------------------
Vars
---- */
2001-05-24 20:21:14 +02:00
static const sQuestItemMap s_questItemMap[]=
{
2001-05-29 21:48:47 +02:00
{ 1,1, FRM__C1_L1_QUEST_ITEM },
{ 1,2, FRM__C1_L2_QUEST_ITEM },
{ 1,3, FRM__C1_L3_QUEST_ITEM },
{ 1,4, FRM__C1_L4_QUEST_ITEM },
{ 2,1, FRM__C2_L1_QUEST_ITEM },
{ 2,2, FRM__C2_L2_QUEST_ITEM },
{ 2,3, FRM__C2_L3_QUEST_ITEM },
{ 2,4, FRM__C2_L4_QUEST_ITEM },
{ 3,1, FRM__C3_L1_QUEST_ITEM },
{ 3,2, FRM__C3_L2_QUEST_ITEM },
{ 3,3, FRM__C3_L3_QUEST_ITEM },
{ 3,4, FRM__C3_L4_QUEST_ITEM },
{ 4,1, FRM__C4_QUEST_ITEM_1 },
{ 4,2, FRM__C4_QUEST_ITEM_1 },
{ 4,3, FRM__C4_QUEST_ITEM_1 },
2001-07-11 21:52:10 +02:00
{ 4,4, FRM__C4_QUEST_ITEM_1 },
2001-05-29 21:48:47 +02:00
{ 5,1, FRM__C5_L1_QUEST_ITEM },
{ 5,2, FRM__C5_L2_QUEST_ITEM },
{ 5,3, FRM__C5_L3_QUEST_ITEM },
{ 5,4, FRM__C5_L4_QUEST_ITEM },
2001-05-24 20:21:14 +02:00
};
static const int s_numQuestItemMap=sizeof(s_questItemMap)/sizeof(sQuestItemMap);
2001-02-21 16:35:38 +01:00
/*----------------------------------------------------------------------
Function:
Purpose:
Params:
Returns:
---------------------------------------------------------------------- */
2001-05-24 20:21:14 +02:00
void CQuestItemPickup::init()
2001-02-21 16:35:38 +01:00
{
2001-05-24 20:21:14 +02:00
int chapter,level;
const sQuestItemMap *qi;
int i;
sFrameHdr *fh;
2001-04-20 18:57:05 +02:00
2001-02-21 16:35:38 +01:00
CBasePickup::init();
2001-04-20 18:57:05 +02:00
2001-05-24 20:21:14 +02:00
chapter=GameScene.getChapterNumber();
level=GameScene.getLevelNumber();
m_gfxFrame=-1;
qi=s_questItemMap;
for(i=0;i<s_numQuestItemMap;i++)
{
if(qi->m_chapter==chapter&&qi->m_level==level)
{
m_gfxFrame=qi->m_gfxFrame;
break;
}
qi++;
}
ASSERT(m_gfxFrame!=-1);
2001-05-25 20:43:47 +02:00
fh=CGameScene::getSpriteBank()->getFrameHeader(m_gfxFrame);
2001-04-20 18:57:05 +02:00
setCollisionSize(fh->W,fh->H);
2001-06-12 17:41:47 +02:00
if(level==5-1)
{
m_hiddenUntilBossDead=true;
}
else
{
m_hiddenUntilBossDead=false;
}
2001-06-18 22:51:46 +02:00
m_collected=false;
m_collectedFrameCount=0;
2001-06-15 20:04:22 +02:00
2001-06-18 21:16:58 +02:00
m_starSinRotate=0;
m_starSinRadius=0;
m_starFrame=0;
2001-06-15 20:04:22 +02:00
m_starSinR=m_starSinG=m_starSinB=0;
2001-02-21 16:35:38 +01:00
}
2001-04-02 23:37:20 +02:00
/*----------------------------------------------------------------------
Function:
Purpose:
Params:
Returns:
---------------------------------------------------------------------- */
2001-05-24 20:21:14 +02:00
DVECTOR CQuestItemPickup::getSizeForPlacement()
2001-04-02 23:37:20 +02:00
{
DVECTOR size;
sFrameHdr *fh;
2001-05-25 20:43:47 +02:00
fh=CGameScene::getSpriteBank()->getFrameHeader(m_gfxFrame);
2001-04-02 23:37:20 +02:00
size.vx=fh->W;
size.vy=fh->H;
return size;
}
2001-02-21 16:35:38 +01:00
/*----------------------------------------------------------------------
Function:
Purpose:
Params:
Returns:
---------------------------------------------------------------------- */
2001-05-24 20:21:14 +02:00
void CQuestItemPickup::collect(class CPlayer *_player)
2001-02-21 23:33:17 +01:00
{
CBasePickup::collect(_player);
}
2001-06-12 17:41:47 +02:00
/*----------------------------------------------------------------------
Function:
Purpose:
Params:
Returns:
---------------------------------------------------------------------- */
void CQuestItemPickup::collidedWith(CThing *_thisThing)
{
2001-07-03 00:57:52 +02:00
if(!m_hiddenUntilBossDead&!m_collected)
2001-06-12 17:41:47 +02:00
{
2001-06-18 22:51:46 +02:00
switch(_thisThing->getThingType())
{
case TYPE_PLAYER:
// collect((CPlayer*)_thisThing);
CSoundMediator::playSfx(sfxToPlayWhenCollected());
m_collected=true;
2001-07-03 00:57:52 +02:00
((CPlayer*)_thisThing)->collectedQuestItem();
2001-06-18 22:51:46 +02:00
break;
case TYPE_NPC:
break;
default:
ASSERT(0);
}
2001-06-12 17:41:47 +02:00
}
}
2001-02-21 23:33:17 +01:00
/*----------------------------------------------------------------------
Function:
Purpose:
Params:
Returns:
---------------------------------------------------------------------- */
2001-05-24 20:21:14 +02:00
int CQuestItemPickup::getVisibilityRadius()
2001-02-21 23:33:17 +01:00
{
2001-06-15 20:04:22 +02:00
return 100;
2001-02-21 23:33:17 +01:00
}
/*----------------------------------------------------------------------
Function:
Purpose:
Params:
Returns:
---------------------------------------------------------------------- */
2001-05-24 20:21:14 +02:00
void CQuestItemPickup::thinkPickup(int _frames)
2001-02-21 16:35:38 +01:00
{
2001-06-18 22:51:46 +02:00
if(m_collected)
{
m_collectedFrameCount+=_frames;
if(m_collectedFrameCount>100)
{
collect(NULL);
}
}
2001-06-12 17:41:47 +02:00
if(!m_hiddenUntilBossDead)
2001-02-21 18:13:37 +01:00
{
2001-06-18 21:16:58 +02:00
m_starSinRotate=(m_starSinRotate+(16*_frames))&4095;
m_starSinRadius=(m_starSinRadius+(32*_frames))&4095;
m_starFrame+=_frames;
m_starSinR=(m_starSinR+(10*_frames))&4095;
m_starSinG=(m_starSinG+(20*_frames))&4095;
m_starSinB=(m_starSinB+(30*_frames))&4095;
2001-06-12 17:41:47 +02:00
}
else if(GameScene.getBossHasBeenKilled())
{
m_hiddenUntilBossDead=false;
2001-02-21 18:13:37 +01:00
}
2001-02-21 16:35:38 +01:00
}
/*----------------------------------------------------------------------
Function:
2001-06-18 22:51:46 +02:00
Purpose:
2001-02-21 16:35:38 +01:00
Params:
Returns:
---------------------------------------------------------------------- */
2001-06-18 22:51:46 +02:00
static const int s_questStarFrames[8]={FRM__QUESTITEMSTAR1,FRM__QUESTITEMSTAR2,FRM__QUESTITEMSTAR3,FRM__QUESTITEMSTAR2};
2001-05-24 20:21:14 +02:00
void CQuestItemPickup::renderPickup(DVECTOR *_pos)
2001-02-21 16:35:38 +01:00
{
2001-06-12 17:41:47 +02:00
if(!m_hiddenUntilBossDead)
{
2001-06-15 20:04:22 +02:00
DVECTOR pos;
SpriteBank *sprites;
sFrameHdr *fh;
int i;
int x,y;
2001-06-18 21:16:58 +02:00
int angle,radius;
int r,g,b;
2001-06-15 20:04:22 +02:00
sprites=CGameScene::getSpriteBank();
// Quest item graphic
2001-06-18 22:51:46 +02:00
if(!m_collected)
{
fh=sprites->getFrameHeader(m_gfxFrame);
x=_pos->vx-(fh->W/2);
y=_pos->vy-(fh->H/2);
sprites->printFT4(fh,x,y,0,0,OTPOS__PICKUP_POS);
}
2001-06-15 20:04:22 +02:00
// Stars
2001-06-18 21:16:58 +02:00
angle=m_starSinRotate;
2001-06-18 22:51:46 +02:00
radius=((msin(m_starSinRadius)*20)>>12)+40+(m_collectedFrameCount*2);
2001-06-18 21:16:58 +02:00
r=((msin(m_starSinR)*64)>>12)+128;
g=((msin(m_starSinG)*64)>>12)+128;
b=((msin(m_starSinB)*64)>>12)+128;
2001-06-18 22:51:46 +02:00
fh=sprites->getFrameHeader(s_questStarFrames[(m_starFrame>>3)&3]);
2001-06-15 20:04:22 +02:00
for(i=0;i<4;i++)
{
POLY_FT4 *ft4;
2001-06-18 22:51:46 +02:00
x=_pos->vx+((msin(angle)*radius)>>12);
y=_pos->vy+((mcos(angle)*radius)>>12);
2001-06-15 20:04:22 +02:00
ft4=sprites->printFT4(fh,x,y,0,0,0);
setRGB0(ft4,r,g,b);
2001-06-18 22:51:46 +02:00
angle=(angle+1024)&4095;
2001-06-18 21:16:58 +02:00
}
2001-06-18 22:51:46 +02:00
angle=(m_starSinRotate+512)&4095;
radius=((msin((m_starSinRadius+2048)&4095)*20)>>12)+40+(m_collectedFrameCount*2);
2001-06-18 21:16:58 +02:00
r=((msin((m_starSinR+2048)&4095)*64)>>12)+128;
g=((msin((m_starSinG+2048)&4095)*64)>>12)+128;
b=((msin((m_starSinB+2048)&4095)*64)>>12)+128;
2001-06-18 22:51:46 +02:00
fh=sprites->getFrameHeader(s_questStarFrames[((m_starFrame>>3)+2)&3]);
2001-06-18 21:16:58 +02:00
for(i=0;i<4;i++)
{
POLY_FT4 *ft4;
2001-06-18 22:51:46 +02:00
x=_pos->vx+((msin(angle)*radius)>>12);
y=_pos->vy+((mcos(angle)*radius)>>12);
2001-06-18 21:16:58 +02:00
ft4=sprites->printFT4(fh,x,y,0,0,0);
setRGB0(ft4,r,g,b);
2001-06-18 22:51:46 +02:00
angle=(angle+1024)&4095;
2001-06-15 20:04:22 +02:00
}
2001-02-21 18:13:37 +01:00
}
2001-02-21 16:35:38 +01:00
}
/*===========================================================================
end */