mirror of
https://github.com/NickTheFox99/ChristmOS.git
synced 2026-06-13 19:35:10 -04:00
Compare commits
18 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6b1e840810 | ||
|
|
5f079d45a3 | ||
|
|
992907dfad | ||
|
|
61168bee04 | ||
|
|
fd7d44e2ce | ||
|
|
f01cbc782f | ||
|
|
5e2451459c | ||
|
|
b2d7d71c80 | ||
|
|
cf602bb513 | ||
|
|
2c15d64ab3 | ||
|
|
795b54a90a | ||
|
|
99f769a79b | ||
|
|
fabf4ea2d1 | ||
|
|
588d921553 | ||
|
|
9f4b0015aa | ||
|
|
85bfe365ce | ||
|
|
e8e6768ca4 | ||
|
|
11d9cedb27 |
@@ -7,8 +7,9 @@ set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
|
|||||||
# Dependencies
|
# Dependencies
|
||||||
set(RAYLIB_VERSION 5.5)
|
set(RAYLIB_VERSION 5.5)
|
||||||
find_package(raylib ${RAYLIB_VERSION} QUIET) # QUIET or REQUIRED
|
find_package(raylib ${RAYLIB_VERSION} QUIET) # QUIET or REQUIRED
|
||||||
if(NOT raylib_FOUND) # If there's none, fetch and build raylib
|
|
||||||
include(FetchContent)
|
include(FetchContent)
|
||||||
|
set(FETCHCONTENT_QUIET NO)
|
||||||
|
if(NOT raylib_DIR) # If there's none, fetch and build raylib
|
||||||
FetchContent_Declare(
|
FetchContent_Declare(
|
||||||
raylib
|
raylib
|
||||||
DOWNLOAD_EXTRACT_TIMESTAMP OFF
|
DOWNLOAD_EXTRACT_TIMESTAMP OFF
|
||||||
@@ -16,26 +17,16 @@ if(NOT raylib_FOUND) # If there's none, fetch and build raylib
|
|||||||
)
|
)
|
||||||
FetchContent_GetProperties(raylib)
|
FetchContent_GetProperties(raylib)
|
||||||
if(NOT raylib_POPULATED) # Have we downloaded raylib yet?
|
if(NOT raylib_POPULATED) # Have we downloaded raylib yet?
|
||||||
set(FETCHCONTENT_QUIET NO)
|
|
||||||
FetchContent_MakeAvailable(raylib)
|
FetchContent_MakeAvailable(raylib)
|
||||||
endif()
|
endif()
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
set(RAYLIB_CPP_VERSION "v5.5.0")
|
|
||||||
find_package(raylib_cpp QUIET) # QUIET or REQUIRED
|
|
||||||
if(NOT raylib_cpp_FOUND) # If there's none, fetch and build raylib
|
|
||||||
include(FetchContent)
|
|
||||||
FetchContent_Declare(
|
FetchContent_Declare(
|
||||||
raylib_cpp
|
raylib_cpp
|
||||||
DOWNLOAD_EXTRACT_TIMESTAMP OFF
|
GIT_REPOSITORY https://github.com/RobLoach/raylib-cpp.git
|
||||||
URL https://github.com/RobLoach/raylib-cpp/archive/refs/tags/${RAYLIB_CPP_VERSION}.tar.gz
|
GIT_TAG master
|
||||||
)
|
)
|
||||||
FetchContent_GetProperties(raylib_cpp)
|
|
||||||
if(NOT raylib_cpp_POPULATED) # Have we downloaded raylib yet?
|
|
||||||
set(FETCHCONTENT_QUIET NO)
|
|
||||||
FetchContent_MakeAvailable(raylib_cpp)
|
FetchContent_MakeAvailable(raylib_cpp)
|
||||||
endif()
|
|
||||||
endif()
|
|
||||||
|
|
||||||
# Our Project
|
# Our Project
|
||||||
add_executable(${PROJECT_NAME})
|
add_executable(${PROJECT_NAME})
|
||||||
|
|||||||
BIN
assets/cube.png
BIN
assets/cube.png
Binary file not shown.
|
Before Width: | Height: | Size: 102 B |
BIN
assets/tree.png
Normal file
BIN
assets/tree.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 4.2 KiB |
31
src/consts.cpp
Normal file
31
src/consts.cpp
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
#include "Color.hpp"
|
||||||
|
#include <array>
|
||||||
|
#include <raylib.h>
|
||||||
|
#include <sys/types.h>
|
||||||
|
|
||||||
|
// SCREEN CONSTS
|
||||||
|
const int SCREEN_WIDTH = 80;
|
||||||
|
const int SCREEN_HEIGHT = 60;
|
||||||
|
|
||||||
|
const int WIN_WIDTH = 1280;
|
||||||
|
const int WIN_HEIGHT = 720;
|
||||||
|
|
||||||
|
namespace Snow {
|
||||||
|
const int MAX_CYCLE_FRAMES = 4;
|
||||||
|
const int INV_HORMOVE_CHANCE = 5;
|
||||||
|
} // 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
|
||||||
52
src/main.cpp
52
src/main.cpp
@@ -1,17 +1,16 @@
|
|||||||
#include "../data/cube.png.h"
|
#include "../data/tree.png.h"
|
||||||
#include "raylib.h"
|
#include "Functions.hpp"
|
||||||
#include <cmath>
|
#include "Vector2.hpp"
|
||||||
|
#include "consts.cpp"
|
||||||
|
#include "lights/manager.h"
|
||||||
|
#include "snow/manager.h"
|
||||||
#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))
|
||||||
|
|
||||||
@@ -22,25 +21,20 @@ raylib::Window window(WIN_WIDTH, WIN_HEIGHT, "game",
|
|||||||
|
|
||||||
raylib::RenderTexture2D target(SCREEN_WIDTH, SCREEN_HEIGHT);
|
raylib::RenderTexture2D target(SCREEN_WIDTH, SCREEN_HEIGHT);
|
||||||
|
|
||||||
raylib::Image texImg =
|
raylib::Image treeImg =
|
||||||
raylib::LoadImageFromMemory(".png", cube_png, cube_png_len);
|
raylib::LoadImageFromMemory(".png", tree_png, tree_png_len);
|
||||||
|
|
||||||
raylib::Texture2D texture = texImg.LoadTexture();
|
raylib::Texture2D tree = treeImg.LoadTexture();
|
||||||
|
|
||||||
raylib::Camera3D cam(raylib::Vector3(0.0f, 0.0f, std::sqrt(3.0f)),
|
Snow::Manager sMgr;
|
||||||
raylib::Vector3::Zero(), raylib::Vector3(0.0f, 1.0f, 0.0f),
|
Lights::Manager lMgr;
|
||||||
60.0f, CAMERA_PERSPECTIVE);
|
|
||||||
|
|
||||||
raylib::Model cube(GenMeshCube(1.0f, 1.0f, 1.0f));
|
|
||||||
|
|
||||||
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);
|
||||||
|
|
||||||
target.GetTexture().SetFilter(TEXTURE_FILTER_POINT);
|
tree.SetFilter(TEXTURE_FILTER_POINT);
|
||||||
|
|
||||||
cube.materials[0].maps[MATERIAL_MAP_ALBEDO].texture = texture;
|
|
||||||
|
|
||||||
#if defined(PLATFORM_WEB)
|
#if defined(PLATFORM_WEB)
|
||||||
emscripten_set_main_loop(MainLoop, 0, 1);
|
emscripten_set_main_loop(MainLoop, 0, 1);
|
||||||
@@ -60,21 +54,15 @@ void MainLoop() {
|
|||||||
float scale =
|
float scale =
|
||||||
MIN((float)winWidth / SCREEN_WIDTH, (float)winHeight / SCREEN_HEIGHT);
|
MIN((float)winWidth / SCREEN_WIDTH, (float)winHeight / SCREEN_HEIGHT);
|
||||||
|
|
||||||
cube.SetTransform(
|
sMgr.Update();
|
||||||
raylib::Matrix::RotateXYZ(
|
lMgr.Update();
|
||||||
raylib::Vector3(1.0f, 1.5f, 2.5f).Scale(window.GetFrameTime()))
|
|
||||||
.Multiply(cube.GetTransform()));
|
|
||||||
|
|
||||||
target.BeginMode();
|
target.BeginMode();
|
||||||
{
|
{
|
||||||
ClearBackground(BLACK);
|
// ClearBackground(BLACK);
|
||||||
raylib::Vector2(160.0f, 120.0f)
|
DrawTexture(tree, 0, 0, raylib::Color::White());
|
||||||
.DrawCircle(120.0f, raylib::Color::White());
|
lMgr.Draw();
|
||||||
cam.BeginMode();
|
sMgr.Draw();
|
||||||
{
|
|
||||||
cube.Draw(raylib::Vector3::Zero());
|
|
||||||
}
|
|
||||||
cam.EndMode();
|
|
||||||
}
|
}
|
||||||
target.EndMode();
|
target.EndMode();
|
||||||
|
|
||||||
|
|||||||
40
src/snow/manager.cpp
Normal file
40
src/snow/manager.cpp
Normal file
@@ -0,0 +1,40 @@
|
|||||||
|
#include "manager.h"
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
|
namespace Snow {
|
||||||
|
|
||||||
|
Manager::Manager() = default;
|
||||||
|
Manager::~Manager() = default;
|
||||||
|
|
||||||
|
void Manager::NewSnow() { snows.emplace_back(new Snowflake()); }
|
||||||
|
void Manager::NewSnows(int count) {
|
||||||
|
snows.reserve(snows.size() + count);
|
||||||
|
for (int i = 0; i < count; i++)
|
||||||
|
NewSnow();
|
||||||
|
}
|
||||||
|
|
||||||
|
void Manager::Update() {
|
||||||
|
frames++;
|
||||||
|
if (frames % 2 == 1)
|
||||||
|
NewSnow();
|
||||||
|
for (auto snowi = 0; snowi < snows.size(); snowi++) {
|
||||||
|
auto &snow = snows[snowi];
|
||||||
|
if (!snow->IsAlive()) {
|
||||||
|
Kill(snowi);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
snow->Update();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Manager::Draw() {
|
||||||
|
for (auto snowi = 0; snowi < snows.size(); snowi++)
|
||||||
|
snows[snowi]->Draw();
|
||||||
|
}
|
||||||
|
|
||||||
|
void Manager::Kill(int pos) {
|
||||||
|
std::swap(snows[pos], snows.back());
|
||||||
|
snows.pop_back();
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace Snow
|
||||||
20
src/snow/manager.h
Normal file
20
src/snow/manager.h
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
#include "snow.h"
|
||||||
|
#include <memory>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
namespace Snow {
|
||||||
|
class Manager {
|
||||||
|
public:
|
||||||
|
Manager();
|
||||||
|
void NewSnows(int snows);
|
||||||
|
void NewSnow();
|
||||||
|
void Update();
|
||||||
|
void Draw();
|
||||||
|
~Manager();
|
||||||
|
|
||||||
|
private:
|
||||||
|
std::vector<std::unique_ptr<Snowflake>> snows;
|
||||||
|
void Kill(int pos);
|
||||||
|
int frames = 0;
|
||||||
|
};
|
||||||
|
} // namespace Snow
|
||||||
46
src/snow/snow.cpp
Normal file
46
src/snow/snow.cpp
Normal file
@@ -0,0 +1,46 @@
|
|||||||
|
#include "snow.h"
|
||||||
|
#include "../consts.cpp"
|
||||||
|
#include "Color.hpp"
|
||||||
|
#include "Vector2.hpp"
|
||||||
|
#include <raylib.h>
|
||||||
|
|
||||||
|
namespace Snow {
|
||||||
|
Snowflake::Snowflake() : Snowflake(GetRandomValue(0, 320)) {}
|
||||||
|
Snowflake::Snowflake(int x) : Snowflake(raylib::Vector2(x, 0)) {}
|
||||||
|
Snowflake::Snowflake(raylib::Vector2 pos) : position(pos) {}
|
||||||
|
|
||||||
|
void Snowflake::Move() {
|
||||||
|
raylib::Vector2 move;
|
||||||
|
int hMove = GetRandomValue(0, INV_HORMOVE_CHANCE);
|
||||||
|
if (hMove <= 1) {
|
||||||
|
hMove = hMove * 2 - 1;
|
||||||
|
} else {
|
||||||
|
hMove = 0;
|
||||||
|
}
|
||||||
|
move.x = hMove;
|
||||||
|
move.y = 1;
|
||||||
|
position += move;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Snowflake::IsAlive() { return live; }
|
||||||
|
|
||||||
|
void Snowflake::CheckLive() {
|
||||||
|
if (position.y >= SCREEN_HEIGHT) {
|
||||||
|
live = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Snowflake::Update() {
|
||||||
|
if (currCycle >= MAX_CYCLE_FRAMES) {
|
||||||
|
Move();
|
||||||
|
CheckLive();
|
||||||
|
currCycle = 0;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
currCycle++;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Snowflake::Draw() { raylib::Color::White().DrawPixel(position); }
|
||||||
|
|
||||||
|
Snowflake::~Snowflake() = default;
|
||||||
|
} // namespace Snow
|
||||||
25
src/snow/snow.h
Normal file
25
src/snow/snow.h
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
#include <raylib-cpp.hpp>
|
||||||
|
#include <sys/types.h>
|
||||||
|
|
||||||
|
namespace Snow {
|
||||||
|
class Snowflake {
|
||||||
|
public:
|
||||||
|
Snowflake();
|
||||||
|
Snowflake(int x);
|
||||||
|
Snowflake(raylib::Vector2 pos);
|
||||||
|
|
||||||
|
void Update();
|
||||||
|
void Draw();
|
||||||
|
bool IsAlive();
|
||||||
|
|
||||||
|
~Snowflake();
|
||||||
|
|
||||||
|
private:
|
||||||
|
raylib::Vector2 position;
|
||||||
|
int currCycle = 0;
|
||||||
|
bool live = true;
|
||||||
|
|
||||||
|
inline void Move();
|
||||||
|
inline void CheckLive();
|
||||||
|
};
|
||||||
|
} // namespace Snow
|
||||||
Reference in New Issue
Block a user