mirror of
https://github.com/NickTheFox99/ChristmOS.git
synced 2026-05-25 04:10:53 -04:00
Compare commits
6 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6b1e840810 | ||
|
|
5f079d45a3 | ||
|
|
992907dfad | ||
|
|
61168bee04 | ||
|
|
fd7d44e2ce | ||
|
|
f01cbc782f |
BIN
assets/tree.png
Normal file
BIN
assets/tree.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 4.2 KiB |
@@ -1,13 +1,31 @@
|
|||||||
|
#include "Color.hpp"
|
||||||
|
#include <array>
|
||||||
|
#include <raylib.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
|
|
||||||
// SCREEN CONSTS
|
// SCREEN CONSTS
|
||||||
const int SCREEN_WIDTH = 320;
|
const int SCREEN_WIDTH = 80;
|
||||||
const int SCREEN_HEIGHT = 240;
|
const int SCREEN_HEIGHT = 60;
|
||||||
|
|
||||||
const int WIN_WIDTH = 1280;
|
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;
|
||||||
|
const std::array<Vector2, 9> POSITIONS{{{28, 17},
|
||||||
|
{36, 15},
|
||||||
|
{49, 16},
|
||||||
|
{22, 31},
|
||||||
|
{34, 31},
|
||||||
|
{61, 30},
|
||||||
|
{59, 42},
|
||||||
|
{28, 28},
|
||||||
|
{47, 29}}};
|
||||||
|
const raylib::Color col1 = raylib::Color::Green();
|
||||||
|
const raylib::Color col2 = raylib::Color::Red();
|
||||||
|
} // namespace Lights
|
||||||
|
|||||||
38
src/lights/light.cpp
Normal file
38
src/lights/light.cpp
Normal file
@@ -0,0 +1,38 @@
|
|||||||
|
#include "light.h"
|
||||||
|
#include "../consts.cpp"
|
||||||
|
#include "Vector2.hpp"
|
||||||
|
#include "raylib.h"
|
||||||
|
#include <cstdio>
|
||||||
|
|
||||||
|
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) {};
|
||||||
|
Light::~Light() = default;
|
||||||
|
|
||||||
|
void Light::Update() {
|
||||||
|
cycle++;
|
||||||
|
if (cycle >= MAX_CYCLE_FRAMES) {
|
||||||
|
SwitchState();
|
||||||
|
cycle = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Light::Draw() {
|
||||||
|
raylib::Color col = (state == Lights::LightState::color1) ? color1 : color2;
|
||||||
|
DrawCircleV(position, radius + 1, col.Alpha(0.5));
|
||||||
|
DrawCircleV(position, radius, col);
|
||||||
|
}
|
||||||
|
|
||||||
|
Lights::LightState Light::SwitchState() {
|
||||||
|
switch (state) {
|
||||||
|
case Lights::LightState::color1:
|
||||||
|
return state = Lights::LightState::color2;
|
||||||
|
case Lights::LightState::color2:
|
||||||
|
return state = Lights::LightState::color1;
|
||||||
|
}
|
||||||
|
return state;
|
||||||
|
}
|
||||||
|
} // 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:
|
||||||
|
LightState SwitchState();
|
||||||
|
|
||||||
|
raylib::Vector2 position;
|
||||||
|
int radius;
|
||||||
|
raylib::Color color1;
|
||||||
|
raylib::Color color2;
|
||||||
|
LightState state;
|
||||||
|
int cycle;
|
||||||
|
};
|
||||||
|
} // namespace Lights
|
||||||
31
src/lights/manager.cpp
Normal file
31
src/lights/manager.cpp
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
#include "manager.h"
|
||||||
|
#include "../consts.cpp"
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
|
namespace Lights {
|
||||||
|
|
||||||
|
Manager::Manager() {
|
||||||
|
int cycle = 0;
|
||||||
|
lights.reserve(POSITIONS.size());
|
||||||
|
for (const auto &position : POSITIONS) {
|
||||||
|
lights.emplace_back(new Light(
|
||||||
|
position, col1, col2, 2,
|
||||||
|
(cycle % 2 == 0) ? LightState::color1 : LightState::color2, 0));
|
||||||
|
cycle++;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
Manager::~Manager() = default;
|
||||||
|
|
||||||
|
void Manager::Update() {
|
||||||
|
for (auto lighti = 0; lighti < lights.size(); lighti++) {
|
||||||
|
auto &light = lights[lighti];
|
||||||
|
light->Update();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Manager::Draw() {
|
||||||
|
for (auto lighti = 0; lighti < lights.size(); lighti++)
|
||||||
|
lights[lighti]->Draw();
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace Lights
|
||||||
16
src/lights/manager.h
Normal file
16
src/lights/manager.h
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
#include "light.h"
|
||||||
|
#include <memory>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
namespace Lights {
|
||||||
|
class Manager {
|
||||||
|
public:
|
||||||
|
Manager();
|
||||||
|
void Update();
|
||||||
|
void Draw();
|
||||||
|
~Manager();
|
||||||
|
|
||||||
|
private:
|
||||||
|
std::vector<std::unique_ptr<Light>> lights;
|
||||||
|
};
|
||||||
|
} // namespace Lights
|
||||||
19
src/main.cpp
19
src/main.cpp
@@ -1,4 +1,8 @@
|
|||||||
|
#include "../data/tree.png.h"
|
||||||
|
#include "Functions.hpp"
|
||||||
|
#include "Vector2.hpp"
|
||||||
#include "consts.cpp"
|
#include "consts.cpp"
|
||||||
|
#include "lights/manager.h"
|
||||||
#include "snow/manager.h"
|
#include "snow/manager.h"
|
||||||
#include <raylib-cpp.hpp>
|
#include <raylib-cpp.hpp>
|
||||||
#include <raylib.h>
|
#include <raylib.h>
|
||||||
@@ -17,13 +21,21 @@ raylib::Window window(WIN_WIDTH, WIN_HEIGHT, "game",
|
|||||||
|
|
||||||
raylib::RenderTexture2D target(SCREEN_WIDTH, SCREEN_HEIGHT);
|
raylib::RenderTexture2D target(SCREEN_WIDTH, SCREEN_HEIGHT);
|
||||||
|
|
||||||
|
raylib::Image treeImg =
|
||||||
|
raylib::LoadImageFromMemory(".png", tree_png, tree_png_len);
|
||||||
|
|
||||||
|
raylib::Texture2D tree = treeImg.LoadTexture();
|
||||||
|
|
||||||
Snow::Manager sMgr;
|
Snow::Manager sMgr;
|
||||||
|
Lights::Manager lMgr;
|
||||||
|
|
||||||
int main(void) {
|
int main(void) {
|
||||||
window.SetMinSize({320, 240});
|
window.SetMinSize({SCREEN_WIDTH, SCREEN_HEIGHT});
|
||||||
window.SetTargetFPS(60);
|
window.SetTargetFPS(60);
|
||||||
window.SetExitKey(KEY_BACKSPACE);
|
window.SetExitKey(KEY_BACKSPACE);
|
||||||
|
|
||||||
|
tree.SetFilter(TEXTURE_FILTER_POINT);
|
||||||
|
|
||||||
#if defined(PLATFORM_WEB)
|
#if defined(PLATFORM_WEB)
|
||||||
emscripten_set_main_loop(MainLoop, 0, 1);
|
emscripten_set_main_loop(MainLoop, 0, 1);
|
||||||
#else
|
#else
|
||||||
@@ -43,10 +55,13 @@ void MainLoop() {
|
|||||||
MIN((float)winWidth / SCREEN_WIDTH, (float)winHeight / SCREEN_HEIGHT);
|
MIN((float)winWidth / SCREEN_WIDTH, (float)winHeight / SCREEN_HEIGHT);
|
||||||
|
|
||||||
sMgr.Update();
|
sMgr.Update();
|
||||||
|
lMgr.Update();
|
||||||
|
|
||||||
target.BeginMode();
|
target.BeginMode();
|
||||||
{
|
{
|
||||||
ClearBackground(BLACK);
|
// ClearBackground(BLACK);
|
||||||
|
DrawTexture(tree, 0, 0, raylib::Color::White());
|
||||||
|
lMgr.Draw();
|
||||||
sMgr.Draw();
|
sMgr.Draw();
|
||||||
}
|
}
|
||||||
target.EndMode();
|
target.EndMode();
|
||||||
|
|||||||
@@ -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