Add flyby
This commit is contained in:
parent
6c8badaeb7
commit
bb8be2a13e
1 changed files with 53 additions and 0 deletions
53
demo3.cpp
53
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())
|
||||
|
|
Loading…
Reference in a new issue