Add individual snow code (not implemented)

This commit is contained in:
Maple Redleaf
2025-12-11 13:53:53 -06:00
parent 9a78a8706d
commit 11d9cedb27
4 changed files with 82 additions and 6 deletions

8
src/consts.cpp Normal file
View File

@@ -0,0 +1,8 @@
#include <sys/types.h>
// SCREEN CONSTS
const uint SCREEN_WIDTH = 320;
const uint SCREEN_HEIGHT = 240;
const uint WIN_WIDTH = 1280;
const uint WIN_HEIGHT = 720;

View File

@@ -1,17 +1,13 @@
#include "../data/cube.png.h" #include "../data/cube.png.h"
#include "raylib.h" #include "consts.cpp"
#include <cmath> #include <cmath>
#include <raylib-cpp.hpp> #include <raylib-cpp.hpp>
#include <raylib.h>
#if defined(PLATFORM_WEB) #if defined(PLATFORM_WEB)
#include <emscripten/emscripten.h> #include <emscripten/emscripten.h>
#endif #endif
#define SCREEN_WIDTH (320)
#define SCREEN_HEIGHT (240)
#define WIN_WIDTH (1280)
#define WIN_HEIGHT (720)
#define MAX(a, b) ((a) > (b) ? (a) : (b)) #define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) < (b) ? (a) : (b)) #define MIN(a, b) ((a) < (b) ? (a) : (b))

49
src/snow/snow.cpp Normal file
View File

@@ -0,0 +1,49 @@
#include "snow.h"
#include "Color.hpp"
#include "Vector2.hpp"
#include "consts.cpp"
#include <raylib.h>
#define MAX_SECS 4
#define INV_CHANCE 5
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;
}
void Snow::Move() {
raylib::Vector2 move;
uint hMove = GetRandomValue(0, INV_CHANCE);
if (hMove <= 1) {
hMove = hMove * 2 - 1;
} else {
hMove = 0;
}
move.x = hMove;
move.y = 1;
position += move;
}
void Snow::CheckLive() {
if (position.y >= SCREEN_HEIGHT)
live = false;
}
void Snow::Update() {
if (currCycle >= maxCycle) {
Move();
CheckLive();
currCycle = 0;
return;
}
currCycle++;
}
void Snow::Draw() { raylib::Color::White().DrawPixel(position); }
Snow::~Snow() = default;

23
src/snow/snow.h Normal file
View File

@@ -0,0 +1,23 @@
#include <raylib-cpp.hpp>
#include <sys/types.h>
class Snow {
public:
Snow();
Snow(uint x);
Snow(raylib::Vector2 pos);
void Update();
void Draw();
~Snow();
private:
raylib::Vector2 position;
uint currCycle;
uint maxCycle;
bool live;
inline void Move();
inline void CheckLive();
};