From 442d0af6a8a4a084decb2d32aed2b34a4668a1be Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miloslav=20=C4=8C=C3=AD=C5=BE?= Date: Wed, 5 Sep 2018 16:25:57 +0200 Subject: [PATCH] Add square type --- game.cpp | 43 ++++++++++++++++++++++++++++++++++++++----- 1 file changed, 38 insertions(+), 5 deletions(-) diff --git a/game.cpp b/game.cpp index 91db742..87e82c9 100644 --- a/game.cpp +++ b/game.cpp @@ -34,6 +34,31 @@ Unit zBuffer[SUBSAMPLED_WIDTH]; #define LEVEL_X_RES 29 #define LEVEL_Y_RES 21 +const unsigned char levelTexture[] = +{ + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 +}; + const signed char levelFloor[] = { 40,40,40,40,40,40,40,40,48,40,48,40,40,40,40,40,40,48,40,48,40,48,40,48,48,24,24,26,28, @@ -503,7 +528,15 @@ public: Character player; Sprite sprites[SPRITES]; -Unit floorHeight(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) + return levelTexture[(LEVEL_Y_RES - y -1) * LEVEL_X_RES + x]; + + return 0; +} + +Unit floorHeightAt(int16_t x, int16_t y) { 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; @@ -511,7 +544,7 @@ Unit floorHeight(int16_t x, int16_t y) return 0; } -Unit ceilingHeight(int16_t x, int16_t y) +Unit ceilingHeightAt(int16_t x, int16_t y) { signed char v = 99; @@ -546,7 +579,7 @@ inline void pixelFunc(PixelInfo pixel) if (intensity < 0) intensity = 0; - c = sampleImage(image2,pixel.hit.textureCoord,pixel.textureCoordY); + c = sampleImage(pixel.hit.type == 0 ? image2 : image,pixel.hit.textureCoord,pixel.textureCoordY); c = addIntensity(c,intensity - 3); } else @@ -573,7 +606,7 @@ void draw() c.maxSteps = 16; c.computeTextureCoords = 1; - render(player.mCamera,floorHeight,ceilingHeight,pixelFunc,c); + render(player.mCamera,floorHeightAt,ceilingHeightAt,textureAt,pixelFunc,c); Unit previousDepth; @@ -700,7 +733,7 @@ int main() player.mCamera.direction += addition * step2; player.mCamera.height = - max(floorHeight(player.mCamera.position.x / UNITS_PER_SQUARE,player.mCamera.position.y / UNITS_PER_SQUARE) + UNITS_PER_SQUARE / 2,player.mCamera.height); + max(floorHeightAt(player.mCamera.position.x / UNITS_PER_SQUARE,player.mCamera.position.y / UNITS_PER_SQUARE) + UNITS_PER_SQUARE / 2,player.mCamera.height); } }