mirror of
https://github.com/NickTheFox99/ChristmOS.git
synced 2026-06-28 16:55:11 -04:00
Add rudimentary implementation of Snow::Manager
This commit is contained in:
BIN
assets/cube.png
BIN
assets/cube.png
Binary file not shown.
|
Before Width: | Height: | Size: 102 B |
@@ -6,3 +6,8 @@ const int SCREEN_HEIGHT = 240;
|
|||||||
|
|
||||||
const int WIN_WIDTH = 1280;
|
const int WIN_WIDTH = 1280;
|
||||||
const int WIN_HEIGHT = 720;
|
const int WIN_HEIGHT = 720;
|
||||||
|
|
||||||
|
namespace Snow {
|
||||||
|
const int MAX_SECS = 4;
|
||||||
|
const int INV_CHANCE = 5;
|
||||||
|
} // namespace Snow
|
||||||
|
|||||||
31
src/main.cpp
31
src/main.cpp
@@ -1,6 +1,5 @@
|
|||||||
#include "../data/cube.png.h"
|
|
||||||
#include "consts.cpp"
|
#include "consts.cpp"
|
||||||
#include <cmath>
|
#include "snow/manager.h"
|
||||||
#include <raylib-cpp.hpp>
|
#include <raylib-cpp.hpp>
|
||||||
#include <raylib.h>
|
#include <raylib.h>
|
||||||
|
|
||||||
@@ -18,25 +17,14 @@ 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 = Snow::Manager();
|
||||||
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);
|
sMgr.NewSnows(10);
|
||||||
|
|
||||||
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);
|
||||||
@@ -56,21 +44,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();
|
||||||
|
|
||||||
|
|||||||
@@ -7,6 +7,10 @@ Manager::Manager() = default;
|
|||||||
Manager::~Manager() = default;
|
Manager::~Manager() = default;
|
||||||
|
|
||||||
void Manager::NewSnow() { snows.push_back(std::make_unique<Snow>()); }
|
void Manager::NewSnow() { snows.push_back(std::make_unique<Snow>()); }
|
||||||
|
void Manager::NewSnows(int snows) {
|
||||||
|
for (int i = 0; i < snows; i++)
|
||||||
|
NewSnow();
|
||||||
|
}
|
||||||
|
|
||||||
void Manager::Update() {
|
void Manager::Update() {
|
||||||
for (auto snowi = 0; snowi < snows.size(); snowi++) {
|
for (auto snowi = 0; snowi < snows.size(); snowi++) {
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ namespace Snow {
|
|||||||
class Manager {
|
class Manager {
|
||||||
public:
|
public:
|
||||||
Manager();
|
Manager();
|
||||||
|
void NewSnows(int snows);
|
||||||
void NewSnow();
|
void NewSnow();
|
||||||
void Update();
|
void Update();
|
||||||
void Draw();
|
void Draw();
|
||||||
|
|||||||
@@ -4,16 +4,12 @@
|
|||||||
#include "Vector2.hpp"
|
#include "Vector2.hpp"
|
||||||
#include <raylib.h>
|
#include <raylib.h>
|
||||||
|
|
||||||
#define MAX_SECS 4
|
|
||||||
#define INV_CHANCE 5
|
|
||||||
|
|
||||||
namespace Snow {
|
namespace Snow {
|
||||||
Snow::Snow() { Snow(GetRandomValue(0, 320)); }
|
Snow::Snow() { Snow(GetRandomValue(0, 320)); }
|
||||||
Snow::Snow(uint x) { Snow(raylib::Vector2(x, 0)); }
|
Snow::Snow(uint x) { Snow(raylib::Vector2(x, 0)); }
|
||||||
Snow::Snow(raylib::Vector2 pos) {
|
Snow::Snow(raylib::Vector2 pos) {
|
||||||
position = pos;
|
position = pos;
|
||||||
currCycle = 0;
|
currCycle = 0;
|
||||||
maxCycle = MAX_SECS;
|
|
||||||
live = true;
|
live = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -38,7 +34,7 @@ void Snow::CheckLive() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void Snow::Update() {
|
void Snow::Update() {
|
||||||
if (currCycle >= maxCycle) {
|
if (currCycle >= MAX_SECS) {
|
||||||
Move();
|
Move();
|
||||||
CheckLive();
|
CheckLive();
|
||||||
currCycle = 0;
|
currCycle = 0;
|
||||||
|
|||||||
@@ -17,7 +17,6 @@ public:
|
|||||||
private:
|
private:
|
||||||
raylib::Vector2 position;
|
raylib::Vector2 position;
|
||||||
uint currCycle;
|
uint currCycle;
|
||||||
uint maxCycle;
|
|
||||||
bool live;
|
bool live;
|
||||||
|
|
||||||
inline void Move();
|
inline void Move();
|
||||||
|
|||||||
Reference in New Issue
Block a user