From ec900f7410414278c48552540ea362082d58f5c7 Mon Sep 17 00:00:00 2001 From: Kenneth van Ewijk Date: Tue, 21 Jun 2016 16:58:39 +0200 Subject: [PATCH] Added health+damage to enemy --- CrystalPoint.vcxproj | 1 + CrystalPoint.vcxproj.filters | 3 +++ Enemy.cpp | 8 +++++++- Enemy.h | 4 +++- World.cpp | 10 ++++++++- weapons.json | 40 ++++++++++++++++++++++++++++++++++++ 6 files changed, 63 insertions(+), 3 deletions(-) create mode 100644 weapons.json diff --git a/CrystalPoint.vcxproj b/CrystalPoint.vcxproj index e9dff21..6435a83 100644 --- a/CrystalPoint.vcxproj +++ b/CrystalPoint.vcxproj @@ -222,6 +222,7 @@ + diff --git a/CrystalPoint.vcxproj.filters b/CrystalPoint.vcxproj.filters index 902a3bc..84737cb 100644 --- a/CrystalPoint.vcxproj.filters +++ b/CrystalPoint.vcxproj.filters @@ -238,6 +238,9 @@ Source Files\json + + Source Files\json + diff --git a/Enemy.cpp b/Enemy.cpp index 42e5019..b16231a 100644 --- a/Enemy.cpp +++ b/Enemy.cpp @@ -6,6 +6,8 @@ Enemy::Enemy(const std::string &fileName, const std::string &fileMusic, + float damage, + float health, const Vec3f &position, const Vec3f &rotation, const float &scale) @@ -18,7 +20,11 @@ Enemy::Enemy(const std::string &fileName, target = position; speed = 1; radius = 10; - xp = 10; + + xp = health; + this->health = health; + this->damage = damage; + hasTarget = false; hit_sound_id = CrystalPoint::GetSoundSystem().LoadSound(fileMusic.c_str(), false); music = CrystalPoint::GetSoundSystem().GetSound(hit_sound_id); diff --git a/Enemy.h b/Enemy.h index 61ab4f4..eb503b4 100644 --- a/Enemy.h +++ b/Enemy.h @@ -8,7 +8,7 @@ class Enemy : public Entity { public: - Enemy(const std::string &fileName, const std::string &fileMusic, const Vec3f &position, const Vec3f &rotation, const float &scale); + Enemy(const std::string &fileName, const std::string &fileMusic, float damage, float health, const Vec3f &position, const Vec3f &rotation, const float &scale); ~Enemy(); Sound* music; @@ -16,6 +16,8 @@ public: bool hasTarget; Vec3f target; float speed,radius; + float health; + float damage; int xp; bool attack; diff --git a/World.cpp b/World.cpp index ebf2d52..38548cb 100644 --- a/World.cpp +++ b/World.cpp @@ -126,12 +126,20 @@ World::World(const std::string &fileName) if (e["music"].isNull()) std::cout << "Invalid world file: enemies music - " << fileName << "\n"; + //Damage + if (e["damage"].isNull()) + std::cout << "Invalid world file: enemies damage - " << fileName << "\n"; + + //Health + if (e["health"].isNull()) + std::cout << "Invalid world file: enemies health - " << fileName << "\n"; + //Create Vec3f position(e["pos"][0].asFloat(), e["pos"][1].asFloat(), e["pos"][2].asFloat()); position.y = getHeight(position.x, position.z) + 2.0f; maxEnemies++; - enemies.push_back(new Enemy(e["file"].asString(), e["music"].asString(), position, rotation, scale)); + enemies.push_back(new Enemy(e["file"].asString(), e["music"].asString(), e["damage"].asFloat(), e["health"].asFloat(), position, rotation, scale)); } maxCrystals = 0; if (!v["crystal"].isNull()) diff --git a/weapons.json b/weapons.json new file mode 100644 index 0000000..1056000 --- /dev/null +++ b/weapons.json @@ -0,0 +1,40 @@ +{ + "weapons": [ + { + "name": "Fire reaper", + "damage": 1, + "element": "fire", + "file": "models/weapons/ZwaardMetTextures/TextureZwaard.obj", + + "anchor": [ -2.0, 6.0, -2.1 ], + "collision": [ 0, 0, 0 ], + "maxRotation": [ 170, 70 ], + "minRotation": [ 20, -80 ], + + "left": { + "offset": [ 4.5, -8, -1 ] + }, + "right": { + "offset": [ 0.5, -8, -1 ] + } + }, + { + "name": "Ice breaker", + "damage": 2, + "element": "ice", + "file": "models/weapons/ZwaardMetTextures/TextureZwaard.obj", + + "anchor": [ -2.0, 6.0, -2.1 ], + "collision": [ 0, 0, 0 ], + "maxRotation": [ 170, 70 ], + "minRotation": [ 20, -80 ], + + "left": { + "offset": [ 4.5, -8, -1 ] + }, + "right": { + "offset": [ 0.5, -8, -1 ] + } + } + ] +} \ No newline at end of file