feat: cactus class for drawing, updating and spawning the cacti on the desert

This commit is contained in:
theoleuthardt 2025-03-13 10:55:01 +01:00
parent 10194544f3
commit 9ff73a95e3
2 changed files with 41 additions and 0 deletions

22
src/Cactus.cpp Normal file
View file

@ -0,0 +1,22 @@
#include "Cactus.hpp"
Cactus::Cactus(Texture2D texture, float x) : texture(texture) {
rect = {static_cast<float>(x), static_cast<float>(300 - texture.height),
static_cast<float>(texture.width), static_cast<float>(texture.height)};
}
void Cactus::Update() {
rect.x -= SPEED;
}
void Cactus::Draw() {
DrawTexture(texture, rect.x, rect.y, WHITE);
}
bool Cactus::IsOffScreen() {
return rect.x + rect.width < 0;
}
Rectangle Cactus::GetRect() {
return rect;
}