From 7c26888a165be96947a463bee3f7ca2bc8e4cf96 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miloslav=20=C4=8C=C3=AD=C5=BE?= Date: Sun, 16 Sep 2018 14:44:43 +0200 Subject: [PATCH] Fix demo1 OOB --- demo1.cpp | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/demo1.cpp b/demo1.cpp index e62cc81..a1ee53b 100644 --- a/demo1.cpp +++ b/demo1.cpp @@ -11,7 +11,7 @@ */ // redefine some parameters -#define FPS 40 +#define FPS 60 #define GRAVITY_ACCELERATION (UNITS_PER_SQUARE * 3) #define PLAYER_JUMP_SPEED 700 #define CAMERA_COLL_HEIGHT_BELOW ((3 * UNITS_PER_SQUARE) / 2) @@ -950,10 +950,13 @@ 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)\ + if (x >= 0 && x < LEVEL_X_RES && y >= 0 && y < LEVEL_Y_RES)\ + {\ + int16_t index = (LEVEL_Y_RES - y - 1) * LEVEL_X_RES + x;\ return (what);\ - return (whatElse); + }\ + else\ + return (whatElse); Unit textureAt(int16_t x, int16_t y) {