mirror of
https://github.com/theoleuthardt/DinoGame.git
synced 2026-06-13 09:27:57 +00:00
feat: cactus class for drawing, updating and spawning the cacti on the desert
This commit is contained in:
parent
10194544f3
commit
9ff73a95e3
2 changed files with 41 additions and 0 deletions
22
src/Cactus.cpp
Normal file
22
src/Cactus.cpp
Normal 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;
|
||||||
|
}
|
||||||
19
src/Cactus.hpp
Normal file
19
src/Cactus.hpp
Normal file
|
|
@ -0,0 +1,19 @@
|
||||||
|
#ifndef CACTUS_H
|
||||||
|
#define CACTUS_H
|
||||||
|
#include "raylib.h"
|
||||||
|
|
||||||
|
class Cactus {
|
||||||
|
public:
|
||||||
|
Cactus(Texture2D texture, float x);
|
||||||
|
void Update();
|
||||||
|
void Draw();
|
||||||
|
bool IsOffScreen();
|
||||||
|
Rectangle GetRect();
|
||||||
|
|
||||||
|
private:
|
||||||
|
Texture2D texture;
|
||||||
|
Rectangle rect;
|
||||||
|
static constexpr float SPEED = 5;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
Loading…
Add table
Add a link
Reference in a new issue