SBSPSS/source/level/layerback.cpp

301 lines
7.9 KiB
C++
Raw Normal View History

2001-02-22 15:55:13 +01:00
/*************************/
/*** Shade Layer Class ***/
/*************************/
2001-01-13 18:04:56 +01:00
#include "system\global.h"
#include <DStructs.h>
#include "utils\utils.h"
#include "gfx\prim.h"
2001-03-09 22:17:14 +01:00
#include "gfx\sprbank.h"
2001-01-13 18:04:56 +01:00
#include "LayerTile.h"
2001-01-15 16:22:33 +01:00
#include "LayerBack.h"
2001-01-13 18:04:56 +01:00
2001-03-09 23:10:53 +01:00
#include <levelbackgfx.h>
2001-04-04 02:16:26 +02:00
#include "Game\game.h"
2001-03-09 22:17:14 +01:00
2001-03-09 23:10:53 +01:00
sBackRGBTable CLayerBack::BackRGBTable[]=
2001-03-09 22:17:14 +01:00
{
{255, 0, 0,0},
{255,255, 0,0},
{ 0,255, 0,0},
{ 0,255,255,0},
{ 0, 0,255,0},
{255, 0,255,0},
{255,255,255,0},
{128, 0, 0,0},
{128,128, 0,0},
{ 0,128, 0,0},
{ 0,128,128,0},
{ 0, 0,128,0},
{128, 0,128,0},
{128,128,128,0},
};
#define BackRGBTableSize sizeof(BackRGBTable)/sizeof(sBackRGBTable)
2001-01-13 18:04:56 +01:00
2001-03-09 23:10:53 +01:00
sBackSpriteInfo CLayerBack::InfoTab[]=
{
{FRM_FLOWER,0,0},
{FRM_GHOST,0,3},
{FRM_PUMPKIN,0,3},
{FRM_BUBBLE,NO_SPIN | NO_SCALE | NO_COLOR,3 },
{FRM_BUBBLESMALL,NO_SPIN | NO_SCALE | NO_COLOR,3},
2001-03-12 20:23:41 +01:00
{FRM_FISHBONE,NO_COLOR,0},
2001-03-09 23:10:53 +01:00
};
2001-01-13 18:04:56 +01:00
/*****************************************************************************/
/*****************************************************************************/
/*****************************************************************************/
2001-03-08 00:20:09 +01:00
CLayerBack::CLayerBack(sLayerHdr *Hdr,sTile *TileBank) : CLayerTile(Hdr,TileBank)
2001-01-13 18:04:56 +01:00
{
2001-02-20 20:17:03 +01:00
Data=(sLayerShadeHdr*)MakePtr(Hdr,sizeof(sLayerHdr));
2001-02-20 16:56:16 +01:00
2001-02-20 20:17:03 +01:00
ASSERT(Data->Count<=LAYER_SHADE_RGB_MAX);
BandCount=Data->Count-1;
2001-03-09 22:17:14 +01:00
2001-04-04 02:16:26 +02:00
Sprites=CGameScene::GetBackSprites();
2001-01-13 18:04:56 +01:00
}
/*****************************************************************************/
2001-01-15 16:22:33 +01:00
CLayerBack::~CLayerBack()
2001-01-13 18:04:56 +01:00
{
}
/*****************************************************************************/
/*****************************************************************************/
/*****************************************************************************/
2001-02-22 15:55:13 +01:00
void CLayerBack::init(DVECTOR &MapPos,int Shift)
2001-01-13 18:04:56 +01:00
{
2001-02-20 20:17:03 +01:00
MapXYShift=Shift;
2001-02-22 15:55:13 +01:00
BandHeight=(MapHeight*16)/(BandCount);
if (BandHeight>=512) BandHeight=511;
2001-02-20 20:17:03 +01:00
for (int i=0; i<BandCount; i++)
{
SetPolyG4(&Band[i]);
setRGB0(&Band[i],Data->Data[i+0].RGB[0],Data->Data[i+0].RGB[1],Data->Data[i+0].RGB[2]);
setRGB1(&Band[i],Data->Data[i+0].RGB[0],Data->Data[i+0].RGB[1],Data->Data[i+0].RGB[2]);
setRGB2(&Band[i],Data->Data[i+1].RGB[0],Data->Data[i+1].RGB[1],Data->Data[i+1].RGB[2]);
setRGB3(&Band[i],Data->Data[i+1].RGB[0],Data->Data[i+1].RGB[1],Data->Data[i+1].RGB[2]);
}
2001-03-09 22:17:14 +01:00
2001-03-09 23:10:53 +01:00
PosDx=0;
PosDy=0;
XOfs=MapPos.vy;
YOfs=MapPos.vy;
}
/*****************************************************************************/
void CLayerBack::SetFrames(int Spr0,int Spr1)
{
int Spr[2];
Spr[0]=Spr0;
Spr[1]=Spr1;
2001-03-09 22:17:14 +01:00
for (int i=0; i<SPRITE_MAX; i++)
{
2001-03-09 23:10:53 +01:00
int Type=Spr[i&1];
2001-03-09 22:17:14 +01:00
POLY_GT4 *Gt4=&SpriteList[i].Poly;
2001-03-09 23:10:53 +01:00
sFrameHdr *Frm=Sprites->getFrameHeader(InfoTab[Type].Frame);
SpriteList[i].Type=Type;
2001-03-09 22:17:14 +01:00
Sprites->prepareGT4(Gt4,Frm,0,0,0,0);
SpriteList[i].W=Frm->W;
SpriteList[i].H=Frm->W;
setSemiTrans(Gt4,1);
2001-03-09 23:10:53 +01:00
Gt4->tpage|=InfoTab[Type].Trans<<5;
2001-03-09 22:17:14 +01:00
if (Frm->Rotated)
{
2001-03-09 23:10:53 +01:00
Gt4->u2++; Gt4->u3++;
Gt4->v2++; Gt4->v3++;
2001-03-09 22:17:14 +01:00
}
else
{
Gt4->u1--; Gt4->u3--;
Gt4->v2--; Gt4->v3--;
}
2001-03-09 23:10:53 +01:00
// Init all
setRGB0(Gt4,255,255,255);
setRGB1(Gt4,255,255,255);
setRGB2(Gt4,255,255,255);
setRGB3(Gt4,255,255,255);
SpriteList[i].Angle=0;
SpriteList[i].AngleInc=0;
SpriteList[i].PosInc.vx=0;
SpriteList[i].PosInc.vy=0;
SpriteList[i].Scale.vx=1024;
SpriteList[i].Scale.vy=1024;
SpriteList[i].ScaleInc.vx=0;
SpriteList[i].ScaleInc.vy=0;
2001-03-09 22:17:14 +01:00
InitSprite(&SpriteList[i]);
SpriteList[i].Pos.vx=getRndRange(512<<MOVE_SHIFT);
SpriteList[i].Pos.vy=getRndRange(256<<MOVE_SHIFT);
}
2001-01-13 18:04:56 +01:00
}
/*****************************************************************************/
2001-01-15 16:22:33 +01:00
void CLayerBack::shutdown()
2001-01-13 18:04:56 +01:00
{
}
2001-03-09 22:17:14 +01:00
/*****************************************************************************/
void CLayerBack::InitSprite(sBackSprite *SpritePtr)
{
int StartPos=getRnd();
int Pos=getRnd();
2001-03-12 20:23:41 +01:00
int XInc=(getRndRange((1<<((MOVE_SHIFT*1)/3))-1)+1)<<MOVE_SHIFT;
int YInc=(getRndRange((1<<((MOVE_SHIFT*1)/3))-1)+1)<<MOVE_SHIFT;
2001-03-09 22:17:14 +01:00
2001-03-09 23:10:53 +01:00
if (!(InfoTab[SpritePtr->Type].Flags & NO_MOVE))
2001-03-09 22:17:14 +01:00
{
2001-03-09 23:10:53 +01:00
switch(StartPos&3)
{
case 0: // Left
SpritePtr->Pos.vx=-63;
SpritePtr->Pos.vy=(Pos%(256+128))-63;
SpritePtr->PosInc.vx=XInc;
if (XInc&1)
SpritePtr->PosInc.vy=+YInc;
else
SpritePtr->PosInc.vy=-YInc;
break;
case 1: // Right
SpritePtr->Pos.vx=512+63;
SpritePtr->Pos.vy=(Pos%(256+128))-63;
2001-03-09 22:17:14 +01:00
SpritePtr->PosInc.vx=-XInc;
2001-03-09 23:10:53 +01:00
if (XInc&1)
SpritePtr->PosInc.vy=+YInc;
else
SpritePtr->PosInc.vy=-YInc;
break;
case 2: // Top
SpritePtr->Pos.vx=(Pos%(512+128))-63;
SpritePtr->Pos.vy=-63;
if (YInc&1)
SpritePtr->PosInc.vx=+XInc;
else
SpritePtr->PosInc.vx=-XInc;
SpritePtr->PosInc.vy=YInc;
break;
case 3: // Bottom
SpritePtr->Pos.vx=(Pos%(512+128))-63;
SpritePtr->Pos.vy=256+63;
if (YInc&1)
SpritePtr->PosInc.vx=+XInc;
else
SpritePtr->PosInc.vx=-XInc;
SpritePtr->PosInc.vy=-YInc;
break;
}
SpritePtr->Pos.vx<<=MOVE_SHIFT;
SpritePtr->Pos.vy<<=MOVE_SHIFT;
2001-03-09 22:17:14 +01:00
}
2001-03-09 23:10:53 +01:00
if (!(InfoTab[SpritePtr->Type].Flags & NO_SCALE))
{
SpritePtr->Scale.vx=getRndRange(4095);
SpritePtr->Scale.vy=getRndRange(4095);
SpritePtr->ScaleInc.vx=getRndRange(31)+31;
if (SpritePtr->ScaleInc.vx&1) SpritePtr->ScaleInc.vx=-SpritePtr->ScaleInc.vx;
SpritePtr->ScaleInc.vy=getRndRange(31)+31;
if (SpritePtr->ScaleInc.vy&1) SpritePtr->ScaleInc.vy=-SpritePtr->ScaleInc.vy;
}
if (!(InfoTab[SpritePtr->Type].Flags & NO_SPIN))
{
SpritePtr->AngleInc=getRndRange(31)+31;
if (SpritePtr->AngleInc&1) SpritePtr->AngleInc=-SpritePtr->AngleInc;
}
2001-03-09 22:17:14 +01:00
2001-03-09 23:10:53 +01:00
if (!(InfoTab[SpritePtr->Type].Flags & NO_COLOR))
{
2001-03-09 22:17:14 +01:00
int i;
i=getRndRange(BackRGBTableSize-1); SpritePtr->Poly.r0=BackRGBTable[i].R; SpritePtr->Poly.g0=BackRGBTable[i].G; SpritePtr->Poly.b0=BackRGBTable[i].B;
i=getRndRange(BackRGBTableSize-1); SpritePtr->Poly.r1=BackRGBTable[i].R; SpritePtr->Poly.g1=BackRGBTable[i].G; SpritePtr->Poly.b1=BackRGBTable[i].B;
i=getRndRange(BackRGBTableSize-1); SpritePtr->Poly.r2=BackRGBTable[i].R; SpritePtr->Poly.g2=BackRGBTable[i].G; SpritePtr->Poly.b2=BackRGBTable[i].B;
i=getRndRange(BackRGBTableSize-1); SpritePtr->Poly.r3=BackRGBTable[i].R; SpritePtr->Poly.g3=BackRGBTable[i].G; SpritePtr->Poly.b3=BackRGBTable[i].B;
2001-03-09 23:10:53 +01:00
}
2001-03-09 22:17:14 +01:00
}
2001-01-13 18:04:56 +01:00
/*****************************************************************************/
2001-02-22 15:55:13 +01:00
extern DVECTOR TileMapOfs;
2001-01-15 16:22:33 +01:00
void CLayerBack::think(DVECTOR &MapPos)
2001-02-20 16:56:16 +01:00
{
2001-03-09 22:17:14 +01:00
int _XOfs=MapPos.vx>>MapXYShift;
int _YOfs=MapPos.vy>>MapXYShift;
_YOfs+=TileMapOfs.vy;
PosDx=(_XOfs-XOfs)<<MOVE_SHIFT;
PosDy=(_YOfs-YOfs)<<MOVE_SHIFT;
XOfs=_XOfs;
YOfs=_YOfs;
2001-01-13 18:04:56 +01:00
}
/*****************************************************************************/
2001-03-09 22:17:14 +01:00
int Tran=0;
2001-01-15 16:22:33 +01:00
void CLayerBack::render()
2001-01-13 18:04:56 +01:00
{
2001-03-09 22:17:14 +01:00
const int OTPos=(MAX_OT-1);
sOT *ThisOT=OtPtr+OTPos;
int i,ThisY=-YOfs;
2001-02-20 20:17:03 +01:00
2001-03-09 22:17:14 +01:00
// Render Back Sprites
sBackSprite *SpritePtr=SpriteList;
for (i=0; i<SPRITE_MAX; i++)
{
SpritePtr->Pos.vx+=SpritePtr->PosInc.vx;
SpritePtr->Pos.vy+=SpritePtr->PosInc.vy;
SpritePtr->Pos.vx-=PosDx;
SpritePtr->Pos.vy-=PosDy;
SpritePtr->Angle+=SpritePtr->AngleInc;
SpritePtr->Angle&=4095;
SpritePtr->Scale.vx+=SpritePtr->ScaleInc.vx;
SpritePtr->Scale.vx&=4095;
SpritePtr->Scale.vy+=SpritePtr->ScaleInc.vy;
SpritePtr->Scale.vy&=4095;
int X=(SpritePtr->Pos.vx>>MOVE_SHIFT);
int Y=(SpritePtr->Pos.vy>>MOVE_SHIFT);
if (X<-64 || X>512+64 || Y<-64 || Y>256+64)
{
InitSprite(SpritePtr);
}
POLY_GT4 *Gt4=&SpriteList[i].Poly;
int ScaleX=msin(SpritePtr->Scale.vx);
int ScaleY=msin(SpritePtr->Scale.vy);
Gt4->tpage|=Tran<<5;
sBox Box;
Sprites->RotateBox(&Box,SpritePtr->W,SpritePtr->W,ScaleX,ScaleY,SpritePtr->Angle);
Gt4->x0=X+Box.x0; Gt4->y0=Y+Box.y0;
Gt4->x1=X+Box.x1; Gt4->y1=Y+Box.y1;
Gt4->x2=X+Box.x2; Gt4->y2=Y+Box.y2;
Gt4->x3=X+Box.x3; Gt4->y3=Y+Box.y3;
AddPrim(ThisOT,Gt4);
SpritePtr++;
}
// Render Back Shade
for (i=0; i<BandCount; i++)
2001-02-20 20:17:03 +01:00
{
setXYWH(&Band[i],0,ThisY,512,BandHeight);
addPrim(ThisOT,&Band[i]);
ThisY+=BandHeight;
}
2001-01-13 18:04:56 +01:00
}