Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ set(SOURCES
src/Player.cpp
src/Platform.cpp
src/Bird.cpp
src/Cloud.cpp
src/Sign.cpp
)

set(HEADERS
Expand All @@ -22,6 +24,8 @@ set(HEADERS
src/Player.hpp
src/Platform.hpp
src/Bird.hpp
src/Cloud.hpp
src/Sign.hpp
src/Common.hpp
)

Expand Down
42 changes: 42 additions & 0 deletions src/Cloud.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#include "Cloud.hpp"
#include <SDL2/SDL.h>
#include <initializer_list>

Cloud::Cloud(float x, float y, float width, float height)
: GameObject(x, y, width, height, Color{255, 255, 255, 200}) { // white with some transparency
}

void Cloud::update(float deltaTime) {
// Move cloud slowly to the left
m_x -= m_speed * deltaTime;
// Reset cloud position if it goes off screen
if (m_x + m_width < 0) {
m_x = 1024; // screen width
}
}

void Cloud::render(SDL_Renderer* renderer) const {
// Render a simple cloud as a filled white ellipse or circle approximation
SDL_SetRenderDrawColor(renderer, m_color.r, m_color.g, m_color.b, m_color.a);
// Simple cloud: draw 3 overlapping circles
int centerX = static_cast<int>(m_x);
int centerY = static_cast<int>(m_y);
int radius = static_cast<int>(m_height / 2);

// Draw 3 circles for cloud shape
for (int dx : std::initializer_list<int>{-radius, 0, radius}) {
for (int dy : std::initializer_list<int>{-radius / 2, 0, radius / 2}) {
int cx = centerX + dx;
int cy = centerY + dy;
for (int w = 0; w < radius * 2; ++w) {
for (int h = 0; h < radius * 2; ++h) {
int distX = radius - w;
int distY = radius - h;
if ((distX * distX + distY * distY) <= (radius * radius)) {
SDL_RenderDrawPoint(renderer, cx + w - radius, cy + h - radius);
}
}
}
}
}
}
17 changes: 17 additions & 0 deletions src/Cloud.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#ifndef CLOUD_HPP
#define CLOUD_HPP

#include "GameObject.hpp"

class Cloud : public GameObject {
public:
Cloud(float x, float y, float width, float height);
void update(float deltaTime) override;
void render(SDL_Renderer* renderer) const override;
void setCameraOffset(float, float) override { /* Ignore camera movement */ }

private:
float m_speed = 20.0f; // pixels per second
};

#endif // CLOUD_HPP
Loading