2001-06-14 23:08:42 +02:00
|
|
|
/******************************/
|
|
|
|
/*** Health throw out stuff ***/
|
|
|
|
/******************************/
|
|
|
|
|
|
|
|
#include "system\global.h"
|
|
|
|
#include "mem\memory.h"
|
|
|
|
#include "gfx\sprbank.h"
|
|
|
|
#include "utils\utils.h"
|
|
|
|
#include "gfx\prim.h"
|
|
|
|
//#include "gfx\actor.h"
|
|
|
|
#include "game\game.h"
|
|
|
|
#include "player\player.h"
|
|
|
|
#include "gfx\otpos.h"
|
|
|
|
#include "game\healthman.h"
|
|
|
|
|
|
|
|
#include <sprites.h>
|
|
|
|
|
|
|
|
CHealthManager::sItemTable CHealthManager::ItemTable[]=
|
|
|
|
{
|
|
|
|
{5,256, 255,255,0},
|
|
|
|
{1,256, 127,127,127},
|
|
|
|
};
|
2001-06-14 17:28:07 +02:00
|
|
|
|
2001-06-14 23:08:42 +02:00
|
|
|
const int CHealthManager::ItemTableSize=sizeof(CHealthManager::ItemTable)/sizeof(CHealthManager::sItemTable);
|
2001-06-14 17:28:07 +02:00
|
|
|
|
2001-06-14 23:08:42 +02:00
|
|
|
int HealthManGrav=128;
|
|
|
|
int HealthManShift=9;
|
2001-07-25 23:30:13 +02:00
|
|
|
int HealthManPickUpDelay=32;
|
2001-06-14 17:28:07 +02:00
|
|
|
|
2001-06-14 23:08:42 +02:00
|
|
|
/*****************************************************************************/
|
|
|
|
void CHealthManager::init()
|
|
|
|
{
|
2001-07-25 23:30:13 +02:00
|
|
|
sItem *list=ItemList;
|
|
|
|
|
2001-06-14 23:08:42 +02:00
|
|
|
FrameHdr=CGameScene::getSpriteBank()->getFrameHeader(FRM__SPATULA);
|
|
|
|
for (int i=0; i<ITEM_MAX; i++)
|
|
|
|
{
|
2001-07-25 23:30:13 +02:00
|
|
|
list->Life=0;
|
|
|
|
setTSprt(&list->Sprite);
|
|
|
|
setTSprtTPage(&list->Sprite,FrameHdr->TPage);
|
|
|
|
list->Sprite.clut=FrameHdr->Clut;
|
|
|
|
list->Sprite.u0=FrameHdr->U;
|
|
|
|
list->Sprite.v0=FrameHdr->V;
|
|
|
|
list->Sprite.w=FrameHdr->W;
|
|
|
|
list->Sprite.h=FrameHdr->H;
|
|
|
|
list++;
|
2001-06-14 23:08:42 +02:00
|
|
|
}
|
2001-06-14 17:28:07 +02:00
|
|
|
|
2001-06-14 23:08:42 +02:00
|
|
|
}
|
2001-06-14 17:28:07 +02:00
|
|
|
|
2001-06-14 23:08:42 +02:00
|
|
|
/*****************************************************************************/
|
|
|
|
void CHealthManager::shutdown()
|
|
|
|
{
|
|
|
|
}
|
2001-06-14 17:28:07 +02:00
|
|
|
|
2001-06-14 23:08:42 +02:00
|
|
|
/*****************************************************************************/
|
|
|
|
const int AngleS=2048+1024+512;
|
2001-07-23 21:26:37 +02:00
|
|
|
void CHealthManager::drop(DVECTOR const &Pos,int Amount,int Vel)
|
2001-06-14 23:08:42 +02:00
|
|
|
{
|
|
|
|
int Count=0;
|
|
|
|
int Am=Amount;
|
|
|
|
// Count em for Arc
|
|
|
|
for (int i=0; i<ItemTableSize; i++)
|
|
|
|
{
|
|
|
|
sItemTable &T=ItemTable[i];
|
|
|
|
|
|
|
|
while (Amount>=T.Count)
|
|
|
|
{
|
|
|
|
Amount-=T.Count;
|
|
|
|
Count++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
int Angle=AngleS;
|
|
|
|
int AngleInc=1024/Count;
|
|
|
|
// Split Em
|
|
|
|
Amount=Am;
|
|
|
|
for (int i=0; i<ItemTableSize; i++)
|
|
|
|
{
|
|
|
|
sItemTable &T=ItemTable[i];
|
|
|
|
|
|
|
|
while (Amount>=T.Count)
|
|
|
|
{
|
|
|
|
Amount-=T.Count;
|
|
|
|
addItem(Pos,i,Angle,Vel);
|
|
|
|
Angle+=AngleInc;
|
|
|
|
Angle&=4095;
|
|
|
|
}
|
|
|
|
}
|
2001-07-23 23:35:55 +02:00
|
|
|
think(1);
|
2001-06-14 23:08:42 +02:00
|
|
|
}
|
2001-06-14 17:28:07 +02:00
|
|
|
|
2001-06-14 23:08:42 +02:00
|
|
|
/*****************************************************************************/
|
2001-07-23 21:26:37 +02:00
|
|
|
void CHealthManager::addItem(DVECTOR const &Pos,int TableIdx,int Angle,int Vel)
|
2001-06-14 23:08:42 +02:00
|
|
|
{
|
|
|
|
int Idx=0;
|
2001-07-25 23:30:13 +02:00
|
|
|
sItem *item;
|
2001-06-14 17:28:07 +02:00
|
|
|
|
2001-06-14 23:08:42 +02:00
|
|
|
while (ItemList[Idx].Life) Idx++;
|
|
|
|
ASSERT(Idx<ITEM_MAX);
|
2001-06-14 17:28:07 +02:00
|
|
|
|
2001-07-25 23:30:13 +02:00
|
|
|
item=&ItemList[Idx];
|
|
|
|
item->Life=ItemTable[TableIdx].Life;
|
|
|
|
setRGB0(&item->Sprite,ItemTable[TableIdx].R,ItemTable[TableIdx].G,ItemTable[TableIdx].B);
|
|
|
|
item->Pos.vx=Pos.vx<<HealthManShift;
|
|
|
|
item->Pos.vy=Pos.vy<<HealthManShift;
|
2001-06-14 17:28:07 +02:00
|
|
|
|
2001-07-25 23:30:13 +02:00
|
|
|
item->Vel.vx=-(msin(Angle)*Vel);//>>1;
|
|
|
|
item->Vel.vy=-(mcos(Angle)*Vel);
|
2001-07-03 00:18:18 +02:00
|
|
|
|
2001-07-25 23:30:13 +02:00
|
|
|
// item->Pos.vx+=item->Vel.vx;
|
|
|
|
// item->Pos.vy+=item->Vel.vy;
|
2001-07-03 00:18:18 +02:00
|
|
|
|
2001-07-25 23:30:13 +02:00
|
|
|
item->Count=ItemTable[TableIdx].Count;
|
2001-06-14 23:08:42 +02:00
|
|
|
}
|
2001-06-14 17:28:07 +02:00
|
|
|
|
2001-06-14 23:08:42 +02:00
|
|
|
/*****************************************************************************/
|
|
|
|
void CHealthManager::checkPlayerCol(CPlayer *Player)
|
|
|
|
{
|
2001-07-25 23:30:13 +02:00
|
|
|
CRECT PRect=Player->getCollisionArea();
|
|
|
|
sItem *item=ItemList;
|
|
|
|
|
|
|
|
|
|
|
|
PRect.x1+=8;
|
|
|
|
PRect.x2+=8;
|
|
|
|
PRect.y1+=16;
|
|
|
|
PRect.y2+=16;
|
2001-06-14 23:08:42 +02:00
|
|
|
|
|
|
|
for (int i=0; i<ITEM_MAX; i++)
|
|
|
|
{
|
2001-07-25 23:30:13 +02:00
|
|
|
if (item->Life && item->Life<256-HealthManPickUpDelay)
|
2001-06-14 23:08:42 +02:00
|
|
|
{
|
2001-07-25 23:30:13 +02:00
|
|
|
if (PRect.x2<item->ScrPos.vx || PRect.x1>item->ScrPos.vx+16 ||
|
|
|
|
PRect.y2<item->ScrPos.vy || PRect.y1>item->ScrPos.vy+32)
|
2001-06-14 23:08:42 +02:00
|
|
|
{
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2001-07-25 23:30:13 +02:00
|
|
|
item->Life=0;
|
|
|
|
Player->addSpatula(item->Count);
|
2001-06-14 23:08:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2001-06-14 17:28:07 +02:00
|
|
|
|
2001-07-25 23:30:13 +02:00
|
|
|
item++;
|
2001-06-14 23:08:42 +02:00
|
|
|
}
|
|
|
|
}
|
2001-06-14 17:28:07 +02:00
|
|
|
|
2001-06-14 23:08:42 +02:00
|
|
|
/*****************************************************************************/
|
|
|
|
/*** think *******************************************************************/
|
|
|
|
/*****************************************************************************/
|
|
|
|
void CHealthManager::think(int frames)
|
2001-06-14 17:28:07 +02:00
|
|
|
{
|
2001-07-25 23:30:13 +02:00
|
|
|
sItem *item=ItemList;
|
|
|
|
|
2001-06-14 23:08:42 +02:00
|
|
|
CLayerCollision *ColLayer=CGameScene::getCollision();
|
|
|
|
|
|
|
|
for (int i=0; i<ITEM_MAX; i++)
|
|
|
|
{
|
|
|
|
for (int f=0; f<frames; f++)
|
|
|
|
{
|
2001-07-25 23:30:13 +02:00
|
|
|
if (item->Life>1)
|
2001-06-14 23:08:42 +02:00
|
|
|
{
|
2001-07-23 23:35:55 +02:00
|
|
|
int OldY=ItemList[i].Pos.vy;
|
2001-07-25 23:30:13 +02:00
|
|
|
item->Life--;
|
|
|
|
item->Pos.vx+=item->Vel.vx;
|
|
|
|
item->Pos.vy+=item->Vel.vy;
|
|
|
|
item->ScrPos.vx=item->Pos.vx>>HealthManShift;
|
|
|
|
item->ScrPos.vy=item->Pos.vy>>HealthManShift;
|
|
|
|
item->Vel.vy+=HealthManGrav;
|
|
|
|
|
|
|
|
// if (item->Vel.vy>0)
|
2001-07-23 23:35:55 +02:00
|
|
|
{
|
2001-07-25 23:30:13 +02:00
|
|
|
int DistY = ColLayer->getHeightFromGround( item->ScrPos.vx, item->ScrPos.vy, 16 );
|
2001-06-14 23:08:42 +02:00
|
|
|
if (DistY<=0)
|
|
|
|
{
|
2001-07-25 23:30:13 +02:00
|
|
|
if (item->Vel.vy<0)
|
2001-07-23 23:35:55 +02:00
|
|
|
{
|
2001-07-25 23:30:13 +02:00
|
|
|
item->Pos.vy=OldY;
|
2001-07-23 23:35:55 +02:00
|
|
|
}
|
2001-07-25 23:30:13 +02:00
|
|
|
item->Vel.vy=-item->Vel.vy>>1;
|
|
|
|
item->Vel.vx>>=1;
|
|
|
|
// item->Pos.vy-=DistY<<(HealthManShift-1);
|
2001-06-14 23:08:42 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int XOfs;
|
2001-07-25 23:30:13 +02:00
|
|
|
if (item->Vel.vx>0)
|
2001-06-14 23:08:42 +02:00
|
|
|
{
|
|
|
|
XOfs=+16;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
XOfs=-16;
|
|
|
|
}
|
|
|
|
// Check X collision
|
2001-07-25 23:30:13 +02:00
|
|
|
int DistX = ColLayer->getHeightFromGround( item->ScrPos.vx+XOfs, item->ScrPos.vy, 32 );
|
2001-06-14 23:08:42 +02:00
|
|
|
if (DistX<=0)
|
|
|
|
{
|
2001-07-25 23:30:13 +02:00
|
|
|
item->Vel.vx=-item->Vel.vx>>1;
|
|
|
|
// item->Pos.vy-=DistY<<(HealthManShift-1);
|
2001-06-14 23:08:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2001-07-25 23:30:13 +02:00
|
|
|
else
|
|
|
|
{
|
|
|
|
item->Life=0;
|
|
|
|
}
|
2001-06-14 23:08:42 +02:00
|
|
|
}
|
2001-07-25 23:30:13 +02:00
|
|
|
|
|
|
|
item++;
|
2001-06-14 17:28:07 +02:00
|
|
|
}
|
|
|
|
|
2001-06-14 23:08:42 +02:00
|
|
|
}
|
2001-06-14 17:28:07 +02:00
|
|
|
|
2001-06-14 23:08:42 +02:00
|
|
|
/*****************************************************************************/
|
|
|
|
/*** render ******************************************************************/
|
|
|
|
/*****************************************************************************/
|
|
|
|
void CHealthManager::render()
|
2001-06-14 17:28:07 +02:00
|
|
|
{
|
2001-07-25 23:30:13 +02:00
|
|
|
sItem *list=ItemList;
|
2001-06-14 23:08:42 +02:00
|
|
|
sOT *ThisOT=OtPtr;//+OTPOS__PICKUP_POS;
|
|
|
|
DVECTOR const &CamPos=CLevel::getCameraPos();
|
|
|
|
for (int i=0; i<ITEM_MAX; i++)
|
|
|
|
{
|
2001-07-25 23:30:13 +02:00
|
|
|
int life=list->Life;
|
|
|
|
if (life&&(life<256-HealthManPickUpDelay||life&3))
|
2001-06-14 23:08:42 +02:00
|
|
|
{
|
|
|
|
// Calc render pos (dont worry about clipping yet)
|
2001-07-25 23:30:13 +02:00
|
|
|
list->Sprite.x0 = list->ScrPos.vx - CamPos.vx;
|
|
|
|
list->Sprite.y0 = (list->ScrPos.vy - CamPos.vy)-32;
|
2001-06-14 17:28:07 +02:00
|
|
|
|
2001-07-25 23:30:13 +02:00
|
|
|
addPrim(ThisOT,&list->Sprite);
|
2001-06-14 23:08:42 +02:00
|
|
|
}
|
2001-07-25 23:30:13 +02:00
|
|
|
list++;
|
2001-06-14 23:08:42 +02:00
|
|
|
}
|
2001-06-14 17:28:07 +02:00
|
|
|
|
|
|
|
}
|