mirror of
https://github.com/NickTheFox99/ChristmOS.git
synced 2026-06-22 06:15:59 -04:00
Begin work on lights
This commit is contained in:
@@ -8,6 +8,10 @@ const int WIN_WIDTH = 1280;
|
|||||||
const int WIN_HEIGHT = 720;
|
const int WIN_HEIGHT = 720;
|
||||||
|
|
||||||
namespace Snow {
|
namespace Snow {
|
||||||
const int MAX_SECS = 4;
|
const int MAX_CYCLE_FRAMES = 4;
|
||||||
const int INV_CHANCE = 5;
|
const int INV_HORMOVE_CHANCE = 5;
|
||||||
} // namespace Snow
|
} // namespace Snow
|
||||||
|
|
||||||
|
namespace Lights {
|
||||||
|
const int MAX_CYCLE_FRAMES = 30;
|
||||||
|
}
|
||||||
|
|||||||
21
src/lights/light.cpp
Normal file
21
src/lights/light.cpp
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
#include "light.h"
|
||||||
|
#include "../consts.cpp"
|
||||||
|
#include "Vector2.hpp"
|
||||||
|
|
||||||
|
namespace Lights {
|
||||||
|
Light::Light(raylib::Vector2 position, raylib::Color color1,
|
||||||
|
raylib::Color color2, int radius, LightState startingState,
|
||||||
|
int startingCycle)
|
||||||
|
: position(position), radius(radius), color1(color1), color2(color2),
|
||||||
|
state(startingState), cycle(startingCycle) {};
|
||||||
|
|
||||||
|
void Light::Update() {
|
||||||
|
cycle++;
|
||||||
|
if (cycle >= MAX_CYCLE_FRAMES)
|
||||||
|
SwitchState();
|
||||||
|
}
|
||||||
|
|
||||||
|
void Light::SwitchState() {
|
||||||
|
switch (state) { case Lights::LightState::color1: }
|
||||||
|
}
|
||||||
|
} // namespace Lights
|
||||||
29
src/lights/light.h
Normal file
29
src/lights/light.h
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
#include "Color.hpp"
|
||||||
|
#include "Vector2.hpp"
|
||||||
|
namespace Lights {
|
||||||
|
enum LightState {
|
||||||
|
color1,
|
||||||
|
color2,
|
||||||
|
};
|
||||||
|
|
||||||
|
class Light {
|
||||||
|
public:
|
||||||
|
Light(raylib::Vector2 position, raylib::Color color1, raylib::Color color2,
|
||||||
|
int radius, LightState startingState, int startingCycle);
|
||||||
|
|
||||||
|
void Update();
|
||||||
|
void Draw();
|
||||||
|
|
||||||
|
~Light();
|
||||||
|
|
||||||
|
private:
|
||||||
|
void SwitchState();
|
||||||
|
|
||||||
|
raylib::Vector2 position;
|
||||||
|
int radius;
|
||||||
|
raylib::Color color1;
|
||||||
|
raylib::Color color2;
|
||||||
|
LightState state;
|
||||||
|
int cycle;
|
||||||
|
};
|
||||||
|
} // namespace Lights
|
||||||
@@ -6,7 +6,7 @@ namespace Snow {
|
|||||||
Manager::Manager() = default;
|
Manager::Manager() = default;
|
||||||
Manager::~Manager() = default;
|
Manager::~Manager() = default;
|
||||||
|
|
||||||
void Manager::NewSnow() { snows.emplace_back(new Snow()); }
|
void Manager::NewSnow() { snows.emplace_back(new Snowflake()); }
|
||||||
void Manager::NewSnows(int count) {
|
void Manager::NewSnows(int count) {
|
||||||
snows.reserve(snows.size() + count);
|
snows.reserve(snows.size() + count);
|
||||||
for (int i = 0; i < count; i++)
|
for (int i = 0; i < count; i++)
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ public:
|
|||||||
~Manager();
|
~Manager();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::vector<std::unique_ptr<Snow>> snows;
|
std::vector<std::unique_ptr<Snowflake>> snows;
|
||||||
void Kill(int pos);
|
void Kill(int pos);
|
||||||
int frames = 0;
|
int frames = 0;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -5,13 +5,13 @@
|
|||||||
#include <raylib.h>
|
#include <raylib.h>
|
||||||
|
|
||||||
namespace Snow {
|
namespace Snow {
|
||||||
Snow::Snow() : Snow(GetRandomValue(0, 320)) {}
|
Snowflake::Snowflake() : Snowflake(GetRandomValue(0, 320)) {}
|
||||||
Snow::Snow(int x) : Snow(raylib::Vector2(x, 0)) {}
|
Snowflake::Snowflake(int x) : Snowflake(raylib::Vector2(x, 0)) {}
|
||||||
Snow::Snow(raylib::Vector2 pos) : position(pos) {}
|
Snowflake::Snowflake(raylib::Vector2 pos) : position(pos) {}
|
||||||
|
|
||||||
void Snow::Move() {
|
void Snowflake::Move() {
|
||||||
raylib::Vector2 move;
|
raylib::Vector2 move;
|
||||||
int hMove = GetRandomValue(0, INV_CHANCE);
|
int hMove = GetRandomValue(0, INV_HORMOVE_CHANCE);
|
||||||
if (hMove <= 1) {
|
if (hMove <= 1) {
|
||||||
hMove = hMove * 2 - 1;
|
hMove = hMove * 2 - 1;
|
||||||
} else {
|
} else {
|
||||||
@@ -22,16 +22,16 @@ void Snow::Move() {
|
|||||||
position += move;
|
position += move;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Snow::IsAlive() { return live; }
|
bool Snowflake::IsAlive() { return live; }
|
||||||
|
|
||||||
void Snow::CheckLive() {
|
void Snowflake::CheckLive() {
|
||||||
if (position.y >= SCREEN_HEIGHT) {
|
if (position.y >= SCREEN_HEIGHT) {
|
||||||
live = false;
|
live = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Snow::Update() {
|
void Snowflake::Update() {
|
||||||
if (currCycle >= MAX_SECS) {
|
if (currCycle >= MAX_CYCLE_FRAMES) {
|
||||||
Move();
|
Move();
|
||||||
CheckLive();
|
CheckLive();
|
||||||
currCycle = 0;
|
currCycle = 0;
|
||||||
@@ -40,7 +40,7 @@ void Snow::Update() {
|
|||||||
currCycle++;
|
currCycle++;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Snow::Draw() { raylib::Color::White().DrawPixel(position); }
|
void Snowflake::Draw() { raylib::Color::White().DrawPixel(position); }
|
||||||
|
|
||||||
Snow::~Snow() = default;
|
Snowflake::~Snowflake() = default;
|
||||||
} // namespace Snow
|
} // namespace Snow
|
||||||
|
|||||||
@@ -2,17 +2,17 @@
|
|||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
|
|
||||||
namespace Snow {
|
namespace Snow {
|
||||||
class Snow {
|
class Snowflake {
|
||||||
public:
|
public:
|
||||||
Snow();
|
Snowflake();
|
||||||
Snow(int x);
|
Snowflake(int x);
|
||||||
Snow(raylib::Vector2 pos);
|
Snowflake(raylib::Vector2 pos);
|
||||||
|
|
||||||
void Update();
|
void Update();
|
||||||
void Draw();
|
void Draw();
|
||||||
bool IsAlive();
|
bool IsAlive();
|
||||||
|
|
||||||
~Snow();
|
~Snowflake();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
raylib::Vector2 position;
|
raylib::Vector2 position;
|
||||||
|
|||||||
Reference in New Issue
Block a user