#include #include #include "Runner.hpp" #include #include "Component/Tag/TagComponent.hpp" #include #include "Component/Music/MusicComponent.hpp" #include "Component/Sound/SoundComponent.hpp" #include "Component/Controllable/ControllableComponent.hpp" #include "Component/Position/PositionComponent.hpp" #include "Component/Timer/TimerComponent.hpp" #include "Component/Animator/AnimatorComponent.hpp" #include "Component/Animation/AnimationsComponent.hpp" #include "Component/Health/HealthComponent.hpp" #include "Component/Renderer/CameraComponent.hpp" #include "Component/Collision/CollisionComponent.hpp" #include "Component/Movable/MovableComponent.hpp" #include "Component/BombHolder/BombHolderComponent.hpp" #include "Component/Renderer/Drawable3DComponent.hpp" #include "Component/Shaders/Items/AlphaCtxShaderComponent.hpp" #include "Component/Speed/SpeedComponent.hpp" #include #include "Component/Shaders/ShaderComponent.hpp" #include "Component/Gravity/GravityComponent.hpp" #include "Component/BumperTimer/BumperTimerComponent.hpp" #include "Model/Model.hpp" #include "Map/Map.hpp" #include "Component/Score/ScoreComponent.hpp" namespace RAY3D = RAY::Drawables::Drawables3D; namespace RAY2D = RAY::Drawables::Drawables2D; namespace BBM { std::shared_ptr Runner::loadGameScene() { auto scene = std::make_shared(); scene->addEntity("camera") .addComponent(8, 0, -5) .addComponent(Vector3f(8, 0, 8)); scene->addEntity("background image") .addComponent("assets/map/breakable_wall.obj", true, std::make_pair(MAP_DIFFUSE, "assets/backgrounds/game.png"), Vector3f(50, 1, 50)) .addComponent(5, -2, 0); scene->addEntity("background image") .addComponent("assets/map/breakable_wall.obj", true, std::make_pair(MAP_DIFFUSE, "assets/backgrounds/gameWall.png"), Vector3f(50, 1, 50), -90, Vector3f(), Vector3f(1, 0, 0)) .addComponent(5, 14, 22); addMenuControl(*scene); return scene; } WAL::Entity &Runner::createPlayer(WAL::Scene &scene) { std::map soundPath ={ {SoundComponent::BOMB, "assets/sounds/jump.wav"}, {SoundComponent::MOVE, "assets/sounds/move.ogg"}, {SoundComponent::BOMB, "assets/sounds/bomb_drop.ogg"}, //{SoundComponent::DEATH, "assets/sounds/death.ogg"} }; return scene.addEntity("Player") .addComponent() .addComponent("assets/player/player.iqm", true, std::nullopt, Vector3f(.75, .75, .75)) .addComponent() .addComponent() .addComponent() .addComponent() .addComponent(true) .addComponent>() .addComponent>() .addComponent() .addComponent("assets/player/player.iqm", 3) .addComponent(BBM::Vector3f{0.25, 0, 0.25}, BBM::Vector3f{.6, 2, .6}) .addComponent() .addComponent() .addComponent("assets/shaders/alpha.fs", "", [](WAL::Entity &myEntity, WAL::Wal &, std::chrono::nanoseconds dtime) { auto &ctx = myEntity.getComponent(); ctx.clock += dtime; if (duration_cast(ctx.clock).count() <= 10) return; ctx.clock = 0ns; auto &bonus = myEntity.getComponent(); auto &shader = myEntity.getComponent(); if (!bonus.isNoClipOn) { ctx.alpha = ctx.maxAlpha; shader.shader.setShaderUniformVar("alpha", ctx.alpha); return; } auto nbMilliSec = duration_cast(bonus.nextNoClipRate).count(); if (nbMilliSec > 1500) { ctx.step = ctx.initalStepValue; } else if (nbMilliSec > 1000) { ctx.step = 0.15; } else if (nbMilliSec > 200) { ctx.step = 0.30; } else { ctx.step = 0.5; } ctx.alpha += static_cast(ctx.step * ctx.balance); if (ctx.alpha <= ctx.minAlpha) { ctx.balance = 1; } if (ctx.alpha >= ctx.maxAlpha) { ctx.balance = -1; } shader.shader.setShaderUniformVar("alpha", ctx.alpha); }, true) .addComponent(soundPath) .addComponent("assets/musics/music_battle.ogg") .addComponent() .addComponent() .addComponent(1, [](WAL::Entity &entity, WAL::Wal &) { auto &animation = entity.getComponent(); animation.setAnimIndex(5); if (entity.hasComponent()) entity.removeComponent(); if (entity.hasComponent()) return; entity.getComponent().disable(); entity.addComponent(1s, [](WAL::Entity &ent, WAL::Wal &) { if (!ent.hasComponent()) return; ent.removeComponent(); ent.removeComponent(); ent.removeComponent(); ent.removeComponent(); }); }); } }