Merge branch 'develop' of github.com:AnonymusRaccoon/Bomberman into parser

# Conflicts:
#	CMakeLists.txt
#	sources/Runner/GameScene.cpp
This commit is contained in:
Clément Le Bihan
2021-06-19 11:34:12 +02:00
9 changed files with 137 additions and 2 deletions
+2
View File
@@ -190,6 +190,8 @@ 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
sources/Component/Speed/SpeedComponent.cpp
sources/Component/Speed/SpeedComponent.hpp
)
+1 -1
View File
@@ -104,7 +104,7 @@ varying vec3 fragNormal;
void main() {
// Send vertex attributes to fragment shader
fragPosition = vertexPosition + vertexPosition * vec3(cnoise(vec3(vertexNormal + vec3(frame))) * 0.5);
fragPosition = vertexPosition + vertexPosition * vec3(cnoise(vec3(vertexNormal + center + vec3(frame))) * 0.5);
fragColor = vertexColor;
fragNormal = vertexNormal;
fragTexCoord = vertexTexCoord;
+16
View File
@@ -6,6 +6,7 @@
#include <utility>
#include "Exceptions/RayError.hpp"
#include "Vector/Vector3.hpp"
namespace RAY
{
@@ -38,6 +39,7 @@ namespace RAY
SetShaderValue(*this->_rayLibShader, this->_shaderIndexVars[varName], &value, SHADER_UNIFORM_FLOAT);
}
void Shader::setShaderUniformVar(const std::string &varName, int value)
{
if (this->_shaderIndexVars.find(varName) == this->_shaderIndexVars.end()) {
@@ -60,4 +62,18 @@ namespace RAY
{
EndShaderMode();
}
void Shader::setShaderUniformVar(const std::string &varName, const RAY::Vector3 &vector)
{
if (this->_shaderIndexVars.find(varName) == this->_shaderIndexVars.end()) {
int varShaderIndex = GetShaderLocation(*this->_rayLibShader, varName.c_str());
if (varShaderIndex < 0) {
throw Exception::WrongInputError("The loaded shader doesn't have a variable called: " + varName);
}
this->_shaderIndexVars[varName] = varShaderIndex;
}
SetShaderValue(*this->_rayLibShader, this->_shaderIndexVars[varName], &vector, SHADER_UNIFORM_VEC3);
}
}
+3
View File
@@ -9,6 +9,7 @@
#include <map>
#include <raylib.h>
#include "Utils/Cache.hpp"
#include "Vector/Vector3.hpp"
namespace RAY
{
@@ -46,6 +47,8 @@ namespace RAY
//! @note Throw if the var is not found
void setShaderUniformVar(const std::string &varName, int value);
void setShaderUniformVar(const std::string &varName, const RAY::Vector3 &vector);
void setLocation(::ShaderLocationIndex, const std::string &name);
//! @brief ctor if no vertexfile in needed set it to nullptr
@@ -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;
};
}
+1
View File
@@ -59,6 +59,7 @@ namespace BBM {
if (!playerBonus)
return;
playerBonus->nextNoClipRate = playerBonus->noClipBonusRate;
playerBonus->isNoClipOn = true;
const_cast<WAL::Entity &>(bonus).scheduleDeletion();
}
+40
View File
@@ -19,9 +19,11 @@
#include "Component/BombHolder/BombHolderComponent.hpp"
#include "Component/Tag/TagComponent.hpp"
#include "Component/Renderer/Drawable3DComponent.hpp"
#include "Component/Shaders/Items/AlphaCtxShaderComponent.hpp"
#include "Component/Speed/SpeedComponent.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"
@@ -70,6 +72,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 > 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<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>()
@@ -53,6 +53,7 @@ namespace BBM
.addComponent<ShaderComponentModel>("assets/shaders/explosion.fs", "assets/shaders/explosion.vs", [](WAL::Entity &entity, WAL::Wal &, std::chrono::nanoseconds dtime) {
auto &ctx = entity.getComponent<BombExplosionShaderComponent>();
auto &shader = entity.getComponent<ShaderComponentModel>();
auto &pos = entity.getComponent<PositionComponent>();
ctx.clock += dtime;
if (duration_cast<std::chrono::milliseconds>(ctx.clock).count() <= 10)
@@ -69,7 +70,8 @@ namespace BBM
shader.shader.setShaderUniformVar("frame", ctx.frameCounter);
shader.shader.setShaderUniformVar("alpha", ctx.alpha);
shader.shader.setShaderUniformVar("radius", ctx.explosionRadius);
})
shader.shader.setShaderUniformVar("center", pos.position);
}, true)
.addComponent<TimerComponent>(500ms, [](WAL::Entity &explosion, WAL::Wal &) {
explosion.scheduleDeletion();
})