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};
|
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)
|
Unit textureAt(int16_t x, int16_t y)
|
||||||
{
|
{
|
||||||
if (x >= 0 && x < LEVEL_X_RES && y >= 0 && y < LEVEL_Y_RES)
|
withinMapReturn(levelTexture[index],0)
|
||||||
return levelTexture[(LEVEL_Y_RES - y -1) * LEVEL_X_RES + x];
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Unit floorHeightAt(int16_t x, int16_t y)
|
Unit floorHeightAt(int16_t x, int16_t y)
|
||||||
|
@ -962,23 +965,18 @@ Unit floorHeightAt(int16_t x, int16_t y)
|
||||||
if (x == 6 && (y == 13 || y == 14)) // moving lift
|
if (x == 6 && (y == 13 || y == 14)) // moving lift
|
||||||
return
|
return
|
||||||
((absVal(-1 * (pokitto.frameCount % 64) + 32)) * UNITS_PER_SQUARE) / 8;
|
((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)
|
Unit ceilingHeightAt(int16_t x, int16_t y)
|
||||||
{
|
{
|
||||||
signed char v = 127;
|
withinMapReturn(levelCeiling[index] * UNITS_PER_SQUARE / 8,
|
||||||
|
127 * UNITS_PER_SQUARE / 8)
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#undef withinMapReturn
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Function for drawing a single pixel (like fragment shader). Bottleneck =>
|
Function for drawing a single pixel (like fragment shader). Bottleneck =>
|
||||||
should be as fast as possible.
|
should be as fast as possible.
|
||||||
|
|
Loading…
Reference in a new issue