2001-04-17 18:42:07 +02:00
|
|
|
/***********************/
|
|
|
|
/*** Layer Collision ***/
|
|
|
|
/***********************/
|
|
|
|
|
|
|
|
#include <DaveLib.h>
|
|
|
|
#include <List2d.h>
|
|
|
|
|
|
|
|
#include "MkLevelLayer.h"
|
|
|
|
#include "MkLevelLayerCollision.h"
|
|
|
|
|
2001-05-09 23:56:48 +02:00
|
|
|
/*
|
|
|
|
0 - Blank
|
|
|
|
1 - Solid block (no flips)
|
|
|
|
2 - slope0
|
|
|
|
3 - slope0 flip x
|
|
|
|
4 - slope1
|
|
|
|
5 - slope1 flip x
|
|
|
|
6 - slope2
|
|
|
|
7 - slope2 flip x
|
|
|
|
*/
|
2001-04-17 18:42:07 +02:00
|
|
|
/*****************************************************************************/
|
|
|
|
/*****************************************************************************/
|
|
|
|
/*****************************************************************************/
|
|
|
|
CMkLevelLayerCollision::CMkLevelLayerCollision(sExpLayerHdr *LayerHdr)
|
|
|
|
{
|
|
|
|
Type=LayerHdr->Type;
|
|
|
|
SubType=LayerHdr->SubType;
|
|
|
|
Width=LayerHdr->Width;
|
|
|
|
Height=LayerHdr->Height;
|
|
|
|
|
|
|
|
sExpColTile *MapPtr=(sExpColTile*)((int)LayerHdr+sizeof(sExpLayerHdr));
|
|
|
|
|
|
|
|
Map.SetSize(Width,Height);
|
|
|
|
|
|
|
|
for (int Y=0; Y<Height; Y++)
|
|
|
|
{
|
|
|
|
for (int X=0; X<Width; X++)
|
|
|
|
{
|
|
|
|
Map.Set(X,Y,*MapPtr++);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
/*****************************************************************************/
|
|
|
|
/*** Pre-Process *************************************************************/
|
|
|
|
/*****************************************************************************/
|
|
|
|
/*****************************************************************************/
|
|
|
|
void CMkLevelLayerCollision::PreProcess(CMkLevel *Core)
|
|
|
|
{
|
|
|
|
//printf("PreProcess Collision Layer\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
/*****************************************************************************/
|
|
|
|
/*** Process *****************************************************************/
|
|
|
|
/*****************************************************************************/
|
|
|
|
/*****************************************************************************/
|
|
|
|
void CMkLevelLayerCollision::Process(CMkLevel *Core)
|
|
|
|
{
|
|
|
|
//printf("Process Collision Layer\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
/*****************************************************************************/
|
|
|
|
/** Write ********************************************************************/
|
|
|
|
/*****************************************************************************/
|
|
|
|
/*****************************************************************************/
|
2001-05-30 19:02:54 +02:00
|
|
|
static const u8 s_collisionTileRemapTable[17]=
|
|
|
|
{
|
|
|
|
0,
|
|
|
|
1,
|
|
|
|
1,
|
|
|
|
1,
|
|
|
|
1,
|
|
|
|
2,
|
|
|
|
3,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
4,
|
|
|
|
5,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
6,
|
|
|
|
7,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
};
|
|
|
|
|
2001-04-17 18:42:07 +02:00
|
|
|
int CMkLevelLayerCollision::Write(FILE *File,const char *LayerName,const char *MapName)
|
|
|
|
{
|
|
|
|
sLayerHdr Hdr;
|
|
|
|
int ThisPos=ftell(File);
|
|
|
|
int Width=Map.GetWidth();
|
|
|
|
int Height=Map.GetHeight();
|
|
|
|
|
|
|
|
Hdr.Type=Type;
|
|
|
|
Hdr.SubType=SubType;
|
|
|
|
Hdr.Width=Width;
|
|
|
|
Hdr.Height=Height;
|
|
|
|
fwrite(&Hdr,sizeof(sLayerHdr),1,File);
|
|
|
|
|
|
|
|
for (int Y=0; Y<Height; Y++)
|
|
|
|
{
|
|
|
|
for (int X=0; X<Width; X++)
|
|
|
|
{
|
|
|
|
sExpColTile &ThisElem=Map.Get(X,Y);
|
|
|
|
u8 OutElem;
|
|
|
|
|
2001-05-30 19:02:54 +02:00
|
|
|
OutElem=s_collisionTileRemapTable[ThisElem.Tile];
|
2001-05-09 23:56:48 +02:00
|
|
|
OutElem|=ThisElem.Flags<<COLLISION_TYPE_FLAG_SHIFT;
|
|
|
|
/*
|
|
|
|
OutElem=0;
|
|
|
|
if (ThisElem.Tile || ThisElem.Flags)
|
|
|
|
{
|
|
|
|
int FF=ThisElem.Tile & 1;
|
|
|
|
int T=(ThisElem.Tile>>1)+1;
|
|
|
|
OutElem=((T-1)*4)+1;
|
|
|
|
OutElem+=FF;
|
|
|
|
OutElem|=ThisElem.Flags<<COLLISION_TYPE_FLAG_SHIFT;
|
|
|
|
|
|
|
|
}
|
2001-04-17 18:42:07 +02:00
|
|
|
|
2001-05-09 23:56:48 +02:00
|
|
|
*/
|
|
|
|
/* if (ThisElem.Tile>(u16)COLLISION_MASK)
|
2001-04-17 18:42:07 +02:00
|
|
|
{
|
|
|
|
printf("COLLISION OVERFLOW %s: %i,%i=(%i,%i)!!\n",MapName,X,Y,ThisElem.Tile,ThisElem.Flags);
|
|
|
|
}
|
2001-05-09 23:56:48 +02:00
|
|
|
*/
|
2001-04-17 18:42:07 +02:00
|
|
|
fwrite(&OutElem,sizeof(u8),1,File);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
PadFile(File);
|
|
|
|
|
|
|
|
return(ThisPos);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*****************************************************************************/
|