mirror of
https://github.com/NickTheFox99/ChristmOS.git
synced 2026-06-19 13:25:10 -04:00
Compare commits
12 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
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 |
13
src/consts.cpp
Normal file
13
src/consts.cpp
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
#include <sys/types.h>
|
||||||
|
|
||||||
|
// SCREEN CONSTS
|
||||||
|
const int SCREEN_WIDTH = 320;
|
||||||
|
const int SCREEN_HEIGHT = 240;
|
||||||
|
|
||||||
|
const int WIN_WIDTH = 1280;
|
||||||
|
const int WIN_HEIGHT = 720;
|
||||||
|
|
||||||
|
namespace Snow {
|
||||||
|
const int MAX_SECS = 4;
|
||||||
|
const int INV_CHANCE = 5;
|
||||||
|
} // namespace Snow
|
||||||
39
src/main.cpp
39
src/main.cpp
@@ -1,17 +1,12 @@
|
|||||||
#include "../data/cube.png.h"
|
#include "consts.cpp"
|
||||||
#include "raylib.h"
|
#include "snow/manager.h"
|
||||||
#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))
|
||||||
|
|
||||||
@@ -22,26 +17,13 @@ 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 =
|
Snow::Manager sMgr;
|
||||||
raylib::LoadImageFromMemory(".png", cube_png, cube_png_len);
|
|
||||||
|
|
||||||
raylib::Texture2D texture = texImg.LoadTexture();
|
|
||||||
|
|
||||||
raylib::Camera3D cam(raylib::Vector3(0.0f, 0.0f, std::sqrt(3.0f)),
|
|
||||||
raylib::Vector3::Zero(), raylib::Vector3(0.0f, 1.0f, 0.0f),
|
|
||||||
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({320, 240});
|
||||||
window.SetTargetFPS(60);
|
window.SetTargetFPS(60);
|
||||||
window.SetExitKey(KEY_BACKSPACE);
|
window.SetExitKey(KEY_BACKSPACE);
|
||||||
|
|
||||||
target.GetTexture().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);
|
||||||
#else
|
#else
|
||||||
@@ -60,21 +42,12 @@ 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(
|
|
||||||
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)
|
sMgr.Draw();
|
||||||
.DrawCircle(120.0f, raylib::Color::White());
|
|
||||||
cam.BeginMode();
|
|
||||||
{
|
|
||||||
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 Snow()); }
|
||||||
|
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<Snow>> 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 {
|
||||||
|
Snow::Snow() : Snow(GetRandomValue(0, 320)) {}
|
||||||
|
Snow::Snow(int x) : Snow(raylib::Vector2(x, 0)) {}
|
||||||
|
Snow::Snow(raylib::Vector2 pos) : position(pos) {}
|
||||||
|
|
||||||
|
void Snow::Move() {
|
||||||
|
raylib::Vector2 move;
|
||||||
|
int hMove = GetRandomValue(0, INV_CHANCE);
|
||||||
|
if (hMove <= 1) {
|
||||||
|
hMove = hMove * 2 - 1;
|
||||||
|
} else {
|
||||||
|
hMove = 0;
|
||||||
|
}
|
||||||
|
move.x = hMove;
|
||||||
|
move.y = 1;
|
||||||
|
position += move;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Snow::IsAlive() { return live; }
|
||||||
|
|
||||||
|
void Snow::CheckLive() {
|
||||||
|
if (position.y >= SCREEN_HEIGHT) {
|
||||||
|
live = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Snow::Update() {
|
||||||
|
if (currCycle >= MAX_SECS) {
|
||||||
|
Move();
|
||||||
|
CheckLive();
|
||||||
|
currCycle = 0;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
currCycle++;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Snow::Draw() { raylib::Color::White().DrawPixel(position); }
|
||||||
|
|
||||||
|
Snow::~Snow() = 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 Snow {
|
||||||
|
public:
|
||||||
|
Snow();
|
||||||
|
Snow(int x);
|
||||||
|
Snow(raylib::Vector2 pos);
|
||||||
|
|
||||||
|
void Update();
|
||||||
|
void Draw();
|
||||||
|
bool IsAlive();
|
||||||
|
|
||||||
|
~Snow();
|
||||||
|
|
||||||
|
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