From 9fa4f2829bdcf04c66ed1079341c52d4ed79d471 Mon Sep 17 00:00:00 2001
From: Frederic Leger <57264593+freeedleger@users.noreply.github.com>
Date: Mon, 30 Oct 2023 14:03:10 -0400
Subject: [PATCH] add boostinfo
---
SQCSim-common/SQCSim-common.vcxproj | 2 +
SQCSim-common/SQCSim-common.vcxproj.filters | 6 +++
SQCSim-common/boostinfo.cpp | 32 +++++++++++++
SQCSim-common/boostinfo.h | 29 ++++++++++++
SQCSim-common/define.h | 7 +++
SQCSim-common/player.cpp | 51 ++++++++++++++++++++-
SQCSim-common/player.h | 10 +++-
SQCSim2021/define.h | 1 +
SQCSim2021/engine.cpp | 4 ++
9 files changed, 140 insertions(+), 2 deletions(-)
create mode 100644 SQCSim-common/boostinfo.cpp
create mode 100644 SQCSim-common/boostinfo.h
diff --git a/SQCSim-common/SQCSim-common.vcxproj b/SQCSim-common/SQCSim-common.vcxproj
index 991cd1d..5f319ac 100644
--- a/SQCSim-common/SQCSim-common.vcxproj
+++ b/SQCSim-common/SQCSim-common.vcxproj
@@ -131,6 +131,7 @@
+
@@ -144,6 +145,7 @@
+
diff --git a/SQCSim-common/SQCSim-common.vcxproj.filters b/SQCSim-common/SQCSim-common.vcxproj.filters
index 26c6c05..45814cf 100644
--- a/SQCSim-common/SQCSim-common.vcxproj.filters
+++ b/SQCSim-common/SQCSim-common.vcxproj.filters
@@ -54,6 +54,9 @@
Fichiers d%27en-tĂȘte
+
+ Fichiers d%27en-tĂȘte
+
@@ -80,5 +83,8 @@
Fichiers sources
+
+ Fichiers sources
+
\ No newline at end of file
diff --git a/SQCSim-common/boostinfo.cpp b/SQCSim-common/boostinfo.cpp
new file mode 100644
index 0000000..9b54626
--- /dev/null
+++ b/SQCSim-common/boostinfo.cpp
@@ -0,0 +1,32 @@
+#include "boostinfo.h"
+#include
+
+BoostInfo::BoostInfo(BoostType type, const std::string& name, float u, float v, float s, int dur) : m_type(type), m_name(name), m_u(u), m_v(v), m_s(s), m_durability(dur)
+{
+}
+
+BoostInfo::~BoostInfo()
+{
+}
+
+BoostType BoostInfo::GetType() const
+{
+ return m_type;
+}
+
+void BoostInfo::GetTexture(float& u, float& v, float& s)
+{
+ u = m_u;
+ v = m_v;
+ s = m_s;
+}
+
+void BoostInfo::Show() const
+{
+ std::cout << "Type: " << m_type << std::endl;
+ std::cout << "Nom: " << m_name << std::endl;
+ std::cout << "Durabilite: " << m_durability << std::endl;
+ std::cout << "Coordonnees Texture: " << m_u << ", " << m_v << ", " << m_s << std::endl;
+}
+
+
diff --git a/SQCSim-common/boostinfo.h b/SQCSim-common/boostinfo.h
new file mode 100644
index 0000000..e76d1ed
--- /dev/null
+++ b/SQCSim-common/boostinfo.h
@@ -0,0 +1,29 @@
+#ifndef BOOSTINFO_H__
+#define BOOSTINFO_H__
+
+#include
+#include "define.h"
+
+class BoostInfo
+{
+public:
+ BoostInfo(BoostType type, const std::string& name, float u, float v, float s, int dur);
+ ~BoostInfo();
+
+ BoostType GetType() const;
+
+ void GetTexture(float& u, float& v, float& s);
+
+ void Show() const;
+
+private:
+ BoostType m_type;
+ float m_u;
+ float m_v;
+ float m_s;
+ std::string m_name;
+ int m_durability;
+
+};
+
+#endif // BOOSTINFO_H__
diff --git a/SQCSim-common/define.h b/SQCSim-common/define.h
index f65bc2b..337a9be 100644
--- a/SQCSim-common/define.h
+++ b/SQCSim-common/define.h
@@ -29,8 +29,15 @@
#define TEXTURE_SIZE 512
#define MAX_BULLETS 512
+#define TIME_SPEED_BOOST 10 //secondes
+#define TIME_DAMAGE_BOOST 10 //secondes
+#define TIME_INVINCIBLE_BOOST 4 //secondes
+#define STRENGTH_SPEED_BOOST 10 //Pourcentage
+
typedef uint8_t BlockType;
+typedef uint8_t BoostType;
enum BLOCK_TYPE { BTYPE_AIR, BTYPE_DIRT, BTYPE_GRASS, BTYPE_METAL, BTYPE_ICE, BTYPE_LAST };
+enum BOOST_TYPE { BTYPE_SPEED, BTYPE_HEAL, BTYPE_DAMAGE, BTYPE_INVINCIBLE };
typedef uint64_t Timestamp;
#ifdef _WIN32
diff --git a/SQCSim-common/player.cpp b/SQCSim-common/player.cpp
index 9fe810c..66b6c0a 100644
--- a/SQCSim-common/player.cpp
+++ b/SQCSim-common/player.cpp
@@ -59,6 +59,11 @@ Vector3f Player::GetInput(bool front, bool back, bool left, bool right, bool jum
delta.y += jump? .32f: shoot? .1f : 0.f;
m_airborne = true;
}
+ if (boostspeed)
+ {
+ delta.x += STRENGTH_SPEED_BOOST / 100 * delta.x;
+ delta.z += STRENGTH_SPEED_BOOST / 100 * delta.z;
+ }
if (shoot) // Recoil!
TurnTopBottom(-1);
@@ -180,7 +185,7 @@ Player::Sound Player::ApplyPhysics(Vector3f input, World* world, float elapsedTi
else isStep = false;
m_POV = m_position.y;
m_POV += m_airborne ? 0 : (sin(bobbingtime) - 0.5f) * (abs(m_velocity.x) + abs(m_velocity.z)) * .2f;
-
+ RemoveBooster(elapsedTime);
return snd;
}
@@ -190,6 +195,50 @@ void Player::ApplyTransformation(Transformation& transformation, bool rel) const
if (rel) transformation.ApplyTranslation(-GetPOV());
}
+void Player::GetBooster(Booster boosttype)
+{
+ if (boosttype == SPEED)
+ {
+ boostspeed = true;
+ timeboostspeed = 0;
+ }
+ if (boosttype == HEAL)
+ {
+ m_hp = 100;
+ }
+ if (boosttype == DAMAGE)
+ {
+ boostdamage = true;
+ timeboostdamage = 0;
+ }
+ if (boosttype == INVINCIBLE)
+ {
+ boostinvincible = true;
+ boostinvincible = 0;
+ }
+}
+void Player::RemoveBooster(float elapsedtime)
+{
+ if (boostspeed)
+ {
+ timeboostspeed += elapsedtime;
+ if (timeboostspeed >= TIME_SPEED_BOOST)
+ boostspeed = false;
+ }
+ if (boostdamage)
+ {
+ timeboostdamage += elapsedtime;
+ if (timeboostdamage >= TIME_DAMAGE_BOOST)
+ boostdamage = false;
+ }
+ if (boostinvincible)
+ {
+ timeboostinvincible += elapsedtime;
+ if (timeboostinvincible >= TIME_INVINCIBLE_BOOST)
+ boostinvincible = false;
+ }
+}
+
Vector3f Player::GetPosition() const { return Vector3f(m_position.x + CHUNK_SIZE_X * WORLD_SIZE_X / 2, m_position.y, m_position.z + CHUNK_SIZE_Z * WORLD_SIZE_Y / 2); }
Vector3f Player::GetVelocity() const { return m_velocity; }
diff --git a/SQCSim-common/player.h b/SQCSim-common/player.h
index e439fa2..1a98d6d 100644
--- a/SQCSim-common/player.h
+++ b/SQCSim-common/player.h
@@ -10,6 +10,7 @@ class World;
class Player {
public:
enum Sound { NOSOUND, STEP, FALL };
+ enum Booster { SPEED, HEAL, DAMAGE, INVINCIBLE };
Player(const Vector3f& position, float rotX = 0, float rotY = 0);
void TurnLeftRight(float value);
@@ -17,7 +18,8 @@ public:
Vector3f GetInput(bool front, bool back, bool left, bool right, bool jump, bool dash, float elapsedTime);
Sound ApplyPhysics(Vector3f input, World* world, float elapsedTime);
void ApplyTransformation(Transformation& transformation, bool rel = true) const;
-
+ void GetBooster(Booster boosttype);
+ void RemoveBooster(float elapsedtime);
Vector3f GetPosition() const;
Vector3f GetDirection() const;
Vector3f GetVelocity() const;
@@ -36,10 +38,16 @@ private:
float m_rotX = 0;
float m_rotY = 0;
float m_POV;
+ float timeboostspeed;
+ float timeboostdamage;
+ float timeboostinvincible;
float m_hp;
bool m_airborne;
+ bool boostspeed;
+ bool boostdamage;
+ bool boostinvincible;
};
#endif //_PLAYER_H__
diff --git a/SQCSim2021/define.h b/SQCSim2021/define.h
index 67c49c3..2abfe0c 100644
--- a/SQCSim2021/define.h
+++ b/SQCSim2021/define.h
@@ -35,5 +35,6 @@
#define AUDIO_PATH "./media/audio/"
#define CHUNK_PATH "./media/chunks/"
#define MENU_ITEM_PATH "./media/menu_items/"
+#define BOOSTER_TEXTURE_PATH "./media/textures/Booster"
#endif // DEFINE_H__
diff --git a/SQCSim2021/engine.cpp b/SQCSim2021/engine.cpp
index a5939e6..daa4123 100644
--- a/SQCSim2021/engine.cpp
+++ b/SQCSim2021/engine.cpp
@@ -305,6 +305,10 @@ void Engine::LoadResource() {
TextureAtlas::TextureIndex texIceIndex = m_textureAtlas.AddTexture(TEXTURE_PATH "metal2.png");
TextureAtlas::TextureIndex texGrassIndex = m_textureAtlas.AddTexture(TEXTURE_PATH "grass.png");
TextureAtlas::TextureIndex texMetalIndex = m_textureAtlas.AddTexture(TEXTURE_PATH "dirt.png");
+ TextureAtlas::TextureIndex texBoostHeal = m_textureAtlas.AddTexture(BOOSTER_TEXTURE_PATH "BoosterMauve.png");
+ TextureAtlas::TextureIndex texBoostDmg = m_textureAtlas.AddTexture(BOOSTER_TEXTURE_PATH "BoosterRouge.png");
+ TextureAtlas::TextureIndex texBoostSpd = m_textureAtlas.AddTexture(BOOSTER_TEXTURE_PATH "BoosterBleu.png");
+ TextureAtlas::TextureIndex texBoostInv = m_textureAtlas.AddTexture(BOOSTER_TEXTURE_PATH "BoosterJaune.png");
if (!m_textureAtlas.Generate(TEXTURE_SIZE, false)) {
std::cout << " Unable to generate texture atlas ..." << std::endl;