Add macro
This commit is contained in:
parent
93bb145d48
commit
567ad36e55
1 changed files with 12 additions and 14 deletions
26
demo1.cpp
26
demo1.cpp
|
@ -949,12 +949,15 @@ const unsigned char spriteTorch2[] =
|
|||
|
||||
const unsigned char *textures[] = {texture1, texture2, texture3, texture4};
|
||||
|
||||
#define withinMapReturn(what,whatElse)\
|
||||
int16_t index = (LEVEL_Y_RES - y - 1) * LEVEL_X_RES + x;\
|
||||
if (index > 0 && index < LEVEL_Y_RES * LEVEL_X_RES)\
|
||||
return (what);\
|
||||
return (whatElse);
|
||||
|
||||
Unit textureAt(int16_t x, int16_t y)
|
||||
{
|
||||
if (x >= 0 && x < LEVEL_X_RES && y >= 0 && y < LEVEL_Y_RES)
|
||||
return levelTexture[(LEVEL_Y_RES - y -1) * LEVEL_X_RES + x];
|
||||
|
||||
return 0;
|
||||
withinMapReturn(levelTexture[index],0)
|
||||
}
|
||||
|
||||
Unit floorHeightAt(int16_t x, int16_t y)
|
||||
|
@ -963,22 +966,17 @@ Unit floorHeightAt(int16_t x, int16_t y)
|
|||
return
|
||||
((absVal(-1 * (pokitto.frameCount % 64) + 32)) * UNITS_PER_SQUARE) / 8;
|
||||
|
||||
if (x >= 0 && x < LEVEL_X_RES && y >= 0 && y < LEVEL_Y_RES)
|
||||
return (levelFloor[(LEVEL_Y_RES - y -1) * LEVEL_X_RES + x] * UNITS_PER_SQUARE) / 8;
|
||||
|
||||
return 0;
|
||||
withinMapReturn((levelFloor[index] * UNITS_PER_SQUARE) / 8,0)
|
||||
}
|
||||
|
||||
Unit ceilingHeightAt(int16_t x, int16_t y)
|
||||
{
|
||||
signed char v = 127;
|
||||
|
||||
if (x >= 0 && x < LEVEL_X_RES && y >= 0 && y < LEVEL_Y_RES)
|
||||
v = levelCeiling[(LEVEL_Y_RES - y -1) * LEVEL_X_RES + x];
|
||||
|
||||
return (v * UNITS_PER_SQUARE) / 8;
|
||||
withinMapReturn(levelCeiling[index] * UNITS_PER_SQUARE / 8,
|
||||
127 * UNITS_PER_SQUARE / 8)
|
||||
}
|
||||
|
||||
#undef withinMapReturn
|
||||
|
||||
/**
|
||||
Function for drawing a single pixel (like fragment shader). Bottleneck =>
|
||||
should be as fast as possible.
|
||||
|
|
Loading…
Reference in a new issue