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

View File

@@ -7,6 +7,10 @@ Manager::Manager() = default;
Manager::~Manager() = default;
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() {
for (auto snowi = 0; snowi < snows.size(); snowi++) {

View File

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

View File

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

View File

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