From 45edf7aedba655391ed4d04a751aaf846baaa2e7 Mon Sep 17 00:00:00 2001 From: Foxar Date: Tue, 8 Dec 2020 14:42:43 +0100 Subject: [PATCH] Added: Static fps member to dolphin.cpp, auto-updated with engine->fps, made player movement multiplied by deltatime of last frame. --- src/samples/dolphin/dolphin.cpp | 5 ++++- src/samples/dolphin/dolphin.hpp | 1 + src/samples/dolphin/objects/player.cpp | 5 ++++- 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/samples/dolphin/dolphin.cpp b/src/samples/dolphin/dolphin.cpp index 704a04b..32f0175 100755 --- a/src/samples/dolphin/dolphin.cpp +++ b/src/samples/dolphin/dolphin.cpp @@ -16,6 +16,8 @@ const u8 WATER_SIZE = 100; const u8 OYSTERS_COUNT = 15; +float Dolphin::engineFPS = 60.F; + Dolphin::Dolphin(Engine *t_engine) : engine(t_engine), camera(&engine->screen) { oysters = new Collectible[OYSTERS_COUNT]; @@ -93,8 +95,9 @@ void Dolphin::onInit() void Dolphin::onUpdate() { + Dolphin::engineFPS = engine->fps; if (engine->pad.isCrossClicked) - printf("PlayerPos (%f,%f), FPS:%f\n", player.mesh.position.x, player.mesh.position.z, this->engine->fps); + printf("Delta multiplier: %f\n", 60.0F / engine->fps); float xDist = player.mesh.position.x - water.position.x; float zDist = player.mesh.position.z - water.position.z; diff --git a/src/samples/dolphin/dolphin.hpp b/src/samples/dolphin/dolphin.hpp index 9630f5e..273f0ef 100755 --- a/src/samples/dolphin/dolphin.hpp +++ b/src/samples/dolphin/dolphin.hpp @@ -33,6 +33,7 @@ public: void onUpdate(); Engine *engine; + static float engineFPS; private: LightBulb bulb; diff --git a/src/samples/dolphin/objects/player.cpp b/src/samples/dolphin/objects/player.cpp index aafe048..8051b55 100755 --- a/src/samples/dolphin/objects/player.cpp +++ b/src/samples/dolphin/objects/player.cpp @@ -9,6 +9,7 @@ */ #include "player.hpp" +#include "dolphin.hpp" #include #include @@ -38,7 +39,6 @@ void Player::update(Pad &t_pad) lift += 0.05F; if (lift < 0.1F && lift > -0.1F) lift = 0; - velocity = 0; if (t_pad.lJoyV <= 100) velocity = 1; else if (t_pad.lJoyV >= 200) @@ -81,9 +81,12 @@ void Player::update(Pad &t_pad) mesh.playAnimation(1, 14, 0); } + velocity *= 60.0F / Dolphin::engineFPS; //Moving by deltatime of last frame. mesh.position.z += Math::cos(mesh.rotation.z) * velocity * (bIsJumping + 1); mesh.position.x += Math::sin(mesh.rotation.z) * velocity * (bIsJumping + 1); mesh.position.y += lift; + + velocity = 0; }