mirror of
https://github.com/NickTheFox99/ChristmOS.git
synced 2026-06-28 16:55:11 -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>
|
||||
|
||||
// SCREEN CONSTS
|
||||
const int SCREEN_WIDTH = 320;
|
||||
const int SCREEN_HEIGHT = 240;
|
||||
const int SCREEN_WIDTH = 80;
|
||||
const int SCREEN_HEIGHT = 60;
|
||||
|
||||
const int WIN_WIDTH = 1280;
|
||||
const int WIN_HEIGHT = 720;
|
||||
@@ -14,4 +17,15 @@ const int INV_HORMOVE_CHANCE = 5;
|
||||
|
||||
namespace Lights {
|
||||
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 "consts.cpp"
|
||||
#include "lights/light.h"
|
||||
#include "lights/manager.h"
|
||||
#include "snow/manager.h"
|
||||
#include <raylib-cpp.hpp>
|
||||
#include <raylib.h>
|
||||
@@ -19,16 +21,21 @@ raylib::Window window(WIN_WIDTH, WIN_HEIGHT, "game",
|
||||
|
||||
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::Color::Red(), 5, Lights::color1, 0);
|
||||
raylib::Texture2D tree = treeImg.LoadTexture();
|
||||
|
||||
Snow::Manager sMgr;
|
||||
Lights::Manager lMgr;
|
||||
|
||||
int main(void) {
|
||||
window.SetMinSize({320, 240});
|
||||
window.SetTargetFPS(60);
|
||||
window.SetExitKey(KEY_BACKSPACE);
|
||||
|
||||
tree.SetFilter(TEXTURE_FILTER_POINT);
|
||||
|
||||
#if defined(PLATFORM_WEB)
|
||||
emscripten_set_main_loop(MainLoop, 0, 1);
|
||||
#else
|
||||
@@ -48,13 +55,14 @@ void MainLoop() {
|
||||
MIN((float)winWidth / SCREEN_WIDTH, (float)winHeight / SCREEN_HEIGHT);
|
||||
|
||||
sMgr.Update();
|
||||
tLight.Update();
|
||||
lMgr.Update();
|
||||
|
||||
target.BeginMode();
|
||||
{
|
||||
ClearBackground(BLACK);
|
||||
// ClearBackground(BLACK);
|
||||
DrawTexture(tree, 0, 0, raylib::Color::White());
|
||||
sMgr.Draw();
|
||||
tLight.Draw();
|
||||
lMgr.Draw();
|
||||
}
|
||||
target.EndMode();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user