diff --git a/demo1.cpp b/demo1.cpp index 9f85c96..aa3b5c9 100644 --- a/demo1.cpp +++ b/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) @@ -962,23 +965,18 @@ Unit floorHeightAt(int16_t x, int16_t y) if (x == 6 && (y == 13 || y == 14)) // moving lift 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.