Continue block collisions
This commit is contained in:
parent
011cd891c1
commit
fa66324833
4 changed files with 100 additions and 36 deletions
50
map.h
50
map.h
|
@ -148,6 +148,20 @@ void LCR_mapBlockGetCoords(const uint8_t block[LCR_BLOCK_SIZE],
|
|||
*z = (block[2] >> 4) | ((block[3] & 0x03) << 4);
|
||||
}
|
||||
|
||||
uint8_t LCR_mapBlockOppositeTransform(uint8_t transform)
|
||||
{
|
||||
if (!(transform & LCR_BLOCK_TRANSFORM_FLIP_H))
|
||||
{
|
||||
if ((transform & 0x60) == LCR_BLOCK_TRANSFORM_ROT_90)
|
||||
return ((transform & (~0x60)) | LCR_BLOCK_TRANSFORM_ROT_270);
|
||||
|
||||
if ((transform & 0x60) == LCR_BLOCK_TRANSFORM_ROT_270)
|
||||
return ((transform & (~0x60)) | LCR_BLOCK_TRANSFORM_ROT_90);
|
||||
}
|
||||
|
||||
return transform;
|
||||
}
|
||||
|
||||
uint8_t LCR_mapBlockGetTransform(const uint8_t block[LCR_BLOCK_SIZE])
|
||||
{
|
||||
return block[3] & 0xf0;
|
||||
|
@ -171,6 +185,15 @@ uint32_t LCR_mapBlockCoordsToCoordNumber(uint8_t x, uint8_t y, uint8_t z)
|
|||
return LCR_mapBlockGetCoordNumber(b);
|
||||
}
|
||||
|
||||
int LCR_rampHeight4ths(uint8_t rampType)
|
||||
{
|
||||
return
|
||||
(rampType == LCR_BLOCK_RAMP_14) +
|
||||
(rampType == LCR_BLOCK_RAMP) * 4 +
|
||||
(rampType == LCR_BLOCK_RAMP_12 || rampType == LCR_BLOCK_RAMP_34) * 2 +
|
||||
(rampType == LCR_BLOCK_RAMP_34);
|
||||
}
|
||||
|
||||
uint8_t *LCR_getMapBlockAtCoordNumber(uint32_t coord)
|
||||
{
|
||||
// binary search the block:
|
||||
|
@ -424,6 +447,21 @@ void _LCR_addBlockShapeByte(uint8_t *bytes, uint8_t *byteCount,
|
|||
*byteCount += 1;
|
||||
}
|
||||
|
||||
|
||||
|
||||
#define LCR_TRANSFORM_COORDS(trans,cx,cy,cz,maxXZ,maxY)\
|
||||
if (trans & LCR_BLOCK_TRANSFORM_FLIP_H) cx = maxXZ - cx;\
|
||||
if (trans & 0x20) { /* for both 90 and 270 */ \
|
||||
cx ^= cz; cz ^= cx; cx ^= cz; /* swap */ \
|
||||
cx = maxXZ - cx; } \
|
||||
if (trans & 0x40) { /* for both 180 and 270 */ \
|
||||
cx = maxXZ - cx; \
|
||||
cz = maxXZ - cz; } \
|
||||
if (trans & LCR_BLOCK_TRANSFORM_FLIP_V) \
|
||||
cy = maxY - cy;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
Gets a shape of given map block type as a 3D model composed of triangles. The
|
||||
model is returned as an array of byte triplets (triangles), with each byte
|
||||
|
@ -521,11 +559,7 @@ void LCR_mapGetBlockShape(uint8_t blockType, uint8_t transform,
|
|||
case LCR_BLOCK_RAMP_14:
|
||||
case LCR_BLOCK_RAMP_34:
|
||||
{
|
||||
uint8_t top =
|
||||
(blockType == LCR_BLOCK_RAMP_14) +
|
||||
(blockType == LCR_BLOCK_RAMP) * 4 +
|
||||
(blockType == LCR_BLOCK_RAMP_12 || blockType == LCR_BLOCK_RAMP_34) * 2 +
|
||||
(blockType == LCR_BLOCK_RAMP_34);
|
||||
uint8_t top = LCR_rampHeight4ths(blockType);
|
||||
|
||||
ADD(0,0,0) ADD(0,top,6) ADD(0,0,6) // side
|
||||
ADD(6,0,0) ADD(6,0,6) ADD(6,top,6) // side
|
||||
|
@ -549,7 +583,10 @@ void LCR_mapGetBlockShape(uint8_t blockType, uint8_t transform,
|
|||
uint8_t x, y, z, tmp;
|
||||
|
||||
_LCR_decodeMapBlockCoords(bytes[i],&x,&y,&z);
|
||||
|
||||
|
||||
LCR_TRANSFORM_COORDS(transform,x,y,z,6,4)
|
||||
|
||||
/*
|
||||
if (transform & LCR_BLOCK_TRANSFORM_FLIP_H)
|
||||
x = 6 - x;
|
||||
|
||||
|
@ -568,6 +605,7 @@ void LCR_mapGetBlockShape(uint8_t blockType, uint8_t transform,
|
|||
|
||||
if (transform & LCR_BLOCK_TRANSFORM_FLIP_V)
|
||||
y = 4 - y;
|
||||
*/
|
||||
|
||||
bytes[i] = _LCR_encodeMapBlockCoords(x,y,z);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue