fix: y position of dino and cacti now on the desert

This commit is contained in:
theoleuthardt 2025-03-13 13:46:12 +01:00
parent c7554cbb81
commit 8dd09555f2
3 changed files with 7 additions and 5 deletions

View file

@ -1,7 +1,7 @@
#include "Cactus.hpp" #include "Cactus.hpp"
Cactus::Cactus(Texture2D texture, float x, float y) : texture(texture) { Cactus::Cactus(Texture2D texture, float x, float y) : texture(texture) {
rect = {static_cast<float>(x), static_cast<float>(300 - texture.height), rect = {static_cast<float>(x), static_cast<float>(320 - texture.height),
static_cast<float>(texture.width), static_cast<float>(texture.height)}; static_cast<float>(texture.width), static_cast<float>(texture.height)};
} }

View file

@ -1,7 +1,7 @@
#include "Dino.hpp" #include "Dino.hpp"
Dino::Dino(Texture2D tex) : texture(tex), velocityY(0), isJumping(false) { Dino::Dino(Texture2D texture) : texture(texture), velocityY(0), isJumping(false) {
rect = {50.0f, static_cast<float>(330 - texture.height), rect = {50.0f, static_cast<float>(320 - texture.height),
static_cast<float>(texture.width), static_cast<float>(texture.height)}; static_cast<float>(texture.width), static_cast<float>(texture.height)};
} }
@ -16,8 +16,9 @@ void Dino::Update() {
velocityY += GRAVITY; velocityY += GRAVITY;
rect.y += velocityY; rect.y += velocityY;
if (rect.y >= 300 - rect.height) { if (rect.y >= groundLevel - rect.height) {
rect.y = 300 - rect.height; rect.y = groundLevel - rect.height;
velocityY = 0;
isJumping = false; isJumping = false;
} }
} }

View file

@ -17,6 +17,7 @@ private:
bool isJumping; bool isJumping;
static constexpr float GRAVITY = 0.4; static constexpr float GRAVITY = 0.4;
static constexpr float JUMP_STRENGTH = -10; static constexpr float JUMP_STRENGTH = -10;
int groundLevel = 320;
}; };
#endif //DINO_HPP #endif //DINO_HPP