mirror of
https://github.com/NickTheFox99/ChristmOS.git
synced 2026-06-30 09:45:12 -04:00
Add Lights Manager, set up Lights, and add Tree.
This commit is contained in:
BIN
assets/tree.png
Normal file
BIN
assets/tree.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 9.8 KiB |
@@ -1,8 +1,11 @@
|
|||||||
|
#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;
|
||||||
@@ -14,4 +17,15 @@ const int INV_HORMOVE_CHANCE = 5;
|
|||||||
|
|
||||||
namespace Lights {
|
namespace Lights {
|
||||||
const int MAX_CYCLE_FRAMES = 30;
|
const int MAX_CYCLE_FRAMES = 30;
|
||||||
}
|
const std::array<Vector2, 9> POSITIONS{{{112, 68},
|
||||||
|
{144, 60},
|
||||||
|
{196, 64},
|
||||||
|
{88, 124},
|
||||||
|
{136, 124},
|
||||||
|
{244, 120},
|
||||||
|
{236, 168},
|
||||||
|
{112, 112},
|
||||||
|
{188, 116}}};
|
||||||
|
const raylib::Color col1 = raylib::Color::Green();
|
||||||
|
const raylib::Color col2 = raylib::Color::Red();
|
||||||
|
} // 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, 4,
|
||||||
|
(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
|
||||||
22
src/main.cpp
22
src/main.cpp
@@ -1,6 +1,8 @@
|
|||||||
|
#include "../data/tree.png.h"
|
||||||
|
#include "Functions.hpp"
|
||||||
#include "Vector2.hpp"
|
#include "Vector2.hpp"
|
||||||
#include "consts.cpp"
|
#include "consts.cpp"
|
||||||
#include "lights/light.h"
|
#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>
|
||||||
@@ -19,16 +21,21 @@ raylib::Window window(WIN_WIDTH, WIN_HEIGHT, "game",
|
|||||||
|
|
||||||
raylib::RenderTexture2D target(SCREEN_WIDTH, SCREEN_HEIGHT);
|
raylib::RenderTexture2D target(SCREEN_WIDTH, SCREEN_HEIGHT);
|
||||||
|
|
||||||
Snow::Manager sMgr;
|
raylib::Image treeImg =
|
||||||
|
raylib::LoadImageFromMemory(".png", tree_png, tree_png_len);
|
||||||
|
|
||||||
Lights::Light tLight(raylib::Vector2(160, 120), raylib::Color::Green(),
|
raylib::Texture2D tree = treeImg.LoadTexture();
|
||||||
raylib::Color::Red(), 5, Lights::color1, 0);
|
|
||||||
|
Snow::Manager sMgr;
|
||||||
|
Lights::Manager lMgr;
|
||||||
|
|
||||||
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);
|
||||||
|
|
||||||
|
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
|
||||||
@@ -48,13 +55,14 @@ void MainLoop() {
|
|||||||
MIN((float)winWidth / SCREEN_WIDTH, (float)winHeight / SCREEN_HEIGHT);
|
MIN((float)winWidth / SCREEN_WIDTH, (float)winHeight / SCREEN_HEIGHT);
|
||||||
|
|
||||||
sMgr.Update();
|
sMgr.Update();
|
||||||
tLight.Update();
|
lMgr.Update();
|
||||||
|
|
||||||
target.BeginMode();
|
target.BeginMode();
|
||||||
{
|
{
|
||||||
ClearBackground(BLACK);
|
// ClearBackground(BLACK);
|
||||||
|
DrawTexture(tree, 0, 0, raylib::Color::White());
|
||||||
sMgr.Draw();
|
sMgr.Draw();
|
||||||
tLight.Draw();
|
lMgr.Draw();
|
||||||
}
|
}
|
||||||
target.EndMode();
|
target.EndMode();
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user