mirror of
https://github.com/NickTheFox99/ChristmOS.git
synced 2026-06-28 16:55:11 -04:00
Add individual snow code (not implemented)
This commit is contained in:
8
src/consts.cpp
Normal file
8
src/consts.cpp
Normal 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;
|
||||
@@ -1,17 +1,13 @@
|
||||
#include "../data/cube.png.h"
|
||||
#include "raylib.h"
|
||||
#include "consts.cpp"
|
||||
#include <cmath>
|
||||
#include <raylib-cpp.hpp>
|
||||
#include <raylib.h>
|
||||
|
||||
#if defined(PLATFORM_WEB)
|
||||
#include <emscripten/emscripten.h>
|
||||
#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 MIN(a, b) ((a) < (b) ? (a) : (b))
|
||||
|
||||
|
||||
49
src/snow/snow.cpp
Normal file
49
src/snow/snow.cpp
Normal 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
23
src/snow/snow.h
Normal 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();
|
||||
};
|
||||
Reference in New Issue
Block a user