diff --git a/SQCSim-common/SQCSim-common.vcxproj b/SQCSim-common/SQCSim-common.vcxproj
index 4cebfaf..4ba7bd4 100644
--- a/SQCSim-common/SQCSim-common.vcxproj
+++ b/SQCSim-common/SQCSim-common.vcxproj
@@ -134,6 +134,7 @@
+
@@ -147,6 +148,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 2ebf25d..90e3d0d 100644
--- a/SQCSim-common/define.h
+++ b/SQCSim-common/define.h
@@ -27,14 +27,20 @@
#define THREADS_UPDATE_CHUNKS 6
#define THREADS_DELETE_CHUNKS 3
-#define VIEW_DISTANCE 512 // Si les chunks arrêtent de s'afficher pendant une game et qu'il y a un access violation quand tu quitte, il faut augmenter ce chiffre.
+#define VIEW_DISTANCE 512 // Si les chunks arr�tent de s'afficher pendant une game et qu'il y a un access violation quand tu quitte, il faut augmenter ce chiffre.
#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
#define BULLET_TIME .1
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, BTYPE_BOOST_LAST };
enum ANIM_TYPE { STILL = 0, SHOOTING = 8, JUMPING = 16, JUMPINGSHOOTING = 24, DEAD = 32, TYPE_LAST = 40};
enum ANIM_POS {FRONT, QUARTER_FRONT_LEFT, QUATER_FRONT_RIGHT, PROFIL_LEFT, PROFIL_RIGHT, QUARTER_BACK_LEFT, QUARTER_BACK_RIGHT, BACK , POS_LAST};
typedef uint64_t Timestamp;
diff --git a/SQCSim-common/player.cpp b/SQCSim-common/player.cpp
index 714a4b9..b88ba18 100644
--- a/SQCSim-common/player.cpp
+++ b/SQCSim-common/player.cpp
@@ -61,6 +61,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);
@@ -182,7 +187,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;
}
@@ -196,6 +201,49 @@ void Player::ApplyTransformation(Transformation& transformation, bool rel, bool
}
}
+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;
+ }
+}
void Player::SetDirection(Vector3f dir) { m_direction = dir; }
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); }
diff --git a/SQCSim-common/player.h b/SQCSim-common/player.h
index 7b2441f..4792d4a 100644
--- a/SQCSim-common/player.h
+++ b/SQCSim-common/player.h
@@ -11,6 +11,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);
~Player();
@@ -19,6 +20,8 @@ public:
void TurnTopBottom(float value);
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 GetBooster(Booster boosttype);
+ void RemoveBooster(float elapsedtime);
void ApplyTransformation(Transformation& transformation, bool rel = true, bool rot = true) const;
void SetDirection(Vector3f dir);
@@ -47,15 +50,20 @@ protected:
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;
Vector3f InterpolatePosition(const Vector3f& vec1, const Vector3f& vec2, const Timestamp& tim1, const Timestamp& tim2, const Timestamp& now);
-
};
#endif //_PLAYER_H__
diff --git a/SQCSim2021/SQCSim2021.vcxproj b/SQCSim2021/SQCSim2021.vcxproj
index 7f1334e..3aec273 100644
--- a/SQCSim2021/SQCSim2021.vcxproj
+++ b/SQCSim2021/SQCSim2021.vcxproj
@@ -20,6 +20,7 @@
+
@@ -36,6 +37,7 @@
+
diff --git a/SQCSim2021/SQCSim2021.vcxproj.filters b/SQCSim2021/SQCSim2021.vcxproj.filters
index 5c8a864..8246b5c 100644
--- a/SQCSim2021/SQCSim2021.vcxproj.filters
+++ b/SQCSim2021/SQCSim2021.vcxproj.filters
@@ -53,6 +53,9 @@
Fichiers d%27en-tête
+
+ Fichiers d%27en-tête
+
@@ -97,5 +100,8 @@
Fichiers sources
+
+ Fichiers sources
+
\ No newline at end of file
diff --git a/SQCSim2021/booster.cpp b/SQCSim2021/booster.cpp
new file mode 100644
index 0000000..cfef393
--- /dev/null
+++ b/SQCSim2021/booster.cpp
@@ -0,0 +1,46 @@
+#include "booster.h";
+
+void Booster::RenderBillboard(const Vector3f pos, TextureAtlas& textureAtlas, TextureAtlas::TextureIndex idx, Shader& shader, Transformation tran)
+{
+ //
+ //Vector3f playerToQuad = m_player.GetPosition() - m_position;
+ //playerToQuad.Normalize();
+ //Vector3f targetPosition = m_player.GetPosition() + playerToQuad * 10.0f;
+ //Matrix4f rotationMatrix;
+ //rotationMatrix.SetLookAt(m_position, targetPosition, Vector3f(0, 1, 0));
+ //glMultMatrixf(rotationMatrix.GetInternalValues());
+ float x = pos.x;
+ float y = pos.y;
+ float z = pos.z;
+ float width = 1.0f;
+ float height = 1.0f;
+ //Pt override les collisions.. a ce point la je sais pas quoi faire
+
+ //Matrix4 mat4 = tran.GetMatrix();
+ //mat4 VP = pMatrix * vMatrix;
+ //Vector3f CameraRight = Vector3f(mat4.Get11(), mat4.Get21(), mat4.Get31());
+ //Vector3f CameraUp = Vector3f(mat4.Get12(), mat4.Get22(), mat4.Get32());
+
+ //Vector3f v1 = (m_position + CameraRight * 0.5 * width + CameraUp * -0.5 * width);
+ //Vector3f v2 = (m_position + CameraRight * 0.5 * width + CameraUp * 0.5 * width);
+ //Vector3f v4 = (m_position + CameraRight * -0.5 * width + CameraUp * -0.5 * width);
+ //Vector3f v3 = (m_position + CameraRight * -0.5 * width + CameraUp * 0.5 * width);
+
+ //tran.ApplyTranslation(m_position);
+ float u, v, w, h;
+ //glDisable(GL_DEPTH_TEST);
+ shader.Use();
+ textureAtlas.Bind();
+ textureAtlas.TextureIndexToCoord(idx, u, v, w, h);
+ //glLoadIdentity();
+ glLoadMatrixf(tran.GetMatrix().GetInternalValues());
+ glBegin(GL_QUADS);
+ glTexCoord2f(u, v); glVertex3f(x - width / 2., y - height, z); //glVertex3f(v4.x, v4.y, v4.z);//glVertex3f(0, 50, 0);
+ glTexCoord2f(u + w, v); glVertex3f(x + width / 2., y - height, z); //glVertex3f(v3.x, v3.y, v3.z); //glVertex3f(50,50, 0);
+ glTexCoord2f(u + w, v + h); glVertex3f(x + width / 2., y, z); //glVertex3f(v2.x, v2.y, v2.z); //glVertex3f(50, 0, 0);
+ glTexCoord2f(u, v + h); glVertex3f(x - width / 2., y, z); //glVertex3f(v1.x, v1.y, v1.z);// glVertex3f(0, 0, 0);
+ glEnd();
+ shader.Disable();
+ //tran.ApplyTranslation(-m_position);
+ //glEnable(GL_DEPTH_TEST);
+}
\ No newline at end of file
diff --git a/SQCSim2021/booster.h b/SQCSim2021/booster.h
new file mode 100644
index 0000000..b9ff3b6
--- /dev/null
+++ b/SQCSim2021/booster.h
@@ -0,0 +1,14 @@
+#ifndef BOOSTER_H__
+#define BOOSTER_H__
+#include "define.h"
+#include "textureatlas.h"
+#include "shader.h"
+#include "../SQCSim-common/vector3.h"
+#include "../SQCSim-common/transformation.h"
+
+
+class Booster {
+public:
+ void RenderBillboard(const Vector3f pos, TextureAtlas& textureAtlas, TextureAtlas::TextureIndex idx, Shader& shader, Transformation tran);
+};
+#endif
diff --git a/SQCSim2021/define.h b/SQCSim2021/define.h
index e88b797..e268b20 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 8e8ef0d..ec3d73c 100644
--- a/SQCSim2021/engine.cpp
+++ b/SQCSim2021/engine.cpp
@@ -450,6 +450,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 "BoosterVert.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");
//AJOUTER LES TEXTURES DANS L'ORDRE DE L'ÉNUM
@@ -496,6 +500,15 @@ void Engine::LoadResource() {
m_blockinfo[BTYPE_METAL] = new BlockInfo(BTYPE_METAL, "Metal", u, v, s, 1);
m_textureAtlas.TextureIndexToCoord(texIceIndex, u, v, s, s);
m_blockinfo[BTYPE_ICE] = new BlockInfo(BTYPE_ICE, "Ice", u, v, s, 1);
+ m_textureAtlas.TextureIndexToCoord(texBoostHeal, u, v, s, s);
+ m_boostinfo[BTYPE_HEAL] = new BoostInfo(BTYPE_HEAL, "Heal", u, v, s, 1);
+ m_textureAtlas.TextureIndexToCoord(texBoostDmg, u, v, s, s);
+ m_boostinfo[BTYPE_DAMAGE] = new BoostInfo(BTYPE_DAMAGE, "Dmg", u, v, s, 1);
+ m_textureAtlas.TextureIndexToCoord(texBoostSpd, u, v, s, s);
+ m_boostinfo[BTYPE_SPEED] = new BoostInfo(BTYPE_SPEED, "Spd", u, v, s, 1);
+ m_textureAtlas.TextureIndexToCoord(texIceIndex, u, v, s, s);
+ m_boostinfo[BTYPE_INVINCIBLE] = new BoostInfo(BTYPE_INVINCIBLE, "Inv", u, v, s, 1);
+
m_animeAtlas.TextureIndexToCoord(0, u, v, s, s);
@@ -1181,9 +1194,8 @@ void Engine::Render(float elapsedTime) {
//m_remotePlayer.ApplyTransformation(remotePlayer, false);
m_world.Update(m_bullets, m_player.GetPosition(), m_blockinfo);
m_renderer.UpdateMesh(&m_world, m_player.GetPosition(), m_blockinfo);
-
- m_remotePlayer.Render(m_animeAtlas, m_shader01, all, elapsedTime);
-
+ m_remotePlayer.Render(m_textureAtlas, m_shader01, all, elapsedTime);
+ m_booster.RenderBillboard({ 120,20,120 }, m_textureAtlas, texBoostHeal, m_shader01, all);
if (m_isSkybox) m_renderer.RenderWorld(&m_world, m_renderCount, m_player.GetPosition(), m_player.GetDirection(), all, m_shader01, m_textureAtlas);
diff --git a/SQCSim2021/engine.h b/SQCSim2021/engine.h
index 142b8c7..712cd91 100644
--- a/SQCSim2021/engine.h
+++ b/SQCSim2021/engine.h
@@ -7,6 +7,7 @@
#include
#include "../SQCSim-common/array2d.h"
#include "../SQCSim-common/blockinfo.h"
+#include "../SQCSim-common/boostinfo.h"
#include "../SQCSim-common/bullet.h"
#include "../SQCSim-common/chunk.h"
#include "../SQCSim-common/world.h"
@@ -22,6 +23,7 @@
#include "connector.h"
#include "renderer.h"
#include "remoteplayer.h"
+#include "booster.h"
class Engine : public OpenglContext {
@@ -68,11 +70,13 @@ private:
Connector m_conn;
Shader m_shader01;
BlockInfo* m_blockinfo[BTYPE_LAST];
+ BoostInfo* m_boostinfo[BTYPE_BOOST_LAST];
TextureAtlas m_textureAtlas = TextureAtlas(BTYPE_LAST);
TextureAtlas m_animeAtlas = TextureAtlas(TYPE_LAST + POS_LAST);
World m_world = World();
Renderer m_renderer = Renderer();
+ Booster m_booster = Booster();
Texture m_textureCrosshair;
Texture m_textureFont;
@@ -84,6 +88,8 @@ private:
Texture m_textureMultiText;
Texture m_textureTitle;
+ TextureAtlas::TextureIndex texBoostHeal;
+
Skybox m_skybox;
Audio m_audio = Audio(AUDIO_PATH "start.wav");
diff --git a/SQCSim2021/media/textures/Booster/BoosterVert.png b/SQCSim2021/media/textures/Booster/BoosterVert.png
new file mode 100644
index 0000000..b731b74
Binary files /dev/null and b/SQCSim2021/media/textures/Booster/BoosterVert.png differ
diff --git a/SQCSim2021/remoteplayer.h b/SQCSim2021/remoteplayer.h
index 68376a7..e782000 100644
--- a/SQCSim2021/remoteplayer.h
+++ b/SQCSim2021/remoteplayer.h
@@ -8,7 +8,6 @@
#include "texture.h"
#include "openglcontext.h"
#include "vertexbuffer.h"
-#include "texture.h"
#include "../SQCSim-common/matrix4.h"
class RemotePlayer : public Player {
diff --git a/SQCSim2021/renderer.cpp b/SQCSim2021/renderer.cpp
index d2b9b30..3e5fc97 100644
--- a/SQCSim2021/renderer.cpp
+++ b/SQCSim2021/renderer.cpp
@@ -1,4 +1,9 @@
#include "renderer.h"
+#include
+#include
+
+#include
+#include
Renderer::Renderer() {
m_meshes.Reset(nullptr);
@@ -131,7 +136,8 @@ void Renderer::RenderWorld(World* origin, int& rendercount, const Vector3f& play
}
shader.Disable();
glStencilFunc(GL_GREATER, 1, 0xFF);
-};
+}
+
void Renderer::UpdateMesh(World* origin, const Vector3f& player, BlockInfo* blockinfo[BTYPE_LAST]) {
int cx = player.x;
@@ -238,6 +244,30 @@ void Renderer::UpdateMesh(World* origin, const Vector3f& player, BlockInfo* bloc
}
}
+void Renderer::RenderBillboard(const Vector3f pos, TextureAtlas textureAtlas, TextureAtlas::TextureIndex idx, Shader& shader, Transformation tran)
+{
+ //float x = pos.x;
+ //float y = pos.y;
+ //float z = pos.z;
+ //float width = 1.0f;
+ //float height = 1.0f;
+
+ //float u, v, w, h;
+ //shader.Use();
+ //textureAtlas.Bind();
+ //textureAtlas.TextureIndexToCoord(idx, u, v, w, h);
+
+ //glLoadMatrixf(tran.GetMatrix().GetInternalValues());
+ //glBegin(GL_QUADS);
+ //glTexCoord2f(u, v); glVertex3f(x - width / 2., y - height, z); //glVertex3f(v4.x, v4.y, v4.z);//glVertex3f(0, 50, 0);
+ //glTexCoord2f(u + w, v); glVertex3f(x + width / 2., y - height, z); //glVertex3f(v3.x, v3.y, v3.z); //glVertex3f(50,50, 0);
+ //glTexCoord2f(u + w, v + h); glVertex3f(x + width / 2., y, z); //glVertex3f(v2.x, v2.y, v2.z); //glVertex3f(50, 0, 0);
+ //glTexCoord2f(u, v + h); glVertex3f(x - width / 2., y, z); //glVertex3f(v1.x, v1.y, v1.z);// glVertex3f(0, 0, 0);
+ //glEnd();
+ //shader.Disable();
+}
+
+
void Renderer::RenderPlayer(Player* player, Transformation tran) const {
}
diff --git a/SQCSim2021/renderer.h b/SQCSim2021/renderer.h
index 0289baf..5a13709 100644
--- a/SQCSim2021/renderer.h
+++ b/SQCSim2021/renderer.h
@@ -9,6 +9,9 @@
#include "textureatlas.h"
#include "shader.h"
#include "remoteplayer.h"
+#include "openglcontext.h"
+#include "vertexbuffer.h"
+#include "../SQCSim-common/matrix4.h"
class Renderer {
private:
@@ -16,6 +19,7 @@ private:
TextureAtlas* m_playertext = nullptr;
Shader* m_playershader = nullptr;
+ bool test = true;
public:
Renderer();
@@ -25,6 +29,8 @@ public:
void UpdateMesh(World* origin, const Vector3f& player, BlockInfo* blockinfo[BTYPE_LAST]);
+ void RenderBillboard(const Vector3f pos, TextureAtlas textureAtlas, TextureAtlas::TextureIndex idx, Shader& shader, Transformation tran);
+
void RenderWorld(World* origin, int& rendercount, const Vector3f& player_pos, const Vector3f& player_dir, Transformation world, Shader& shader, TextureAtlas& atlas) const;
void RenderPlayer(Player* player, Transformation tran) const;
void RenderPlayer(RemotePlayer* rplayer, const Vector3f& player_pos, const Vector3f& player_dir) const;