From bb8be2a13ec6642edb408cba728378056b65da71 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miloslav=20=C4=8C=C3=AD=C5=BE?= Date: Tue, 11 Sep 2018 10:12:31 +0200 Subject: [PATCH] Add flyby --- demo3.cpp | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) diff --git a/demo3.cpp b/demo3.cpp index faf0349..4469723 100644 --- a/demo3.cpp +++ b/demo3.cpp @@ -239,6 +239,8 @@ inline void pixelFunc(PixelInfo pixel) *buf = c; } +bool flyBy = true; + void draw() { RayConstraints c; @@ -250,6 +252,44 @@ void draw() player.mCamera.height += player.mHeadBob; render(player.mCamera,floorHeightAt,0,colorAt,pixelFunc,c); player.mCamera.height -= player.mHeadBob; + + if (flyBy && (pokitto.frameCount >> 3) % 3 != 0) + { + pokitto.display.setCursor(25,5); + pokitto.display.setColor(rgbToIndex(1,0,0)); + pokitto.display.invisiblecolor = 0; + pokitto.display.print("press any key"); + } +} + +void cameraFlyBy(uint32_t dt) +{ + Unit height = floorHeightAt( + divRoundDown(player.mCamera.position.x,UNITS_PER_SQUARE), + divRoundDown(player.mCamera.position.y,UNITS_PER_SQUARE)) + UNITS_PER_SQUARE * 3; + + Unit heightDiff = player.mCamera.height - height; + + Unit step = (100 * dt) / 1000; + + if (heightDiff > UNITS_PER_SQUARE * 2) + { + player.mCamera.height -= step * heightDiff / 200; + player.mCamera.shear = max(player.mCamera.shear - 1,-80); + } + else + { + if (heightDiff < UNITS_PER_SQUARE) + player.mCamera.height += step * absVal(heightDiff / 70); + + if (player.mCamera.shear < 0 && pokitto.frameCount % 2 == 0) + player.mCamera.shear++; + } + + player.mCamera.position.x += step * 30; + player.mCamera.position.y += step * 15; + + player.mCamera.direction = sinInt(pokitto.frameCount / 4); } int main() @@ -264,6 +304,7 @@ int main() squareColors[3] = rgbToIndex(4,4,0); player.setPositionSquare(4,5); + player.mCamera.height = floorHeightAt(4,5); // init changes @@ -297,6 +338,18 @@ int main() dt = timeNow - previousTime; previousTime = timeNow; + if (flyBy) + { + cameraFlyBy(dt); + + if (pokitto.aBtn() || pokitto.bBtn() || pokitto.cBtn() || + pokitto.upBtn() || pokitto.downBtn() || pokitto.leftBtn() || + pokitto.rightBtn()) + flyBy = false; + + continue; + } + strafe = pokitto.aBtn(); if (pokitto.cBtn())