Files
Bomberman/sources/Runner/Runner.cpp
2021-06-02 14:33:52 +02:00

82 lines
2.5 KiB
C++

//
// Created by Zoe Roux on 5/24/21.
//
#include <Wal.hpp>
#include <iostream>
#include <System/Movable/MovableSystem.hpp>
#include <System/Renderer/RenderScreenSystem.hpp>
#include <System/Renderer/Render2DScreenSystem.hpp>
#include <System/Renderer/Renderer2DSystem.hpp>
#include <Model/Model.hpp>
#include <Drawables/3D/Cube.hpp>
#include <Drawables/2D/Rectangle.hpp>
#include <TraceLog.hpp>
#include <System/Renderer/Renderer3DSystem.hpp>
#include "Models/Vector2.hpp"
#include "Component/Renderer/CameraComponent.hpp"
#include "Runner.hpp"
#include "Models/GameState.hpp"
namespace RAY2D = RAY::Drawables::Drawables2D;
namespace RAY3D = RAY::Drawables::Drawables3D;
namespace BBM
{
void updateState(WAL::Wal &engine, GameState &state)
{
// You can change the scene here or update the game state based on entities values.
// If you want to keep a scene loaded but not running, store it in the state.loadedScenes.
// If you don't need the scene anymore, remember to remove it from the loadedScene array.
if (RAY::Window::getInstance().shouldClose())
engine.shouldClose = true;
}
void enableRaylib(WAL::Wal &wal)
{
//RAY::TraceLog::setLevel(LOG_WARNING);
RAY::Window &window = RAY::Window::getInstance(800, 600, "Bomberman", FLAG_WINDOW_RESIZABLE);
wal.addSystem<RenderScreenSystem>(window)
.addSystem<Renderer3DSystem<RAY3D::Cube>>()
.addSystem<Renderer3DSystem<RAY3D::Model>>();
wal.addSystem<Render2DScreenSystem>(window)
.addSystem<Renderer2DSystem<RAY2D::Rectangle>>();
}
std::shared_ptr<WAL::Scene> loadGameScene()
{
auto scene = std::make_shared<WAL::Scene>();
scene->addEntity("cube")
.addComponent<PositionComponent>(10, 10, 0)
.addComponent<Drawable2DComponent<RAY2D::Rectangle>>(Vector2f(), Vector2f(10, 10), GREEN);
scene->addEntity("cube2")
.addComponent<PositionComponent>()
.addComponent<Drawable3DComponent<RAY3D::Cube>>(Vector3f(), Vector3f(1, 1, 1), RED);
scene->addEntity("player")
.addComponent<PositionComponent>()
.addComponent<Drawable3DComponent<RAY3D::Model>>("assets/player/player.iqm", std::make_pair(MAP_DIFFUSE, "assets/player/blue.png"));
scene->addEntity("camera")
.addComponent<PositionComponent>(10, 10, 15)
.addComponent<CameraComponent>();
return scene;
}
int run()
{
WAL::Wal wal;
wal.addSystem<MovableSystem>();
enableRaylib(wal);
wal.scene = loadGameScene();
try {
wal.run<GameState>(updateState);
return 0;
} catch (const std::exception &ex) {
std::cerr << ex.what() << std::endl;
return 1;
}
}
}