Add rudimentary implementation of Snow::Manager

This commit is contained in:
Maple Redleaf
2025-12-12 10:49:18 -06:00
parent fabf4ea2d1
commit 99f769a79b
7 changed files with 16 additions and 32 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 102 B

View File

@@ -6,3 +6,8 @@ const int SCREEN_HEIGHT = 240;
const int WIN_WIDTH = 1280; const int WIN_WIDTH = 1280;
const int WIN_HEIGHT = 720; const int WIN_HEIGHT = 720;
namespace Snow {
const int MAX_SECS = 4;
const int INV_CHANCE = 5;
} // namespace Snow

View File

@@ -1,6 +1,5 @@
#include "../data/cube.png.h"
#include "consts.cpp" #include "consts.cpp"
#include <cmath> #include "snow/manager.h"
#include <raylib-cpp.hpp> #include <raylib-cpp.hpp>
#include <raylib.h> #include <raylib.h>
@@ -18,25 +17,14 @@ raylib::Window window(WIN_WIDTH, WIN_HEIGHT, "game",
raylib::RenderTexture2D target(SCREEN_WIDTH, SCREEN_HEIGHT); raylib::RenderTexture2D target(SCREEN_WIDTH, SCREEN_HEIGHT);
raylib::Image texImg = Snow::Manager sMgr = Snow::Manager();
raylib::LoadImageFromMemory(".png", cube_png, cube_png_len);
raylib::Texture2D texture = texImg.LoadTexture();
raylib::Camera3D cam(raylib::Vector3(0.0f, 0.0f, std::sqrt(3.0f)),
raylib::Vector3::Zero(), raylib::Vector3(0.0f, 1.0f, 0.0f),
60.0f, CAMERA_PERSPECTIVE);
raylib::Model cube(GenMeshCube(1.0f, 1.0f, 1.0f));
int main(void) { int main(void) {
window.SetMinSize({320, 240}); window.SetMinSize({320, 240});
window.SetTargetFPS(60); window.SetTargetFPS(60);
window.SetExitKey(KEY_BACKSPACE); window.SetExitKey(KEY_BACKSPACE);
target.GetTexture().SetFilter(TEXTURE_FILTER_POINT); sMgr.NewSnows(10);
cube.materials[0].maps[MATERIAL_MAP_ALBEDO].texture = texture;
#if defined(PLATFORM_WEB) #if defined(PLATFORM_WEB)
emscripten_set_main_loop(MainLoop, 0, 1); emscripten_set_main_loop(MainLoop, 0, 1);
@@ -56,21 +44,12 @@ void MainLoop() {
float scale = float scale =
MIN((float)winWidth / SCREEN_WIDTH, (float)winHeight / SCREEN_HEIGHT); MIN((float)winWidth / SCREEN_WIDTH, (float)winHeight / SCREEN_HEIGHT);
cube.SetTransform( sMgr.Update();
raylib::Matrix::RotateXYZ(
raylib::Vector3(1.0f, 1.5f, 2.5f).Scale(window.GetFrameTime()))
.Multiply(cube.GetTransform()));
target.BeginMode(); target.BeginMode();
{ {
ClearBackground(BLACK); ClearBackground(BLACK);
raylib::Vector2(160.0f, 120.0f) sMgr.Draw();
.DrawCircle(120.0f, raylib::Color::White());
cam.BeginMode();
{
cube.Draw(raylib::Vector3::Zero());
}
cam.EndMode();
} }
target.EndMode(); target.EndMode();

View File

@@ -7,6 +7,10 @@ Manager::Manager() = default;
Manager::~Manager() = default; Manager::~Manager() = default;
void Manager::NewSnow() { snows.push_back(std::make_unique<Snow>()); } void Manager::NewSnow() { snows.push_back(std::make_unique<Snow>()); }
void Manager::NewSnows(int snows) {
for (int i = 0; i < snows; i++)
NewSnow();
}
void Manager::Update() { void Manager::Update() {
for (auto snowi = 0; snowi < snows.size(); snowi++) { for (auto snowi = 0; snowi < snows.size(); snowi++) {

View File

@@ -6,6 +6,7 @@ namespace Snow {
class Manager { class Manager {
public: public:
Manager(); Manager();
void NewSnows(int snows);
void NewSnow(); void NewSnow();
void Update(); void Update();
void Draw(); void Draw();

View File

@@ -4,16 +4,12 @@
#include "Vector2.hpp" #include "Vector2.hpp"
#include <raylib.h> #include <raylib.h>
#define MAX_SECS 4
#define INV_CHANCE 5
namespace Snow { namespace Snow {
Snow::Snow() { Snow(GetRandomValue(0, 320)); } Snow::Snow() { Snow(GetRandomValue(0, 320)); }
Snow::Snow(uint x) { Snow(raylib::Vector2(x, 0)); } Snow::Snow(uint x) { Snow(raylib::Vector2(x, 0)); }
Snow::Snow(raylib::Vector2 pos) { Snow::Snow(raylib::Vector2 pos) {
position = pos; position = pos;
currCycle = 0; currCycle = 0;
maxCycle = MAX_SECS;
live = true; live = true;
} }
@@ -38,7 +34,7 @@ void Snow::CheckLive() {
} }
void Snow::Update() { void Snow::Update() {
if (currCycle >= maxCycle) { if (currCycle >= MAX_SECS) {
Move(); Move();
CheckLive(); CheckLive();
currCycle = 0; currCycle = 0;

View File

@@ -17,7 +17,6 @@ public:
private: private:
raylib::Vector2 position; raylib::Vector2 position;
uint currCycle; uint currCycle;
uint maxCycle;
bool live; bool live;
inline void Move(); inline void Move();