mirror of
https://github.com/zoriya/Bomberman.git
synced 2026-06-02 02:05:25 +00:00
first correct no clip version
This commit is contained in:
+1
-1
@@ -176,7 +176,7 @@ set(SOURCES
|
||||
sources/Component/Color/ColorComponent.cpp
|
||||
sources/Component/Stat/StatComponent.cpp
|
||||
sources/Component/Stat/StatComponent.hpp
|
||||
)
|
||||
sources/Component/Shaders/Items/AlphaCtxShaderComponent.cpp sources/Component/Shaders/Items/AlphaCtxShaderComponent.hpp)
|
||||
|
||||
add_executable(bomberman
|
||||
sources/main.cpp
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
//
|
||||
// Created by cbihan on 18/06/2021.
|
||||
//
|
||||
|
||||
#include "AlphaCtxShaderComponent.hpp"
|
||||
|
||||
|
||||
namespace BBM
|
||||
{
|
||||
|
||||
AlphaVarShaderComponent::AlphaVarShaderComponent(WAL::Entity &entity) :
|
||||
WAL::Component(entity)
|
||||
{
|
||||
}
|
||||
|
||||
WAL::Component *AlphaVarShaderComponent::clone(WAL::Entity &entity) const
|
||||
{
|
||||
return new AlphaVarShaderComponent(this->_entity);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
//
|
||||
// Created by cbihan on 18/06/2021.
|
||||
//
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <Component/Component.hpp>
|
||||
#include <chrono>
|
||||
|
||||
using namespace std::chrono_literals;
|
||||
|
||||
namespace BBM
|
||||
{
|
||||
class AlphaVarShaderComponent : public WAL::Component
|
||||
{
|
||||
public:
|
||||
//! @brief Transparency
|
||||
float alpha = 1;
|
||||
|
||||
//! @brief minimum transparency
|
||||
float minAlpha = 0.2;
|
||||
//! @brief maximum transparency
|
||||
float maxAlpha = 1;
|
||||
//! @brief inital step value
|
||||
float initalStepValue = 0.04;
|
||||
//! @brief how fast the alpha will vary
|
||||
float step = 0.04;
|
||||
//! @brief if the alpha should increase or decrease
|
||||
float balance = -1;
|
||||
|
||||
//! @brief The clock to use
|
||||
std::chrono::nanoseconds clock = 0ns;
|
||||
|
||||
|
||||
//! @inherit
|
||||
WAL::Component *clone(WAL::Entity &entity) const override;
|
||||
|
||||
//! @brief ctor
|
||||
explicit AlphaVarShaderComponent(WAL::Entity &entity);
|
||||
|
||||
//! @brief Default copy ctor
|
||||
AlphaVarShaderComponent(const AlphaVarShaderComponent &) = default;
|
||||
|
||||
//! @brief Default dtor
|
||||
~AlphaVarShaderComponent() override = default;
|
||||
|
||||
//! @brief Default assignment operator
|
||||
AlphaVarShaderComponent &operator=(const AlphaVarShaderComponent &) = delete;
|
||||
};
|
||||
|
||||
}
|
||||
@@ -58,6 +58,7 @@ namespace BBM {
|
||||
if (!playerBonus)
|
||||
return;
|
||||
playerBonus->nextNoClipRate = playerBonus->noClipBonusRate;
|
||||
|
||||
playerBonus->isNoClipOn = true;
|
||||
const_cast<WAL::Entity &>(bonus).scheduleDeletion();
|
||||
}
|
||||
@@ -70,7 +71,7 @@ namespace BBM {
|
||||
{SPEEDUP, 45.0f},
|
||||
{BOMBSTOCK, 30.0f},
|
||||
{EXPLOSIONINC, 15.0f},
|
||||
{NOCLIP, 1.5f},
|
||||
{NOCLIP, 70.5f},
|
||||
};
|
||||
std::uniform_int_distribution<int> distribution(1,1000);
|
||||
float value = (distribution(generator) / 10);
|
||||
|
||||
@@ -16,8 +16,10 @@
|
||||
#include "Component/BombHolder/BombHolderComponent.hpp"
|
||||
#include "Component/Tag/TagComponent.hpp"
|
||||
#include "Component/Renderer/Drawable3DComponent.hpp"
|
||||
#include "Component/Shaders/Items/AlphaCtxShaderComponent.hpp"
|
||||
#include "Component/Renderer/Drawable2DComponent.hpp"
|
||||
#include <Drawables/Image.hpp>
|
||||
#include "Component/Shaders/ShaderComponent.hpp"
|
||||
#include "Drawables/Texture.hpp"
|
||||
#include "Component/Gravity/GravityComponent.hpp"
|
||||
#include "Component/BumperTimer/BumperTimerComponent.hpp"
|
||||
@@ -66,6 +68,44 @@ namespace BBM
|
||||
.addComponent<AnimationsComponent>("assets/player/player.iqm", 3)
|
||||
.addComponent<CollisionComponent>(BBM::Vector3f{0.25, 0, 0.25}, BBM::Vector3f{.75, 2, .75})
|
||||
.addComponent<MovableComponent>()
|
||||
.addComponent<AlphaVarShaderComponent>()
|
||||
.addComponent<ShaderComponentModel>("assets/shaders/alpha.fs", "", [](WAL::Entity &myEntity, WAL::Wal &wal, std::chrono::nanoseconds dtime) {
|
||||
auto &ctx = myEntity.getComponent<AlphaVarShaderComponent>();
|
||||
|
||||
ctx.clock += dtime;
|
||||
if (duration_cast<std::chrono::milliseconds>(ctx.clock).count() <= 10)
|
||||
return;
|
||||
ctx.clock = 0ns;
|
||||
auto &bonus = myEntity.getComponent<PlayerBonusComponent>();
|
||||
auto &shader = myEntity.getComponent<ShaderComponentModel>();
|
||||
|
||||
if (!bonus.isNoClipOn) {
|
||||
ctx.alpha = ctx.maxAlpha;
|
||||
shader.shader.setShaderUniformVar("alpha", ctx.alpha);
|
||||
return;
|
||||
}
|
||||
|
||||
auto nbMilliSec = duration_cast<std::chrono::milliseconds>(bonus.nextNoClipRate).count();
|
||||
|
||||
if (nbMilliSec > 1000) {
|
||||
ctx.step = ctx.initalStepValue;
|
||||
} else if (nbMilliSec > 500) {
|
||||
ctx.step = 0.15;
|
||||
} else if (nbMilliSec > 100) {
|
||||
ctx.step = 0.30;
|
||||
} else {
|
||||
ctx.step = 0.5;
|
||||
}
|
||||
ctx.alpha += static_cast<float>(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<SoundComponent>(soundPath)
|
||||
.addComponent<MusicComponent>("assets/musics/music_battle.ogg")
|
||||
.addComponent<BombHolderComponent>()
|
||||
|
||||
Reference in New Issue
Block a user