Grog-Knight

some game in C++
Log | Files | Refs | Submodules | README | LICENSE | git clone https://git.ne02ptzero.me/git/Grog-Knight

commit 3a923c8d968826cd7936460005b2d44e90241cba
parent 38e2e5552fcfab05986d0ddc9af20ad9f1ba67e9
Author: Louis Solofrizzo <louis@ne02ptzero.me>
Date:   Thu, 26 Mar 2015 14:07:49 -0400

Merge pull request #7 from Ne02ptzero/build

Rebasing master.
Diffstat:
MAngel/Actors/PhysicsActor.cpp | 5+++++
MAngel/Actors/PhysicsActor.h | 4++++
MAngel/Actors/TextActor.cpp | 2++
MAngel/Infrastructure/TextRendering.cpp | 5+++--
MAngel/Infrastructure/World.cpp | 1+
MConfig/input_bindings.ini | 19+++++++++++++------
MMACOSX/Makefile | 3++-
MMakefile | 3++-
MMaps/MapBase.json | 177+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++----
MResources/Elements/Enemy.json | 12++++++++----
MResources/Elements/Hero.json | 51+++++++++++++++++++++++++++++++++++++--------------
AResources/Elements/Hitbox/enemyHitbox.json | 16++++++++++++++++
MResources/Elements/Hitbox/heroHitbox.json | 23++++++++++++-----------
AResources/Elements/Hitbox/platform_up.json | 16++++++++++++++++
AResources/Elements/Hitbox/slope_left.json | 16++++++++++++++++
MResources/Elements/Weapons/Bow.json | 2+-
MResources/Elements/Weapons/Sword.json | 2+-
AResources/Images/Castlevania-HarmonyOfDespair-Chapter5-SongOfTheUnslakableBlade.png | 0
MResources/Images/Enemy/enemy_000.png | 0
MResources/Images/Enemy/enemy_001.png | 0
MResources/Images/Enemy/enemy_002.png | 0
MResources/Images/Enemy/enemy_003.png | 0
MResources/Images/Enemy/enemy_004.png | 0
AResources/Images/Enemy/enemy_005.png | 0
AResources/Images/HUD/background_hud.png | 0
AResources/Images/HUD/gold.png | 0
AResources/Images/HUD/half_heart.png | 0
AResources/Images/HUD/heart.png | 0
AResources/Images/HUD/hp.png | 0
AResources/Images/HUD/map_bar_empty_end.png | 0
AResources/Images/HUD/mp.png | 0
AResources/Images/HUD/mp_bar_empty.png | 0
AResources/Images/HUD/mp_bar_end.png | 0
AResources/Images/HUD/mp_bar_first.png | 0
AResources/Images/HUD/mp_bar_full_end.png | 0
AResources/Images/HUD/mp_bar_mid.png | 0
AResources/Images/HUD/perso.png | 0
AResources/Images/HUD/quarter_and_half_heart.png | 0
AResources/Images/HUD/quarter_heart.png | 0
AResources/Images/HUD/star.png | 0
AResources/Images/HUD/xp.png | 0
AResources/Images/Hero/._sword_hit | 0
MResources/Images/Hero/hero_000.png | 0
MResources/Images/Hero/hero_001.png | 0
MResources/Images/Hero/hero_002.png | 0
MResources/Images/Hero/hero_003.png | 0
MResources/Images/Hero/hero_004.png | 0
MResources/Images/Hero/hero_005.png | 0
MResources/Images/Hero/hero_006.png | 0
MResources/Images/Hero/hero_007.png | 0
MResources/Images/Hero/hero_008.png | 0
MResources/Images/Hero/hero_009.png | 0
MResources/Images/Hero/hero_010.png | 0
MResources/Images/Hero/hero_011.png | 0
MResources/Images/Hero/hero_012.png | 0
MResources/Images/Hero/hero_013.png | 0
MResources/Images/Hero/hero_014.png | 0
MResources/Images/Hero/hero_015.png | 0
MResources/Images/Hero/hero_016.png | 0
MResources/Images/Hero/hero_017.png | 0
MResources/Images/Hero/hero_018.png | 0
MResources/Images/Hero/hero_019.png | 0
MResources/Images/Hero/hero_020.png | 0
MResources/Images/Hero/hero_021.png | 0
MResources/Images/Hero/hero_022.png | 0
MResources/Images/Hero/hero_023.png | 0
MResources/Images/Hero/hero_024.png | 0
MResources/Images/Hero/hero_025.png | 0
MResources/Images/Hero/hero_026.png | 0
MResources/Images/Hero/hero_027.png | 0
AResources/Images/Hero/hero_028.png | 0
AResources/Images/Hero/hero_029.png | 0
AResources/Images/Hero/hero_030.png | 0
AResources/Images/Hero/hero_031.png | 0
AResources/Images/Hero/hero_032.png | 0
AResources/Images/Hero/hero_033.png | 0
AResources/Images/Hero/hero_034.png | 0
AResources/Images/Hero/hero_035.png | 0
AResources/Images/Hero/hero_037.png | 0
AResources/Images/Hero/hero_038.png | 0
AResources/Images/Hero/hero_039.png | 0
AResources/Images/Hero/hero_040.png | 0
DResources/Images/Hero/old/hero_000.png | 0
DResources/Images/Hero/old/hero_001.png | 0
DResources/Images/Hero/old/hero_002.png | 0
DResources/Images/Hero/old/hero_003.png | 0
DResources/Images/Hero/old/hero_004.png | 0
DResources/Images/Hero/old/hero_005.png | 0
DResources/Images/Hero/old/hero_006.png | 0
DResources/Images/Hero/old/hero_007.png | 0
DResources/Images/Hero/old/hero_008.png | 0
DResources/Images/Hero/old/hero_009.png | 0
AResources/Images/bourse.png | 0
DResources/Images/mob1/static/mob1-static00.png | 0
DResources/Images/mob1/static/mob1-static01.png | 0
DResources/Images/mob1/static/mob1-static02.png | 0
DResources/Images/mob1/static/mob1-static03.png | 0
DResources/Images/mob1/static/mob1-static04.png | 0
AResources/weffrefe.png | 0
MSources/inc/Characters.hpp | 19++++++++++++++++---
MSources/inc/Consumable.hpp | 1-
MSources/inc/Elements.hpp | 15+++++++++------
MSources/inc/Enemy.hpp | 1+
MSources/inc/Equipment.hpp | 10++++++----
MSources/inc/Game.hpp | 17+++++++++++++++++
ASources/inc/HUDWindow.hpp | 73+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
MSources/inc/Hero.hpp | 5+++--
MSources/inc/Hitbox.hpp | 6+++++-
MSources/inc/LevelGenerator.hpp | 18++++++++++++++++--
MSources/inc/Object.hpp | 3---
MSources/inc/Projectile.hpp | 13+++++++++++--
MSources/inc/Room.hpp | 46+++++++++++++++++++++++++++++++++++-----------
MSources/inc/Weapon.hpp | 2+-
MSources/inc/main.hpp | 1+
MSources/src/Characters.cpp | 172++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-------------
MSources/src/Consumable.cpp | 25++++++++++++++-----------
MSources/src/Elements.cpp | 16+++++++++-------
MSources/src/Enemy.cpp | 55++++++++++++++++++++++++++++++++++++++++++++++---------
MSources/src/Equipment.cpp | 30++++++++++++++++++++++++------
MSources/src/Game.cpp | 99++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-------
ASources/src/HUDWindow.cpp | 194+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
MSources/src/Hero.cpp | 63+++++++++++++++++++++++++++++++++++++++++++++++++++++----------
MSources/src/Hitbox.cpp | 61++++++++++++++++++++++++++++++++++++++++++++++++++++++++-----
MSources/src/LevelGenerator.cpp | 211+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--
MSources/src/Map.cpp | 21++++++++++++++-------
MSources/src/Object.cpp | 9++++++---
MSources/src/Projectile.cpp | 57++++++++++++++++++++++++++++++++++++---------------------
MSources/src/Room.cpp | 84++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-
MSources/src/Shooter.cpp | 1-
MSources/src/Weapon.cpp | 25++++++++++++++++++-------
MSources/src/WeaponList.cpp | 8--------
MSources/src/main.cpp | 33++++++++++++++++++++++-----------
132 files changed, 1519 insertions(+), 232 deletions(-)

diff --git a/Angel/Actors/PhysicsActor.cpp b/Angel/Actors/PhysicsActor.cpp @@ -57,6 +57,11 @@ PhysicsActor::PhysicsActor(void) : void PhysicsActor::setId(int i) { this->_id = i; } + +void PhysicsActor::setBox(b2PolygonShape b) { + this->_box = b; +} + PhysicsActor::~PhysicsActor() { if( _physBody != NULL ) diff --git a/Angel/Actors/PhysicsActor.h b/Angel/Actors/PhysicsActor.h @@ -333,6 +333,10 @@ public: int getId(void) { return this->_id; }; /* END */ + /* Modified code by Noich 14/03/15 */ + void setBox(b2PolygonShape b); + /* END */ + protected: virtual void InitShape(b2Shape* /*shapeDef*/ ) {} b2Body *_physBody; diff --git a/Angel/Actors/TextActor.cpp b/Angel/Actors/TextActor.cpp @@ -58,6 +58,8 @@ void TextActor::Render() for(unsigned int i=0; i < _displayStrings.size(); i++) { DrawGameText(_displayStrings[i]._string, _fontNickname, (int)_displayStrings[i]._position.X, (int)_displayStrings[i]._position.Y, _rotation + theCamera.GetRotation()); + + std::cout << "Call DrawGameText('" << _displayStrings[i]._string << "', " << _fontNickname << "," << (int)_displayStrings[i]._position.X << "," << (int)_displayStrings[i]._position.Y << "," << _rotation + theCamera.GetRotation() << ");" << std::endl; } } diff --git a/Angel/Infrastructure/TextRendering.cpp b/Angel/Infrastructure/TextRendering.cpp @@ -107,6 +107,7 @@ Vector2 DrawGameText(const String& text, const String& nickname, int pixelX, int { Vector2 forReturn; + std::map<String,FTFont*>::iterator it = _fontCache.find(nickname); if (it == _fontCache.end()) { @@ -132,10 +133,10 @@ Vector2 DrawGameText(const String& text, const String& nickname, int pixelX, int glRotatef(angle, 0.0f, 0.0f, 1.0f); glEnable(GL_TEXTURE_2D); - glDisable(GL_DEPTH_TEST); + //glDisable(GL_DEPTH_TEST); it->second->Render(text.c_str()); glDisable(GL_TEXTURE_2D); - glEnable(GL_DEPTH_TEST); + //glEnable(GL_DEPTH_TEST); glPopMatrix(); glMatrixMode(GL_PROJECTION); diff --git a/Angel/Infrastructure/World.cpp b/Angel/Infrastructure/World.cpp @@ -650,6 +650,7 @@ void World::TickAndRender() Tick(); Game::destroyAllBodies(); Render(); + Game::showText(); } void World::Tick() diff --git a/Config/input_bindings.ini b/Config/input_bindings.ini @@ -1,16 +1,22 @@ ; This is the key-bindings file. ;; MOVEMENT - D = +forwardPressed - D = -forwardReleased - A = +backwardPressed - A = -backwardReleased + SPACE = +jumpPressed SPACE = -jumpReleased + RIGHT_ARROW = +forwardPressed + RIGHT_ARROW = -forwardReleased + LEFT_ARROW = +backwardPressed + LEFT_ARROW = -backwardReleased + + ;; ORENTATION - W = upPressed - S = downPressed + UP_ARROW = upPressed + DOWN_ARROW = downPressed ;; ATTACK E = +attackPressed E = -attackReleased + +;; OTHER ACTIONS + F = pickupItemPressed+ \ No newline at end of file diff --git a/MACOSX/Makefile b/MACOSX/Makefile @@ -22,7 +22,8 @@ SRCS = ../Sources/src/main.cpp \ ../Sources/src/Equipment.cpp \ ../Sources/src/Consumable.cpp \ ../Sources/src/Hitbox.cpp \ - ../Angel/Scripting/Interfaces/AngelLuaWrapping.cpp + ../Angel/Scripting/Interfaces/AngelLuaWrapping.cpp \ + ../Sources/src/HUDWindow.cpp \ OBJS = $(SRCS:.cpp=.o) diff --git a/Makefile b/Makefile @@ -75,7 +75,8 @@ SRCS = ./Sources/src/Elements.cpp \ ./Sources/src/Map.cpp \ ./Sources/src/Equipment.cpp \ ./Sources/src/Consumable.cpp \ - ./Sources/src/Hitbox.cpp + ./Sources/src/Hitbox.cpp \ + ./Sources/src/HUDWindow.cpp SYSOBJS = $(patsubst %.cpp,%.o,$(SYSSRCS)) OBJS = $(patsubst %.cpp,%.o,$(SRCS)) diff --git a/Maps/MapBase.json b/Maps/MapBase.json @@ -1,13 +1,13 @@ -{ "height":20, +{ "height":16, "layers":[ { - "data":[1, 2, 3, 1, 2, 3, 4, 5, 3, 4, 1, 2, 3, 4, 1, 1, 2, 3, 4, 5, 16, 17, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 26, 27, 64, 80, 81, 64, 16, 17, 31, 32, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 41, 42, 64, 95, 96, 64, 31, 32, 46, 47, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 56, 57, 64, 110, 111, 64, 46, 47, 16, 17, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 41, 42, 64, 125, 126, 64, 16, 17, 31, 32, 64, 64, 64, 64, 64, 64, 118, 107, 107, 107, 107, 107, 107, 107, 107, 124, 31, 32, 46, 47, 64, 64, 64, 64, 64, 64, 133, 122, 122, 122, 122, 122, 122, 122, 122, 122, 46, 47, 16, 17, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 56, 57, 64, 64, 64, 64, 16, 17, 31, 32, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 41, 42, 64, 64, 64, 64, 31, 32, 46, 47, 64, 36, 36, 36, 36, 37, 64, 64, 64, 64, 56, 57, 64, 64, 64, 64, 16, 17, 16, 17, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 41, 42, 64, 64, 64, 64, 31, 32, 31, 32, 64, 64, 64, 64, 64, 64, 64, 64, 36, 36, 71, 72, 37, 64, 64, 64, 46, 47, 46, 47, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 56, 57, 64, 64, 64, 64, 31, 32, 16, 17, 64, 64, 64, 36, 36, 36, 37, 64, 64, 64, 86, 87, 64, 64, 64, 64, 46, 47, 31, 32, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 56, 57, 64, 64, 64, 64, 16, 17, 46, 47, 64, 64, 64, 64, 64, 64, 80, 81, 64, 64, 41, 42, 64, 80, 81, 64, 31, 32, 16, 17, 106, 107, 108, 64, 64, 64, 95, 96, 64, 64, 56, 57, 64, 95, 96, 64, 16, 17, 31, 32, 121, 122, 123, 124, 64, 64, 110, 111, 64, 64, 41, 42, 64, 110, 111, 64, 16, 17, 46, 47, 121, 122, 122, 123, 124, 64, 125, 126, 64, 64, 56, 57, 64, 125, 126, 64, 31, 32, 142, 143, 144, 145, 146, 147, 148, 149, 150, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148], - "height":20, + "data":[10, 11, 12, 13, 14, 15, 11, 12, 13, 14, 11, 12, 13, 12, 13, 14, 11, 12, 11, 12, 13, 12, 11, 12, 13, 12, 13, 16, 17, 65, 80, 81, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 26, 27, 65, 65, 16, 17, 31, 32, 65, 95, 96, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 41, 42, 65, 65, 31, 32, 31, 32, 65, 110, 111, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 56, 57, 65, 65, 16, 17, 16, 17, 65, 125, 126, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 41, 42, 65, 65, 16, 17, 31, 32, 65, 36, 37, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 56, 57, 65, 65, 31, 32, 16, 17, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 36, 37, 65, 65, 65, 65, 65, 70, 71, 72, 65, 65, 16, 17, 31, 32, 65, 65, 65, 65, 65, 65, 36, 37, 65, 65, 65, 65, 65, 65, 65, 65, 65, 66, 67, 41, 42, 65, 65, 31, 32, 31, 32, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 64, 65, 65, 65, 65, 65, 65, 56, 57, 65, 65, 16, 17, 31, 32, 64, 65, 36, 37, 65, 65, 65, 65, 65, 65, 65, 65, 65, 36, 37, 65, 65, 65, 65, 41, 42, 65, 65, 31, 32, 16, 17, 64, 65, 65, 65, 65, 65, 36, 37, 65, 65, 65, 65, 65, 65, 64, 65, 65, 36, 37, 56, 57, 65, 65, 79, 79, 31, 32, 64, 80, 81, 65, 65, 65, 80, 81, 65, 65, 65, 80, 81, 65, 65, 65, 80, 81, 65, 86, 87, 80, 81, 79, 79, 31, 32, 65, 95, 96, 64, 65, 65, 95, 96, 65, 65, 65, 95, 96, 65, 36, 37, 95, 96, 65, 101, 102, 95, 96, 79, 79, 16, 17, 65, 110, 111, 65, 65, 65, 110, 111, 65, 65, 65, 110, 111, 65, 65, 65, 110, 111, 65, 116, 117, 118, 119, 119, 120, 31, 32, 65, 125, 126, 65, 65, 65, 125, 126, 64, 65, 65, 125, 126, 64, 65, 65, 125, 126, 65, 131, 132, 133, 134, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 148, 149], + "height":16, "name":"Tile Layer 1", "opacity":1, "type":"tilelayer", "visible":true, - "width":20, + "width":27, "x":0, "y":0 }], @@ -35,10 +35,26 @@ "tileheight":16, "tileproperties": { + "100": + { + "physic":"0" + }, + "101": + { + "physic":"0" + }, "102": { "physic":"0" }, + "103": + { + "physic":"0" + }, + "104": + { + "physic":"0" + }, "109": { "physic":"0" @@ -55,9 +71,21 @@ { "physic":"0" }, + "115": + { + "physic":"0" + }, + "116": + { + "physic":"0" + }, + "117": + { + "physic":"0" + }, "124": { - //"physic":"0" + "physic":"0" }, "125": { @@ -71,6 +99,14 @@ { "physic":"0" }, + "130": + { + "physic":"0" + }, + "131": + { + "physic":"0" + }, "25": { "physic":"0" @@ -83,6 +119,18 @@ { "physic":"0" }, + "35": + { + "hitbox":"platform_up" + }, + "36": + { + "hitbox":"platform_up" + }, + "37": + { + "hitbox":"platform_up" + }, "40": { "physic":"0" @@ -107,13 +155,81 @@ { "physic":"0" }, + "60": + { + "physic":"0" + }, + "61": + { + "physic":"0" + }, + "62": + { + "physic":"0" + }, + "63": + { + "physic":"0" + }, "64": { "physic":"0" }, + "65": + { + "physic":"0" + }, + "66": + { + "physic":"0" + }, + "67": + { + "physic":"0" + }, + "68": + { + "physic":"0" + }, + "69": + { + "hitbox":"platform_up" + }, + "70": + { + "hitbox":"platform_up" + }, + "71": + { + "hitbox":"platform_up" + }, "72": { - + "physic":"0" + }, + "73": + { + "physic":"0" + }, + "74": + { + "physic":"0" + }, + "75": + { + "physic":"0" + }, + "76": + { + "physic":"0" + }, + "77": + { + "physic":"0" + }, + "78": + { + "physic":"0" }, "79": { @@ -127,6 +243,18 @@ { "physic":"0" }, + "82": + { + "physic":"0" + }, + "83": + { + "physic":"0" + }, + "84": + { + "physic":"0" + }, "85": { "physic":"0" @@ -139,6 +267,30 @@ { "physic":"0" }, + "88": + { + "physic":"0" + }, + "89": + { + "physic":"0" + }, + "90": + { + "physic":"0" + }, + "91": + { + "physic":"0" + }, + "92": + { + "physic":"0" + }, + "93": + { + "physic":"0" + }, "94": { "physic":"0" @@ -150,11 +302,19 @@ "96": { "physic":"0" + }, + "97": + { + "hitbox":"platform_up" + }, + "98": + { + "hitbox":"platform_up" } }, "tilewidth":16 }], "tilewidth":16, "version":1, - "width":20 -} + "width":27 +}+ \ No newline at end of file diff --git a/Resources/Elements/Enemy.json b/Resources/Elements/Enemy.json @@ -2,15 +2,19 @@ "infos": { "name": "Enemy", "id": 1, - "HP": 50, + "HP": 10, "sprites": "Resources/Images/Enemy/enemy_000.png", "size": 1.3, - "maxSpeed": 5 + "maxSpeed": 5, + "hitboxType": "special", + "hitbox": "enemyHitbox" }, "Actions": { "breath": { - "beginFrame": 1, - "endFrame": 4, + "beginFrame_right": 1, + "endFrame_right": 4, + "beginFrame_left": 1, + "endFrame_left": 4, "time": 0.1 }, "jump": { diff --git a/Resources/Elements/Hero.json b/Resources/Elements/Hero.json @@ -6,35 +6,49 @@ "sprites": "Resources/Images/Hero/hero_000.png", "size": 1.3, "maxSpeed": 5, - "weapon": "Sword" + "weapon": "Sword", + "hitboxType": "special", + "hitbox": "heroHitbox" }, "Actions": { "forward": { "subscribe": "forward", - "beginFrame": 4, - "endFrame": 9, + "beginFrame": 20, + "endFrame": 27, "time": 0.1, - "force": 10 + "force": 7 }, "backward": { "subscribe": "backward", - "beginFrame": 10, - "endFrame": 15, + "beginFrame": 28, + "endFrame": 35, "time": 0.1, - "force": 10 + "force": 7 }, "jump": { "subscribe": "jump", "double": 1, "force": 6, - "rejump": 7, - "beginFrame": 16, - "fallingFrame": 23, - "endFrame": 27, + "rejump": 10, + "beginFrame_right": 4, + "beginFrame_left": 12, + "fallingFrame_right": 8, + "fallingFrame_left": 16, + "endFrame_right": 11, + "endFrame_left": 19, + "time": 0.1 + }, + "pickupItem": { + "subscribe": "pickupItem", + "beginFrame": 8, + "endFrame": 10, "time": 0.1 }, "attack": { - "subscribe": "attack" + "subscribe": "attack", + "beginFrame": 37, + "endFrame": 40, + "time": 0.5 }, "down": { "subscribe": "down" @@ -43,8 +57,17 @@ "subscribe": "up" }, "breath": { - "beginFrame": 1, - "endFrame": 3, + "beginFrame_right": 0, + "endFrame_right": 1, + "beginFrame_left": 2, + "endFrame_left": 3, + "time": 0.3 + }, + "takeDamage": { + "beginFrame_right": 0, + "endFrame_right": 1, + "beginFrame_left": 2, + "endFrame_left": 3, "time": 0.1 } } diff --git a/Resources/Elements/Hitbox/enemyHitbox.json b/Resources/Elements/Hitbox/enemyHitbox.json @@ -0,0 +1,16 @@ +{ + "data": { + "hitbox": [0,0,0,1,0,0,0,1,0,0,0, + 0,0,1,0,0,0,0,0,1,0,0, + 0,0,0,0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0,0,0,0, + 0,0,1,0,0,0,0,0,1,0,0, + 0,0,0,1,0,0,0,1,0,0,0], + "name": "enemyHitbox" + } +} diff --git a/Resources/Elements/Hitbox/heroHitbox.json b/Resources/Elements/Hitbox/heroHitbox.json @@ -1,15 +1,16 @@ { "data": { - "hitbox": [0,0,1,0,0,0,0,1,0,0, - 0,1,0,0,0,0,0,0,1,0, - 0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0, - 0,1,0,0,0,0,0,0,1,0, - 0,0,1,0,0,0,0,1,0,0], - "name": "hero" + "hitbox": [0,0,0,1,0,0,0,1,0,0,0, + 0,0,1,0,0,0,0,0,1,0,0, + 0,0,0,0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0,0,0,0, + 0,0,1,0,0,0,0,0,1,0,0, + 0,0,0,1,0,0,0,1,0,0,0], + "name": "heroHitbox" } } diff --git a/Resources/Elements/Hitbox/platform_up.json b/Resources/Elements/Hitbox/platform_up.json @@ -0,0 +1,16 @@ +{ + "data": { + "hitbox": [1,0,0,0,0,0,0,0,0,0,1, + 0,0,0,0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0,0,0,0, + 1,0,0,0,0,0,0,0,0,0,1, + 0,0,0,0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0,0,0,0], + "name": "platform_up" + } +} diff --git a/Resources/Elements/Hitbox/slope_left.json b/Resources/Elements/Hitbox/slope_left.json @@ -0,0 +1,16 @@ +{ + "data": { + "hitbox": [0,0,0,0,0,0,0,0,0,1,1, + 0,0,0,0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0,0,0,0, + 1,0,0,0,0,0,0,0,0,0,0, + 1,0,0,0,0,0,0,0,0,0,1], + "name": "slope_left" + } +} diff --git a/Resources/Elements/Weapons/Bow.json b/Resources/Elements/Weapons/Bow.json @@ -6,7 +6,7 @@ "size": 0.5, "active": 0.2, "lvlRequired": 1, - "damage": 0.5, + "damage": 2, "pushback": 1, "recovery": 0.1, "attack": "ranged", diff --git a/Resources/Elements/Weapons/Sword.json b/Resources/Elements/Weapons/Sword.json @@ -5,7 +5,7 @@ "hitbox": "SWORD", "size": 1, "lvlRequired": 1, - "damage": 1, + "damage": 5, "recovery": 1, "pushback": 5, "active": 0.2, diff --git a/Resources/Images/Castlevania-HarmonyOfDespair-Chapter5-SongOfTheUnslakableBlade.png b/Resources/Images/Castlevania-HarmonyOfDespair-Chapter5-SongOfTheUnslakableBlade.png Binary files differ. diff --git a/Resources/Images/Enemy/enemy_000.png b/Resources/Images/Enemy/enemy_000.png Binary files differ. diff --git a/Resources/Images/Enemy/enemy_001.png b/Resources/Images/Enemy/enemy_001.png Binary files differ. diff --git a/Resources/Images/Enemy/enemy_002.png b/Resources/Images/Enemy/enemy_002.png Binary files differ. diff --git a/Resources/Images/Enemy/enemy_003.png b/Resources/Images/Enemy/enemy_003.png Binary files differ. diff --git a/Resources/Images/Enemy/enemy_004.png b/Resources/Images/Enemy/enemy_004.png Binary files differ. diff --git a/Resources/Images/Enemy/enemy_005.png b/Resources/Images/Enemy/enemy_005.png Binary files differ. diff --git a/Resources/Images/HUD/background_hud.png b/Resources/Images/HUD/background_hud.png Binary files differ. diff --git a/Resources/Images/HUD/gold.png b/Resources/Images/HUD/gold.png Binary files differ. diff --git a/Resources/Images/HUD/half_heart.png b/Resources/Images/HUD/half_heart.png Binary files differ. diff --git a/Resources/Images/HUD/heart.png b/Resources/Images/HUD/heart.png Binary files differ. diff --git a/Resources/Images/HUD/hp.png b/Resources/Images/HUD/hp.png Binary files differ. diff --git a/Resources/Images/HUD/map_bar_empty_end.png b/Resources/Images/HUD/map_bar_empty_end.png Binary files differ. diff --git a/Resources/Images/HUD/mp.png b/Resources/Images/HUD/mp.png Binary files differ. diff --git a/Resources/Images/HUD/mp_bar_empty.png b/Resources/Images/HUD/mp_bar_empty.png Binary files differ. diff --git a/Resources/Images/HUD/mp_bar_end.png b/Resources/Images/HUD/mp_bar_end.png Binary files differ. diff --git a/Resources/Images/HUD/mp_bar_first.png b/Resources/Images/HUD/mp_bar_first.png Binary files differ. diff --git a/Resources/Images/HUD/mp_bar_full_end.png b/Resources/Images/HUD/mp_bar_full_end.png Binary files differ. diff --git a/Resources/Images/HUD/mp_bar_mid.png b/Resources/Images/HUD/mp_bar_mid.png Binary files differ. diff --git a/Resources/Images/HUD/perso.png b/Resources/Images/HUD/perso.png Binary files differ. diff --git a/Resources/Images/HUD/quarter_and_half_heart.png b/Resources/Images/HUD/quarter_and_half_heart.png Binary files differ. diff --git a/Resources/Images/HUD/quarter_heart.png b/Resources/Images/HUD/quarter_heart.png Binary files differ. diff --git a/Resources/Images/HUD/star.png b/Resources/Images/HUD/star.png Binary files differ. diff --git a/Resources/Images/HUD/xp.png b/Resources/Images/HUD/xp.png Binary files differ. diff --git a/Resources/Images/Hero/._sword_hit b/Resources/Images/Hero/._sword_hit Binary files differ. diff --git a/Resources/Images/Hero/hero_000.png b/Resources/Images/Hero/hero_000.png Binary files differ. diff --git a/Resources/Images/Hero/hero_001.png b/Resources/Images/Hero/hero_001.png Binary files differ. diff --git a/Resources/Images/Hero/hero_002.png b/Resources/Images/Hero/hero_002.png Binary files differ. diff --git a/Resources/Images/Hero/hero_003.png b/Resources/Images/Hero/hero_003.png Binary files differ. diff --git a/Resources/Images/Hero/hero_004.png b/Resources/Images/Hero/hero_004.png Binary files differ. diff --git a/Resources/Images/Hero/hero_005.png b/Resources/Images/Hero/hero_005.png Binary files differ. diff --git a/Resources/Images/Hero/hero_006.png b/Resources/Images/Hero/hero_006.png Binary files differ. diff --git a/Resources/Images/Hero/hero_007.png b/Resources/Images/Hero/hero_007.png Binary files differ. diff --git a/Resources/Images/Hero/hero_008.png b/Resources/Images/Hero/hero_008.png Binary files differ. diff --git a/Resources/Images/Hero/hero_009.png b/Resources/Images/Hero/hero_009.png Binary files differ. diff --git a/Resources/Images/Hero/hero_010.png b/Resources/Images/Hero/hero_010.png Binary files differ. diff --git a/Resources/Images/Hero/hero_011.png b/Resources/Images/Hero/hero_011.png Binary files differ. diff --git a/Resources/Images/Hero/hero_012.png b/Resources/Images/Hero/hero_012.png Binary files differ. diff --git a/Resources/Images/Hero/hero_013.png b/Resources/Images/Hero/hero_013.png Binary files differ. diff --git a/Resources/Images/Hero/hero_014.png b/Resources/Images/Hero/hero_014.png Binary files differ. diff --git a/Resources/Images/Hero/hero_015.png b/Resources/Images/Hero/hero_015.png Binary files differ. diff --git a/Resources/Images/Hero/hero_016.png b/Resources/Images/Hero/hero_016.png Binary files differ. diff --git a/Resources/Images/Hero/hero_017.png b/Resources/Images/Hero/hero_017.png Binary files differ. diff --git a/Resources/Images/Hero/hero_018.png b/Resources/Images/Hero/hero_018.png Binary files differ. diff --git a/Resources/Images/Hero/hero_019.png b/Resources/Images/Hero/hero_019.png Binary files differ. diff --git a/Resources/Images/Hero/hero_020.png b/Resources/Images/Hero/hero_020.png Binary files differ. diff --git a/Resources/Images/Hero/hero_021.png b/Resources/Images/Hero/hero_021.png Binary files differ. diff --git a/Resources/Images/Hero/hero_022.png b/Resources/Images/Hero/hero_022.png Binary files differ. diff --git a/Resources/Images/Hero/hero_023.png b/Resources/Images/Hero/hero_023.png Binary files differ. diff --git a/Resources/Images/Hero/hero_024.png b/Resources/Images/Hero/hero_024.png Binary files differ. diff --git a/Resources/Images/Hero/hero_025.png b/Resources/Images/Hero/hero_025.png Binary files differ. diff --git a/Resources/Images/Hero/hero_026.png b/Resources/Images/Hero/hero_026.png Binary files differ. diff --git a/Resources/Images/Hero/hero_027.png b/Resources/Images/Hero/hero_027.png Binary files differ. diff --git a/Resources/Images/Hero/hero_028.png b/Resources/Images/Hero/hero_028.png Binary files differ. diff --git a/Resources/Images/Hero/hero_029.png b/Resources/Images/Hero/hero_029.png Binary files differ. diff --git a/Resources/Images/Hero/hero_030.png b/Resources/Images/Hero/hero_030.png Binary files differ. diff --git a/Resources/Images/Hero/hero_031.png b/Resources/Images/Hero/hero_031.png Binary files differ. diff --git a/Resources/Images/Hero/hero_032.png b/Resources/Images/Hero/hero_032.png Binary files differ. diff --git a/Resources/Images/Hero/hero_033.png b/Resources/Images/Hero/hero_033.png Binary files differ. diff --git a/Resources/Images/Hero/hero_034.png b/Resources/Images/Hero/hero_034.png Binary files differ. diff --git a/Resources/Images/Hero/hero_035.png b/Resources/Images/Hero/hero_035.png Binary files differ. diff --git a/Resources/Images/Hero/hero_037.png b/Resources/Images/Hero/hero_037.png Binary files differ. diff --git a/Resources/Images/Hero/hero_038.png b/Resources/Images/Hero/hero_038.png Binary files differ. diff --git a/Resources/Images/Hero/hero_039.png b/Resources/Images/Hero/hero_039.png Binary files differ. diff --git a/Resources/Images/Hero/hero_040.png b/Resources/Images/Hero/hero_040.png Binary files differ. diff --git a/Resources/Images/Hero/old/hero_000.png b/Resources/Images/Hero/old/hero_000.png Binary files differ. diff --git a/Resources/Images/Hero/old/hero_001.png b/Resources/Images/Hero/old/hero_001.png Binary files differ. diff --git a/Resources/Images/Hero/old/hero_002.png b/Resources/Images/Hero/old/hero_002.png Binary files differ. diff --git a/Resources/Images/Hero/old/hero_003.png b/Resources/Images/Hero/old/hero_003.png Binary files differ. diff --git a/Resources/Images/Hero/old/hero_004.png b/Resources/Images/Hero/old/hero_004.png Binary files differ. diff --git a/Resources/Images/Hero/old/hero_005.png b/Resources/Images/Hero/old/hero_005.png Binary files differ. diff --git a/Resources/Images/Hero/old/hero_006.png b/Resources/Images/Hero/old/hero_006.png Binary files differ. diff --git a/Resources/Images/Hero/old/hero_007.png b/Resources/Images/Hero/old/hero_007.png Binary files differ. diff --git a/Resources/Images/Hero/old/hero_008.png b/Resources/Images/Hero/old/hero_008.png Binary files differ. diff --git a/Resources/Images/Hero/old/hero_009.png b/Resources/Images/Hero/old/hero_009.png Binary files differ. diff --git a/Resources/Images/bourse.png b/Resources/Images/bourse.png Binary files differ. diff --git a/Resources/Images/mob1/static/mob1-static00.png b/Resources/Images/mob1/static/mob1-static00.png Binary files differ. diff --git a/Resources/Images/mob1/static/mob1-static01.png b/Resources/Images/mob1/static/mob1-static01.png Binary files differ. diff --git a/Resources/Images/mob1/static/mob1-static02.png b/Resources/Images/mob1/static/mob1-static02.png Binary files differ. diff --git a/Resources/Images/mob1/static/mob1-static03.png b/Resources/Images/mob1/static/mob1-static03.png Binary files differ. diff --git a/Resources/Images/mob1/static/mob1-static04.png b/Resources/Images/mob1/static/mob1-static04.png Binary files differ. diff --git a/Resources/weffrefe.png b/Resources/weffrefe.png Binary files differ. diff --git a/Sources/inc/Characters.hpp b/Sources/inc/Characters.hpp @@ -29,7 +29,7 @@ # include "Weapon.hpp" # include "Log.hpp" -//class Weapon; +class Weapon; # ifdef __APPLE__ # include "../../Tools/jsoncpp/include/json/json.h" @@ -40,8 +40,8 @@ # include <list> # include "../../Angel/Angel.h" # ifndef __Elements__ -# include "Elements.hpp" -#endif +# include "Elements.hpp" +# endif class Characters : public Elements { @@ -65,6 +65,8 @@ class Characters : public Elements { virtual void EndContact(Elements *elem, b2Contact *contact); Characters::Orientation getOrientation(void); std::string getLastAction(void); + int getHP(void); + void setHP(int h); // Virtual function, overwritten in childs virtual void actionCallback(std::string name, int status) {}; virtual void equipWeapon(Weapon* weapon); @@ -78,10 +80,15 @@ class Characters : public Elements { int _maxSpeed; int _isJump; int _isRunning; + int _hp; + int _maxHp; bool _canMove; + bool _canJump; bool _invincibility; Weapon* _weapon; + Elements* _item; Characters::Orientation _orientation; + Characters::Orientation _latOrientation; std::list<Elements*> _grounds; std::list<Elements*> _wallsLeft; std::list<Elements*> _walls; @@ -96,7 +103,9 @@ class Characters : public Elements { virtual void _down(int status); virtual void _jump(int status); virtual void _attack(int status); + virtual void _pickupItem(int status); virtual void _run(void); + void _destroyEnemy(void); private: std::map<std::string, std::map<std::string, Json::Value> > _attr; @@ -106,6 +115,10 @@ class Characters : public Elements { void _parseJson(std::string file); }; +# ifndef __Object__ +# include "Equipment.hpp" +# endif + # include "Game.hpp" #endif diff --git a/Sources/inc/Consumable.hpp b/Sources/inc/Consumable.hpp @@ -36,7 +36,6 @@ public: Consumable(); ~Consumable(); - void init(void); void BeginContact(Elements *elem, b2Contact *contact); }; diff --git a/Sources/inc/Elements.hpp b/Sources/inc/Elements.hpp @@ -54,6 +54,7 @@ public: void display(void); std::map<std::string, std::string> getAttributes(void); void setFrameSprite(int frame); + void setHitbox(std::string); /* Virtual function, overridden in Childs */ virtual void callback(Elements * elem) { }; @@ -66,16 +67,18 @@ public: protected: virtual void _run() {}; + std::string _hitboxType; + std::string _hitbox; private: float _XStartPos; float _YStartPos; - std::map<std::string, std::string> _attributes; - int _height; - int _width; - int _cutHeight; - int _cutWidth; - int _frame; + std::map<std::string, std::string> _attributes; + int _height; + int _width; + int _cutHeight; + int _cutWidth; + int _frame; }; # include "Characters.hpp" diff --git a/Sources/inc/Enemy.hpp b/Sources/inc/Enemy.hpp @@ -34,6 +34,7 @@ public: Enemy(); ~Enemy(); + int takeDamage(int damage); void actionCallback(std::string name, int status); void init(void); void BeginContact(Elements* m, b2Contact* contact); diff --git a/Sources/inc/Equipment.hpp b/Sources/inc/Equipment.hpp @@ -26,19 +26,21 @@ #ifndef __Equipment__ # define __Equipment__ -# include "Elements.hpp" -# include "Hero.hpp" # include "WeaponList.hpp" # include "Object.hpp" +# include "Game.hpp" +# include "Elements.hpp" class Equipment : public Object { public: Equipment(); ~Equipment(); - void init(void); Weapon* getWeapon(void); - void BeginContact(Elements *elem, b2Contact *contact); + void BeginContact(Elements *elem, b2Contact *contact); + void EndContact(Elements *elem, b2Contact *contact); + void ReceiveMessage(Message* m); + private: Weapon* _weapon; }; diff --git a/Sources/inc/Game.hpp b/Sources/inc/Game.hpp @@ -39,7 +39,13 @@ class Maps; # include "ContactFilter.hpp" # include "Characters.hpp" # include "WeaponList.hpp" +# include "Hitbox.hpp" +# include "HUDWindow.hpp" + class WeaponList; +class Hitbox; +class HUDWindow; +class Characters; class Game { @@ -55,6 +61,9 @@ class Game { void displayEnemy(Elements & Enemy); void displayObject(Elements & Object); void showMap(void); + void displayHUD(void); + void setHero(Characters &h); + Characters &getHero(void); static void destroyAllBodies(void); static void addToDestroyList(Elements *m); @@ -68,17 +77,25 @@ class Game { static void startRunning(Elements *c); static void stopRunning(Elements *c); static void makeItRun(void); + static void showText(void); + static void addHUDWindow(HUDWindow *); + static void removeHUDWindow(HUDWindow *); + static HUDWindow* getHUD(void); + static int lol; Maps *maps; static int currentIds; static std::map<int, Elements *> elementMap; static std::list<Elements *> bodiesToDestroy; static std::list<Elements *> runningCharac; + static std::list<HUDWindow *> windows; static WeaponList* wList; + static Hitbox* hList; private: float beginXHero; float beginYHero; + Characters &_hero; }; diff --git a/Sources/inc/HUDWindow.hpp b/Sources/inc/HUDWindow.hpp @@ -0,0 +1,73 @@ + +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +/** + * File: HUDWindow.hpp + * Creation: 2015-03-14 05:35 + * Louis Solofrizzo <louis@ne02ptzero.me> + */ + +#ifndef __HUDWindow__ +# define __HUDWindow__ + +# include "../../Angel/Angel.h" +# include "Game.hpp" +class Game; + +# include <iostream> + +class HUDWindow : public HUDActor { + + class Text { + public: + Text() {}; + ~Text() {}; + std::string str; + int x; + int y; + int colorR; + int colorG; + int colorB; + int colorA; + }; + + public: + HUDWindow(void); + ~HUDWindow(void); + + void setText(std::string str, int x, int y); + void setText(std::string str, int x, int y, Vector3 color, int alpha); + void removeText(std::string str); + void displayText(void); + void addImage(std::string p, int x, int y); + void addImage(std::string path, int x, int y, float size); + void life(int l); + void mana(int mana); + void gold(int g); + void setGame(Game *); + + private: + Game *_g; + std::list<HUDActor *> _hearts; + std::list<HUDActor *> _mana; + std::list<HUDWindow::Text *> _text; +}; + +#endif diff --git a/Sources/inc/Hero.hpp b/Sources/inc/Hero.hpp @@ -26,8 +26,8 @@ #ifndef __Hero__ # define __Hero__ -# include "Characters.hpp" # include "Weapon.hpp" +# include "Characters.hpp" class Hero : public Characters { @@ -37,7 +37,8 @@ class Hero : public Characters { void init(); virtual void BeginContact(Elements* m, b2Contact* contact); + virtual void EndContact(Elements* m, b2Contact* contact); virtual void actionCallback(std::string name, int status); -}; +}; #endif diff --git a/Sources/inc/Hitbox.hpp b/Sources/inc/Hitbox.hpp @@ -32,11 +32,15 @@ class Hitbox { public: Hitbox(); ~Hitbox(); + b2PolygonShape getHitbox(std::string); + int checkExists(std::string); + private: b2PolygonShape _getPolygon(std::string res); b2PolygonShape _parseJson(std::string res); + b2PolygonShape _parseVertices(int v, std::vector<std::vector<int> >map); - std::list<b2PolygonShape> _hitboxes; + std::map<std::string, b2PolygonShape> _hitboxes; }; #endif diff --git a/Sources/inc/LevelGenerator.hpp b/Sources/inc/LevelGenerator.hpp @@ -30,8 +30,10 @@ # include <list> # include <cstdlib> # include <ctime> +# include <iostream> # include "Room.hpp" +# include "main.hpp" class LevelGenerator { @@ -39,7 +41,18 @@ class LevelGenerator { LevelGenerator(int height, int width, int minPathLenght, int roomPopRate, int doorsPopRate); ~LevelGenerator(); - void execute(); + void print(void); + void execute(); //execute generation process + void firstPass(); //generate base rooms + void secondPass(); //generate links + void thirdPass(); //delete isolated rooms + void fourthPass(); //generate entry + + void linkAdjacentRooms(Room *room); + void shockwave(); + int getEntryId(); + int addDistanceToAdjacentRooms(Room *room, int searchDistance); + Room *findRoomByPos(int x, int y); private: int _height; @@ -48,8 +61,9 @@ class LevelGenerator { int _minPathLenght; int _roomPopRate; int _doorsPopRate; + int _maxSearchDistance; std::vector<std::vector<int> > _graph; - std::list<Room> *_rooms; + std::vector<Room> *_rooms; LevelGenerator(); }; diff --git a/Sources/inc/Object.hpp b/Sources/inc/Object.hpp @@ -29,15 +29,12 @@ # include "Elements.hpp" # include "Hero.hpp" # include "WeaponList.hpp" -// # include "Equipment.hpp" -// # include "Consumable.hpp" class Object : public Elements { public: Object(); ~Object(); - void init(void); void BeginContact(Elements *elem, b2Contact *contact); }; diff --git a/Sources/inc/Projectile.hpp b/Sources/inc/Projectile.hpp @@ -50,7 +50,16 @@ public: void EndContact(Elements *elem, b2Contact *contact); void ReceiveMessage(Message *m); private: - Weapon* _weapon; -}; + void _initDirection(Weapon* w, Characters* c); + + std::string _name; + std::string _flavor; + std::string _attack; + float _active; + int _size; + int _damage; + int _pushback; + float _recovery; +}; #endif diff --git a/Sources/inc/Room.hpp b/Sources/inc/Room.hpp @@ -28,7 +28,7 @@ enum DepthType {CEIL, STD, FLOOR}; -enum SpecialType {ENTRY, BOSS, CHEST, MONSTER, MINIBOSS, ITEM}; +enum SpecialType {NONE, ENTRY, BOSS, CHEST, MONSTER, MINIBOSS, ITEM}; class Room { @@ -36,17 +36,41 @@ class Room { Room(int id, int x, int y, int mapId); ~Room(); + int getX() const; + int getY() const; + int getMapId() const; + int getId() const; + int getDistance() const; + int getLinks() const; + SpecialType getSpecialType() const; + bool getTopDoor() const; + bool getLeftDoor() const; + bool getBottomDoor() const; + bool getRightDoor() const; + + + void addLink(); + + void setTopDoor(bool state); + void setLeftDoor(bool state); + void setBottomDoor(bool state); + void setRightDoor(bool state); + void setDistance(int distance); + void setSpecialType(SpecialType type); + private: - int _id; - int _y; - int _x; - int _mapId; - DepthType _depthType; - SpecialType _specialType; - bool _topDoor; - bool _leftDoor; - bool _bottomDoor; - bool _rightDoor; + int _id; //uniqueid + int _y; //width position + int _x; //height position + int _mapId; //map prefab id + DepthType _depthType; //depth in level (Ceil => y = 0 / Floor => y = mapWidth / Std = other width) + SpecialType _specialType; //special type of room + int _distance; //distance from starting point for shockwave algorythm + int _links; //number of links between this room and surrounding ones + bool _topDoor; //has top door + bool _leftDoor; //has left door + bool _bottomDoor; //has bottom door + bool _rightDoor; //has right door Room(void); }; diff --git a/Sources/inc/Weapon.hpp b/Sources/inc/Weapon.hpp @@ -37,7 +37,6 @@ class Characters; - class Weapon: public Elements { public: Weapon(std::string name); @@ -72,6 +71,7 @@ private: int _size; int _damage; int _pushback; + void _initDirection(Weapon* w, Characters* c); void _readFile(std::string name); void _readFileFromFilename(std::string name); void _parseJson(std::string file); diff --git a/Sources/inc/main.hpp b/Sources/inc/main.hpp @@ -29,4 +29,5 @@ # define NAME "rogue-like" # include "Maps.hpp" + #endif diff --git a/Sources/src/Characters.cpp b/Sources/src/Characters.cpp @@ -40,15 +40,17 @@ Characters::Characters(std::string name) : _name(name), _isRunning(0), _isJump(0 this->addAttribute("physic", "1"); this->addAttribute("type", name); this->SetDensity(1.0f); - this->SetFriction(1.0f); + this->SetFriction(1); this->SetRestitution(0.0f); this->SetFixedRotation(true); this->_orientation = RIGHT; this->_readFile(name); this->_canMove = true; + this->_canJump = true; this->_invincibility = false; this->_grounds.clear(); this->_walls.clear(); + this->_item = nullptr; } /** @@ -71,7 +73,7 @@ void Characters::_readFile(std::string name) { fd.open(file.c_str()); if (!fd.is_open()) - Log::error("Can't open the file for the " + + Log::error("Can't open the file for the " + name + " class. (Supposed path is Resources/Elements/" + name +".json)"); buffer << fd.rdbuf(); this->_parseJson(buffer.str()); @@ -96,6 +98,10 @@ void Characters::_parseJson(std::string file) { this->_id = json["infos"].get("id", "").asInt(); this->_size = json["infos"].get("size", "").asFloat(); this->_maxSpeed = json["infos"].get("maxSpeed", "").asFloat(); + this->_hp = json["infos"].get("HP", "").asInt(); + this->_maxHp = json["infos"].get("HP", "").asInt(); + this->_hitboxType = json["infos"].get("hitboxType", "").asString(); + this->_hitbox = json["infos"].get("hitbox", "").asString(); this->addAttribute("spritesFrame", json["infos"].get("sprites", "").asString()); for (i = json["Actions"].begin(); i != json["Actions"].end(); i++) { @@ -104,7 +110,7 @@ void Characters::_parseJson(std::string file) { this->_attr[i.key().asString()] = tmp; // Subcribe to the broadcasts if (v.key().asString() == "subscribe") { - Log::info("SubscribeTo " + (*v).asString()); +// Log::info("SubscribeTo " + (*v).asString()); theSwitchboard.SubscribeTo(this, (*v).asString() + "Pressed"); theSwitchboard.SubscribeTo(this, (*v).asString() + "Released"); } @@ -159,10 +165,39 @@ void Characters::ReceiveMessage(Message *m) { int status; if (m->GetMessageName() == "canMove") { - this->_canMove = true; + this->changeCanMove(); } else if (m->GetMessageName() == "endInvincibility") { + theSwitchboard.UnsubscribeFrom(this, "colorDamageBlink1"); + theSwitchboard.UnsubscribeFrom(this, "colorDamageBlink2"); this->_invincibility = false; + this->SetColor(1,1,1,1); + } + else if (m->GetMessageName() == "colorDamageBlink1") { + theSwitchboard.DeferredBroadcast(new Message("colorDamageBlink2"), 0.1f); + this->SetColor(1,1,1,0.5f); + } + else if (m->GetMessageName() == "colorDamageBlink2") { + theSwitchboard.DeferredBroadcast(new Message("colorDamageBlink1"), 0.1f); + this->SetColor(1,0,0,0.9f); + } + else if (m->GetMessageName() == "startPathing") { + if (this->_grounds.size() > 0) { + if (this->_wallsLeft.size() > 0) + this->_orientation = RIGHT; + else if (this->_wallsRight.size() > 0) + this->_orientation = LEFT; + if (this->_orientation == RIGHT) + this->GetBody()->SetLinearVelocity(b2Vec2(5,0)); + if (this->_orientation == LEFT) + this->GetBody()->SetLinearVelocity(b2Vec2(-5,0)); + } + theSwitchboard.DeferredBroadcast(new Message("startPathing"), 0.2f); + return; + } + else if (m->GetMessageName() == "destroyEnemy") { + this->_destroyEnemy(); + return; } for (i = this->_attr.begin(); i != this->_attr.end(); i++) { attrName = this->_getAttr(i->first, "subscribe").asString(); @@ -184,6 +219,8 @@ void Characters::ReceiveMessage(Message *m) { this->_jump(status); } else if (attrName == "attack") { this->_attack(status); + } else if (attrName == "pickupItem") { + this->_pickupItem(status); } this->_lastAction = attrName; this->actionCallback(attrName, status); @@ -200,9 +237,19 @@ void Characters::AnimCallback(String s) { this->_setCategory("breath"); if (s == "base") { if (this->_isRunning == 0) { - this->PlaySpriteAnimation(this->_getAttr("time").asFloat(), SAT_OneShot, - this->_getAttr("beginFrame").asInt(), - this->_getAttr("endFrame").asInt(), "base"); + if (this->_latOrientation == LEFT) { + this->PlaySpriteAnimation(this->_getAttr("time").asFloat(), SAT_OneShot, + this->_getAttr("beginFrame_left").asInt(), + this->_getAttr("endFrame_left").asInt(), "base"); + } else if (this->_latOrientation == RIGHT) { + this->PlaySpriteAnimation(this->_getAttr("time").asFloat(), SAT_OneShot, + this->_getAttr("beginFrame_right").asInt(), + this->_getAttr("endFrame_right").asInt(), "base"); + } else { + this->PlaySpriteAnimation(this->_getAttr("time").asFloat(), SAT_OneShot, + this->_getAttr("beginFrame_right").asInt(), + this->_getAttr("endFrame_right").asInt(), "base"); + } } else { if (this->_isRunning == 1) { this->_setCategory("forward"); @@ -210,8 +257,8 @@ void Characters::AnimCallback(String s) { this->_setCategory("backward"); } this->PlaySpriteAnimation(this->_getAttr("time").asFloat(), SAT_Loop, - this->_getAttr("beginFrame").asInt(), - this->_getAttr("endFrame").asInt()); + this->_getAttr("beginFrame").asInt(), + this->_getAttr("endFrame").asInt()); } } } @@ -224,13 +271,19 @@ void Characters::AnimCallback(String s) { */ void Characters::BeginContact(Elements *elem, b2Contact *contact) { if (elem->getAttributes()["type"] == "ground") { - if (this->GetBody()->GetWorldCenter().y - 1 >= elem->GetBody()->GetWorldCenter().y) { + if (this->GetBody()->GetWorldCenter().y - 0.905 >= elem->GetBody()->GetWorldCenter().y) { if (this->_grounds.size() > 0) contact->SetEnabled(false); if (this->_isJump > 0) { this->_isJump = 0; - this->PlaySpriteAnimation(0.1f, SAT_OneShot, this->_getAttr("jump", "endFrame").asInt(), - this->_getAttr("jump", "endFrame").asInt(), "base"); + if (this->_latOrientation == RIGHT) + this->PlaySpriteAnimation(0.1f, SAT_OneShot, + this->_getAttr("jump", "endFrame_right").asInt() - 2, + this->_getAttr("jump", "endFrame_right").asInt(), "base"); + if (this->_latOrientation == LEFT) + this->PlaySpriteAnimation(0.1f, SAT_OneShot, + this->_getAttr("jump", "endFrame_left").asInt() - 2, + this->_getAttr("jump", "endFrame_left").asInt(), "base"); } this->_grounds.push_back(elem); } else if (this->GetBody()->GetWorldCenter().x >= elem->GetBody()->GetWorldCenter().x) { @@ -257,11 +310,17 @@ void Characters::EndContact(Elements *elem, b2Contact *contact) { this->_wallsRight.remove(elem); if (this->_grounds.size() == 1) { this->_grounds.remove(elem); - if (this->_grounds.size() == 0) + if (this->_grounds.size() == 0) { this->_isJump++; -// this->PlaySpriteAnimation(this->_getAttr("time").asFloat(), SAT_OneShot, -// this->_getAttr("jump", "fallingFrame").asInt(), -// this->_getAttr("jump", "endFallingFrame").asInt() - 1, "jump"); + if (this->_lastAction == "forward" && this->_canMove) + this->PlaySpriteAnimation(this->_getAttr("time").asFloat(), SAT_OneShot, + this->_getAttr("jump", "fallingFrame_right").asInt(), + this->_getAttr("jump", "endFrame_right").asInt() - 3, "jump"); + else if (this->_lastAction == "backward" && this->_canMove) + this->PlaySpriteAnimation(this->_getAttr("time").asFloat(), SAT_OneShot, + this->_getAttr("jump", "fallingFrame_left").asInt(), + this->_getAttr("jump", "endFrame_left").asInt() - 3, "jump"); + } } else this->_grounds.remove(elem); @@ -287,17 +346,27 @@ void Characters::_run(void) { */ void Characters::_forward(int status) { this->_setCategory("forward"); - if (status == 1){ + if (status == 1) { this->_orientation = RIGHT; - if (this->GetSpriteFrame() < this->_getAttr("beginFrame").asInt() && !this->_isJump) + this->_latOrientation = RIGHT; + if ((this->GetSpriteFrame() < this->_getAttr("beginFrame").asInt() || + (this->GetSpriteFrame() >= this->_getAttr("backward", "beginFrame").asInt() && + this->GetSpriteFrame() <= this->_getAttr("backward", "endFrame").asInt())) && !this->_isJump) this->PlaySpriteAnimation(this->_getAttr("time").asFloat(), SAT_Loop, - this->_getAttr("beginFrame").asInt(), - this->_getAttr("endFrame").asInt()); + this->_getAttr("beginFrame").asInt(), this->_getAttr("endFrame").asInt()); + else if (this->_isJump) { + this->_setCategory("jump"); + if (this->GetSpriteFrame() >= this->_getAttr("beginFrame_left").asInt() && this->GetSpriteFrame() <= this->_getAttr("endFrame_left").asInt()) + this->PlaySpriteAnimation(this->_getAttr("time").asFloat(), SAT_OneShot, + this->GetSpriteFrame() - 8, + this->_getAttr("endFrame_right").asInt() - 3, "jump"); + this->_setCategory("forward"); + } Game::startRunning(this); if (this->_isRunning == 2) this->GetBody()->SetLinearVelocity(b2Vec2(this->_getAttr("force").asFloat(), this->GetBody()->GetLinearVelocity().y)); this->_isRunning = 1; - } else if (status == 0) { + } else if (status == 0 && this->_latOrientation == RIGHT) { this->GetBody()->SetLinearVelocity(b2Vec2(0, this->GetBody()->GetLinearVelocity().y)); Game::stopRunning(this); this->_isRunning = 0; @@ -320,20 +389,29 @@ void Characters::_backward(int status) { this->_setCategory("backward"); if (status == 1) { this->_orientation = LEFT; + this->_latOrientation = LEFT; if (this->GetSpriteFrame() < this->_getAttr("beginFrame").asInt() && !this->_isJump) this->PlaySpriteAnimation(this->_getAttr("time").asFloat(), SAT_Loop, this->_getAttr("beginFrame").asInt(), this->_getAttr("endFrame").asInt()); + else if (this->_isJump) { + this->_setCategory("jump"); + if (this->GetSpriteFrame() >= this->_getAttr("beginFrame_right").asInt() && this->GetSpriteFrame() <= this->_getAttr("endFrame_right").asInt()) + this->PlaySpriteAnimation(this->_getAttr("time").asFloat(), SAT_OneShot, + this->GetSpriteFrame() + 8, + this->_getAttr("endFrame_left").asInt() - 3, "jump"); + this->_setCategory("backward"); + } Game::startRunning(this); if (this->_isRunning == 1) this->GetBody()->SetLinearVelocity(b2Vec2(-this->_getAttr("force").asFloat(), this->GetBody()->GetLinearVelocity().y)); this->_isRunning = 2; - } else if (status == 0) { + } else if (status == 0 && this->_latOrientation == LEFT) { this->GetBody()->SetLinearVelocity(b2Vec2(0, this->GetBody()->GetLinearVelocity().y)); + Game::stopRunning(this); + this->_isRunning = 0; if (!this->_isJump) this->AnimCallback("base"); - this->_isRunning = 0; - Game::stopRunning(this); } else { if (this->GetBody()->GetLinearVelocity().x > -(this->_maxSpeed)) { if (this->_wallsLeft.size() == 0 && this->_canMove == true) @@ -350,7 +428,8 @@ void Characters::_backward(int status) { void Characters::_jump(int status) { this->_setCategory("jump"); - if (status == 1) { + if (status == 1 && this->_canJump == true) { + this->_canJump = false; if (this->_isJump == 0 || (this->_isJump <= 1 && this->_getAttr("double").asInt() == 1)) { if (this->_isJump >= 1) { this->GetBody()->SetLinearVelocity(b2Vec2(this->GetBody()->GetLinearVelocity().x, this->_getAttr("rejump").asFloat())); @@ -358,13 +437,23 @@ void Characters::_jump(int status) { else { this->ApplyLinearImpulse(Vector2(0, this->_getAttr("force").asFloat()), Vector2(0, 0)); } - this->PlaySpriteAnimation(this->_getAttr("time").asFloat(), SAT_OneShot, - this->_getAttr("beginFrame").asInt(), - this->_getAttr("endFrame").asInt() - 1, "jump"); + if (this->_latOrientation == RIGHT) { + this->PlaySpriteAnimation(this->_getAttr("time").asFloat(), SAT_OneShot, + this->_getAttr("beginFrame_right").asInt(), + this->_getAttr("endFrame_right").asInt() - 3, "jump"); + } + else if (this->_latOrientation == LEFT) { + this->PlaySpriteAnimation(this->_getAttr("time").asFloat(), SAT_OneShot, + this->_getAttr("beginFrame_left").asInt(), + this->_getAttr("endFrame_left").asInt() - 3, "jump"); +} if (this->_grounds.size() == 0) this->_isJump++; } } + else if (status == 0) { + this->_canJump = true; + } return ; } @@ -393,15 +482,42 @@ void Characters::_down(int status) { * @param: status (int) */ void Characters::_attack(int status) { + this->_setCategory("attack"); + if (status == 1 && this->_weapon->attackReady() == 1) { this->_weapon->attack(this); + /* this->ChangeSizeTo(Vector2(2.0f, 2.0f), 4.0f);*/ + //this->PlaySpriteAnimation(this->_getAttr("time").asFloat(), SAT_OneShot, + //this->_getAttr("beginFrame").asInt(), + /*this->_getAttr("endFrame").asInt(), "base");*/ } } +void Characters::_pickupItem(int status) { + if (this->_item == nullptr) + return; + this->equipWeapon(static_cast<Equipment*>(this->_item)->getWeapon()); + this->_item = nullptr; + theSwitchboard.Broadcast(new Message("DeleteEquipment")); +} + void Characters::equipWeapon(Weapon* weapon) { this->_weapon = new Weapon(weapon); } +void Characters::setHP(int hp) { + if (hp > this->_maxHp) + this->_hp = this->_maxHp; + else + this->_hp = hp; +}; + +void Characters::_destroyEnemy(void) { + theSwitchboard.UnsubscribeFrom(this, "destroyEnemy"); + Game::addToDestroyList(this); +} + Characters::Orientation Characters::getOrientation(void) { return this->_orientation; } std::string Characters::getLastAction(void) { return this->_lastAction; }; +int Characters::getHP(void) { return this->_hp; }; void Characters::changeCanMove(void) { this->_canMove = (this->_canMove ? false : true); }; diff --git a/Sources/src/Consumable.cpp b/Sources/src/Consumable.cpp @@ -31,21 +31,24 @@ */ Consumable::Consumable(void) { this->addAttribute("type2", "Consumable"); - this->SetColor(1,1,1,1); - this->SetPosition(6, -11); + this->addAttribute("type3", "HP"); + this->addAttribute("value", "50"); + this->SetSprite("Resources/Images/HUD/heart.png"); + this->SetPosition(9, -4); this->InitPhysics(); theWorld.Add(this); - Log::info("wjorwbgurw"); } - +/** + * Collision begin callback + * @param: elem (Elements *) + * @param: contact (b2Contact *) + * @note: This function is called just before a collision + */ void Consumable::BeginContact(Elements *elem, b2Contact *contact) { - if (elem->getAttributes()["type"] == "Hero"){ - Game::bodiesToDestroy.push_back(this); - contact->SetEnabled(false); - } -} - -void Consumable::init(void) { + // if (elem->getAttributes()["type"] == "Hero"){ + // Game::bodiesToDestroy.push_back(this); + // contact->SetEnabled(false); + // } } /* diff --git a/Sources/src/Elements.cpp b/Sources/src/Elements.cpp @@ -29,7 +29,7 @@ /** * Main constructor */ -Elements::Elements(void) : PhysicsActor() { +Elements::Elements(int id) : PhysicsActor() { this->setId(Game::getNextId()); Game::addElement(*this); return ; @@ -38,7 +38,7 @@ Elements::Elements(void) : PhysicsActor() { /** * Main constructor */ -Elements::Elements(int id) : PhysicsActor() { +Elements::Elements(void) : PhysicsActor() { this->setId(Game::getNextId()); Game::addElement(*this); return ; @@ -121,8 +121,6 @@ void Elements::setFrameSprite(int frame) { void Elements::display(void) { this->SetPosition(this->_XStartPos, this->_YStartPos); this->Tag(this->getAttribute("type")); - //std::cout << "Add an object at: " << this->_XStartPos << ", " << this->_YStartPos << std::endl; - this->Tag(this->getAttribute("type")); if (this->getAttribute("sprite") != "") this->SetSprite(this->getAttribute("sprite")); else if (this->getAttribute("spritesFrame") != "") { @@ -139,15 +137,18 @@ void Elements::display(void) { this->SetFriction(1); this->SetRestitution(0); } - if (this->getAttribute("hero") == "1") { - this->SetShapeType(PhysicsActor::SHAPETYPE_HERO); + else if (this->getAttribute("type") == "Hero") + this->SetFriction(0.7f); + if (this->_hitboxType == "special") { + this->SetShapeType(PhysicsActor::SHAPETYPE_LOADED); + Game::hList->checkExists(this->_hitbox); + this->setBox(Game::hList->getHitbox(this->_hitbox)); } else { this->SetShapeType(PhysicsActor::SHAPETYPE_BOX); } if (this->getAttribute("physic") != "") { this->InitPhysics(); - std::cout << "Init phy" << std::endl; } theWorld.Add(this); } @@ -161,6 +162,7 @@ void Elements::setHeight(int h) { this->_height = h; }; void Elements::setCutWidth(int w) { this->_cutWidth = w; }; void Elements::setCutHeight(int h) { this->_cutHeight = h; }; void Elements::setFrame(int n) { this->_frame = n; }; +void Elements::setHitbox(std::string n) { this->_hitbox = n; this->_hitboxType = "special"; }; /* GETTERS */ std::map<std::string, std::string> Elements::getAttributes(void) { return this->_attributes; }; diff --git a/Sources/src/Enemy.cpp b/Sources/src/Enemy.cpp @@ -26,6 +26,8 @@ #include "../inc/Enemy.hpp" Enemy::Enemy(void) : Characters("Enemy") { + theSwitchboard.SubscribeTo(this, "startPathing"); + theSwitchboard.Broadcast(new Message("startPathing")); return ; } @@ -34,13 +36,14 @@ Enemy::Enemy(void) : Characters("Enemy") { */ Enemy::~Enemy(void) { return ; -} +} /** * Init Animation */ void Enemy::init(void) { this->AnimCallback("base"); + this->_orientation = RIGHT; } /** @@ -52,21 +55,55 @@ void Enemy::actionCallback(std::string name, int status) { return ; } +/** + * Collision begin callback + * @param: elem (Elements *) + * @param: contact (b2Contact *) + * @note: This function is called just before a collision + */ void Enemy::BeginContact(Elements* m, b2Contact *contact) { Characters::BeginContact(m, contact); Weapon* w = static_cast<Weapon*>(m); Projectile* p = static_cast<Projectile*>(m); if (m->getAttributes()["type"] == "HeroWeaponHitBox") { - if (this->GetBody()->GetWorldCenter().x > m->GetBody()->GetWorldCenter().x) { - this->ApplyLinearImpulse(Vector2(w->getPushback(), w->getPushback()), Vector2(0,0)); - } else { - this->ApplyLinearImpulse(Vector2(-w->getPushback(), w->getPushback()), Vector2(0,0)); + if (this->takeDamage(w->getDamage()) == 1) { + if (this->GetBody()->GetWorldCenter().x > m->GetBody()->GetWorldCenter().x) { + this->ApplyLinearImpulse(Vector2(w->getPushback(), w->getPushback()), Vector2(0,0)); + } else { + this->ApplyLinearImpulse(Vector2(-w->getPushback(), w->getPushback()), Vector2(0,0)); + } } } else if (m->getAttributes()["type"] == "HeroProjectile") { - if (this->GetBody()->GetWorldCenter().x > m->GetBody()->GetWorldCenter().x) { - this->ApplyLinearImpulse(Vector2(p->getPushback(), p->getPushback()), Vector2(0,0)); - } else { - this->ApplyLinearImpulse(Vector2(-p->getPushback(), p->getPushback()), Vector2(0,0)); + if (this->takeDamage(p->getDamage()) == 1) { + if (this->GetBody()->GetWorldCenter().x > m->GetBody()->GetWorldCenter().x) { + this->ApplyLinearImpulse(Vector2(p->getPushback(), p->getPushback()), Vector2(0,0)); + } else { + this->ApplyLinearImpulse(Vector2(-p->getPushback(), p->getPushback()), Vector2(0,0)); + } } + } else if (m->getAttributes()["type"] == "Hero") { + if (this->_orientation == LEFT) + this->_orientation = RIGHT; + else + this->_orientation = LEFT; + } +} + + +/** + * Function that applies damage + * @param: damage (int) + */ + +int Enemy::takeDamage(int damage) { + if (this->_hp - damage <= 0) { + this->GetBody()->SetLinearVelocity(b2Vec2(0, 0)); + this->PlaySpriteAnimation(0.1, SAT_OneShot, 5, 5, "destroyEnemy"); + theSwitchboard.SubscribeTo(this, "destroyEnemy"); + theSwitchboard.DeferredBroadcast(new Message("destroyEnemy"), 0.1); + theSwitchboard.UnsubscribeFrom(this, "startPathing"); + return 0; } + this->_hp -= damage; + return 1; } diff --git a/Sources/src/Equipment.cpp b/Sources/src/Equipment.cpp @@ -32,24 +32,42 @@ Equipment::Equipment(void) { this->addAttribute("type2", "Equipment"); this->SetColor(0,1,1,1); - this->SetPosition(5, -10); + this->SetPosition(5, -12); this->InitPhysics(); theWorld.Add(this); this->_weapon = new Weapon(Game::wList->getWeapon("Bow")); + theSwitchboard.SubscribeTo(this, "DeleteEquipment"); } +/** + * Collision begin callback + * @param: elem (Elements *) + * @param: contact (b2Contact *) + * @note: This function is called just before a collision + */ void Equipment::BeginContact(Elements *elem, b2Contact *contact) { if (elem->getAttributes()["type"] == "Hero"){ - TextActor *t; - //static_cast<Characters*>(elem)->equipWeapon(this->_weapon); + Game::getHUD()->setText(this->_weapon->getFlavor(), 450, 50); } } -void Equipment::init(void) { +/** + * End of contact + * @param: elem (Elements *) + * @param: contact (b2Contact *) + */ +void Equipment::EndContact(Elements *elem, b2Contact *contact) { + if (elem->getAttributes()["type"] == "Hero"){ + Game::getHUD()->removeText(this->_weapon->getFlavor()); + } } -Weapon* Equipment::getWeapon(void) { - return this->_weapon; +/*GETTERS*/ +Weapon* Equipment::getWeapon(void) { return this->_weapon; } + +void Equipment::ReceiveMessage(Message *m) { + if (m->GetMessageName() == "DeleteEquipment") + Game::addToDestroyList(this); } /* diff --git a/Sources/src/Game.cpp b/Sources/src/Game.cpp @@ -29,9 +29,14 @@ * Basic constructor, set the window to default value * (http://docs.angel2d.com/class_world.html#ae5d7e8d20d3e6fc93785ab2014ac0c13) */ -Game::Game(void) { - theWorld.Initialize(1920, 1080, NAME); - theWorld.SetupPhysics(); +Game::Game(void) : _hero(*(new Characters())) { + #ifdef __APPLE__ + theWorld.Initialize(1920, 1080, NAME, false, false); + #else + theWorld.Initialize(1024, 720, NAME, false, false); + //heWorld.Initialize(1600, 1200, NAME, false, false); + #endif + theWorld.SetupPhysics(Vector2(0, -20)); GameContactListener *gListen = new GameContactListener(); ContactFilter *filter = new ContactFilter(); theWorld.GetPhysicsWorld().SetContactFilter(filter); @@ -45,7 +50,7 @@ Game::Game(void) { * @param: width (unsigned int) * @param: heigh (unsigned int) */ -Game::Game(unsigned int width, unsigned int height) { +Game::Game(unsigned int width, unsigned int height) : _hero(*(new Characters())) { theWorld.Initialize(width, height, NAME); theWorld.SetupPhysics(); GameContactListener *gListen = new GameContactListener(); @@ -95,7 +100,7 @@ void Game::showMap(void) { * @param: Hero (Elements &) */ void Game::displayHero(Elements & Hero) { - Hero.setXStart(10); + Hero.setXStart(4); Hero.setYStart(-10); Hero.addAttribute("hero", "1"); Hero.display(); @@ -168,9 +173,9 @@ void Game::callCallbacks(int a, int b) { void Game::listElement(void) { int i; - for (i = 0; i < Game::currentIds; i++) { - std::cout << Game::elementMap[i] << std::endl; - } +// for (i = 0; i < Game::currentIds; i++) { +// std::cout << Game::elementMap[i] << std::endl; +// } } /** @@ -199,14 +204,27 @@ void Game::destroyAllBodies(void) { Game::bodiesToDestroy.clear(); } +/** + * Make an element running + * @param: c (Elements *) + * @note: This function do not make the element 'running', just add them to the callback list. + */ void Game::startRunning(Elements *c) { Game::runningCharac.push_back(c); } +/** + * Make an element stop running + * @param: c (Elements *) + * @note: Same as Game::startRunning(), but the object is remove from the list. + */ void Game::stopRunning(Elements *c) { Game::runningCharac.remove(c); } +/** + * The callback for each frame, making the call to the interns callbacks. + */ void Game::makeItRun(void) { std::list<Elements *>::iterator i; @@ -215,9 +233,74 @@ void Game::makeItRun(void) { } } +/** + * Callback for each frame, to display the text in the HUDs. + */ +void Game::showText(void) { + std::list<HUDWindow *>::iterator i; + + for (i = Game::windows.begin(); i != Game::windows.end(); i++) { + (*i)->displayText(); + } +} + +/** + * Add a HUDWindow object to the callback list + * @param: w (HUDWindow *) + */ +void Game::addHUDWindow(HUDWindow *w) { + if (std::find(Game::windows.begin(), Game::windows.end(), w) == Game::windows.end()) + Game::windows.push_back(w); +} + +/** + * Remove a HUDWindow from the callback list. + * @param: w (HUDWindow *) + */ +void Game::removeHUDWindow(HUDWindow *w) { + std::list<HUDWindow *>::iterator it; + + it = std::find(Game::windows.begin(), Game::windows.end(), w); + if (it != Game::windows.end()) + Game::windows.erase(it); +} + +/** + * Get the first HUD from the list. (Assuming there is an element) + */ +HUDWindow *Game::getHUD(void) { + return Game::windows.front(); +} + +/** + * The init function for display the base HUD. + */ +void Game::displayHUD(void) { + HUDWindow *w = new HUDWindow(); + w->SetPosition(theCamera.GetWindowWidth() / 2, 50); + w->SetSize(theCamera.GetWindowWidth(), 100.0f); + w->SetSprite("Resources/Images/HUD/background_hud.png"); + w->SetDrawShape(ADS_Square); + w->SetLayer(-1); + w->addImage("Resources/Images/HUD/perso.png", 100, 50); + theWorld.Add(w); + Game *g = this; + w->setGame(g); + w->life(125); + w->mana(90); + w->gold(200); + Game::addHUDWindow(w); +} + +/* SETTERS */ +void Game::setHero(Characters & h) { this->_hero = h; }; +Characters &Game::getHero(void) { return this->_hero; }; + // Set for the statics int Game::currentIds = 0; std::map<int, Elements *> Game::elementMap = {}; std::list<Elements *> Game::runningCharac; std::list<Elements *> Game::bodiesToDestroy; +std::list<HUDWindow *> Game::windows; WeaponList* Game::wList; +Hitbox* Game::hList; diff --git a/Sources/src/HUDWindow.cpp b/Sources/src/HUDWindow.cpp @@ -0,0 +1,194 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +/** + * File: HUDWindow.cpp + * Creation: 2015-03-14 05:35 + * Louis Solofrizzo <louis@ne02ptzero.me> + */ + +# include "HUDWindow.hpp" + +/** + * Basic constructor + */ +HUDWindow::HUDWindow(void) : HUDActor() { + return; +} + +/** + * Basic destructor + */ +HUDWindow::~HUDWindow(void) { + return; +} + +/** + * Set a text in the window + * @param: str (std::string) + * @param: x (int) + * @param: y (int) + */ +void HUDWindow::setText(std::string str, int x, int y) { + HUDWindow::Text *t = new HUDWindow::Text(); + t->str = str; + t->x = x; + t->y = y; + t->colorR = t->colorG = t->colorB = t->colorA = 1; + this->_text.push_back(t); +} + +/** + * Set a text in the window + * @param: str (std::string) + * @param: x (int) + * @param: y (int) + * @param: color (Vector3) + * @param: alpha (int) + * @note: This function is an overload of ^ + */ +void HUDWindow::setText(std::string str, int x, int y, Vector3 color, int alpha) { + HUDWindow::Text *t = new HUDWindow::Text(); + t->str = str; + t->x = x; + t->y = y; + t->colorR = color.X; + t->colorG = color.Y; + t->colorB = color.Z; + t->colorA = alpha; + this->_text.push_back(t); +} + +void HUDWindow::removeText(std::string str) { + std::list<HUDWindow::Text *>::iterator i; + + for (i = this->_text.begin(); i != this->_text.end(); i++) { + if ((*i)->str == str) + break ; + } + if (i != this->_text.end()) + this->_text.erase(i); +} + +/** + * Display a text in the HUD + */ +void HUDWindow::displayText(void) { + std::list<HUDWindow::Text *>::iterator i; + + for (i = this->_text.begin(); i != this->_text.end(); i++) { + glColor4f((*i)->colorR, (*i)->colorG, (*i)->colorB, (*i)->colorA); + DrawGameText((*i)->str, "Console", (*i)->x, (*i)->y, theCamera.GetRotation()); + } +} + +/** + * Add an image in the HUD + * @param: path (std::string) + * @param: x (int) + * @param: y (int) + */ +void HUDWindow::addImage(std::string path, int x, int y) { + HUDActor *tmp = new HUDActor(); + tmp->SetSprite(path); + tmp->SetPosition(x, y); + tmp->SetSize(50.0f); + tmp->SetDrawShape(ADS_Square); + tmp->SetLayer(100); + theWorld.Add(tmp); +} + +/** + * Add an image in the HUD + * @param: path (std::string) + * @param: x (int) + * @param: y (int) + * @param: size (float) + * @note: This function is an overload of ^ + */ +void HUDWindow::addImage(std::string path, int x, int y, float size) { + HUDActor *tmp = new HUDActor(); + tmp->SetSprite(path); + tmp->SetPosition(x, y); + tmp->SetSize(size); + tmp->SetDrawShape(ADS_Square); + tmp->SetLayer(100); + theWorld.Add(tmp); +} + +/** + * Life is life (lalala) + */ +void HUDWindow::life(int life) { + int x; + std::list<HUDActor *>::iterator i; + int index; + HUDActor *tmp; + + for (i = this->_hearts.begin(), index = 0; i != this->_hearts.end(); i++, index++) + theWorld.Remove(*(i)); + this->_hearts.clear(); + for (x = 200; life > 0; x += 25) { + if (x == 200) { + this->addImage("Resources/Images/HUD/hp.png", (x - 30), 35, 28.0f); + } if (life >= 25) { + tmp = new HUDActor(); + tmp->SetSprite("Resources/Images/HUD/heart.png"); + tmp->SetPosition(x, 35); + tmp->SetSize(30.0f); + theWorld.Add(tmp); + this->_hearts.push_back(tmp); + life -= 25; + } + } +} + +/** + * Show the mana in the HUD + */ +void HUDWindow::mana(int mana) { + std::list<HUDActor *>::iterator i; + int x = 200, y, max = 90; + + for (i = this->_mana.begin(); i != this->_mana.end(); i++) + theWorld.Remove(*(i)); + this->_mana.clear(); + this->addImage("Resources/Images/HUD/mp.png", (x - 30), 60, 26.0f); + this->addImage("Resources/Images/HUD/mp_bar_first.png", x, 60, 12.0f); + x += 11; + for (y = 0; y < (mana - 1); y += 10, x += 11) { + this->addImage("Resources/Images/HUD/mp_bar_mid.png", x, 60, 12.0f); + } + if (y == max) + this->addImage("Resources/Images/HUD/mp_bar_full_end.png", x, 60, 12.0f); + else + this->addImage("Resources/Images/HUD/mp_bar_end.png", x, 60, 12.0f); +} + +/** + * Make it rain baby + * @param: gold (int) + */ +void HUDWindow::gold(int gold) { + this->addImage("Resources/Images/HUD/xp.png", 340, 50, 20.0f); + this->addImage("Resources/Images/HUD/gold.png", 360, 50, 20.0f); + this->setText(std::to_string(gold), 380, 57); +} + +void HUDWindow::setGame(Game *g) { this->_g = g; }; diff --git a/Sources/src/Hero.cpp b/Sources/src/Hero.cpp @@ -23,7 +23,7 @@ * Louis Solofrizzo <louis@ne02ptzero.me> */ -# include "../inc/Hero.hpp" +# include "Hero.hpp" /** * Basic constructor @@ -58,24 +58,67 @@ void Hero::actionCallback(std::string name, int status) { return ; } +/** + * Collision begin callback + * @param: elem (Elements *) + * @param: contact (b2Contact *) + * @note: This function is called just before a collision + */ void Hero::BeginContact(Elements* elem, b2Contact *contact) { Characters::BeginContact(elem, contact); if (elem->getAttributes()["type"] == "Enemy") { - if (this->_invincibility == true) - return; this->GetBody()->SetLinearVelocity(b2Vec2(0, 0)); Game::stopRunning(this); this->_isRunning = 0; - //Damage here - Characters::changeCanMove(); - this->_invincibility = true; - theSwitchboard.DeferredBroadcast(new Message("canMove"), 1); - theSwitchboard.DeferredBroadcast(new Message("endInvincibility"), 1); + this->_isJump = 1; + if (this->_invincibility == false) { + this->changeCanMove(); + this->setHP(this->getHP() - 25); + theSwitchboard.DeferredBroadcast(new Message("canMove"), 0.5f); + theSwitchboard.DeferredBroadcast(new Message("endInvincibility"), 1); + Game::getHUD()->life(this->getHP()); + } if (this->GetBody()->GetWorldCenter().x >= elem->GetBody()->GetWorldCenter().x) { - this->ApplyLinearImpulse(Vector2(10, 10), Vector2(0, 0)); + this->ApplyLinearImpulse(Vector2(4, 4), Vector2(0, 0)); + this->PlaySpriteAnimation(this->_getAttr("time").asFloat(), SAT_Loop, + this->_getAttr("takeDamage", "beginFrame_right").asInt(), + this->_getAttr("takeDamage", "endFrame_right").asInt(), + "takeDamage"); } else if (this->GetBody()->GetWorldCenter().x < elem->GetBody()->GetWorldCenter().x) { - this->ApplyLinearImpulse(Vector2(-10, 10), Vector2(0, 0)); + this->ApplyLinearImpulse(Vector2(-4, 4), Vector2(0, 0)); + this->PlaySpriteAnimation(this->_getAttr("time").asFloat(), SAT_Loop, + this->_getAttr("takeDamage", "beginFrame_left").asInt(), + this->_getAttr("takeDamage", "endFrame_left").asInt(), + "takeDamage"); + } + this->SetColor(1,0,0,0.8f); + theSwitchboard.SubscribeTo(this, "colorDamageBlink1"); + theSwitchboard.SubscribeTo(this, "colorDamageBlink2"); + theSwitchboard.DeferredBroadcast(new Message("colorDamageBlink1"), 0.1f); + this->_invincibility = true; + } + else if (elem->getAttributes()["type"] == "Object") { + if (elem->getAttributes()["type2"] == "Consumable") { + if (elem->getAttributes()["type3"] == "HP") { + if (this->_hp != this->_maxHp) { + Game::addToDestroyList(elem); + this->setHP(this->getHP() + 50); + Game::getHUD()->life(this->getHP()); + } + } + } + else if (elem->getAttributes()["type2"] == "Equipment") { + this->_item = elem; + } + } +} + +void Hero::EndContact(Elements *elem, b2Contact *contact) { + Characters::EndContact(elem, contact); + if (elem->getAttributes()["type"] == "Object") { + if (elem->getAttributes()["type2"] == "Equipment") { + this->_item = nullptr; } } } diff --git a/Sources/src/Hitbox.cpp b/Sources/src/Hitbox.cpp @@ -41,7 +41,8 @@ Hitbox::Hitbox(void) { if (dirEntry && strcmp(dirEntry->d_name, ".") && strcmp(dirEntry->d_name, "..")) { iss.str(dirEntry->d_name); std::getline(iss, res, '.'); - this->_hitboxes.push_back(this->_getPolygon(res)); + Log::info("Parsing " + res + " hitbox"); + this->_hitboxes[res] = this->_getPolygon(res); } } } @@ -64,7 +65,7 @@ b2PolygonShape Hitbox::_parseJson(std::string file) { Json::Reader read; Json::Value json; Json::Value hitbox; - int v, i, j; + int v, i, j, vertices = 0; std::vector<std::vector<int> > map; std::vector<int> tmp; @@ -73,7 +74,7 @@ b2PolygonShape Hitbox::_parseJson(std::string file) { hitbox = json["data"]["hitbox"]; for (v = i = j = 0; i < hitbox.size(); i++, v++) { - if (v == 10) { + if (v == 11) { map.insert(map.begin() + j, tmp); j++; v = 0; @@ -85,12 +86,62 @@ b2PolygonShape Hitbox::_parseJson(std::string file) { std::vector<std::vector<int> >::iterator itr; std::vector<int>::iterator itr2; + for (itr = map.begin(); itr != map.end(); itr++) { for (itr2 = (*itr).begin(); itr2 != (*itr).end(); itr2++) { - std::cout << (*itr2) << ", "; +// std::cout << (*itr2) << ", "; + if ((*itr2) == 1) + vertices++; } - std::cout << std::endl; +// std::cout << std::endl; } + + if (vertices < 4 || vertices > 8) + Log::error(json["data"]["name"].asString() + " contains an invalid hitbox"); + return this->_parseVertices(vertices, map); +} + +b2PolygonShape Hitbox::_parseVertices(int v, std::vector<std::vector<int> > map) { + std::vector<std::vector<int> >::iterator itr; + std::vector<int>::iterator itr2; + std::vector<std::vector<int> >::reverse_iterator ritr; + std::vector<int>::reverse_iterator ritr2; + b2Vec2 vertices[v]/* = new b2Vec2[v]*/; + b2PolygonShape box; + int i = 0; + float x2, y2, x, y = 0; + + for (itr = map.begin(); itr != map.end(); itr++, y++) { + for (itr2 = (*itr).begin(), x = 0; itr2 != (*itr).end(); itr2++, x++) { + if ((*itr2) == 1) { +// std::cout << x - 5 << ":" << -(y - 5) << std::endl; + vertices[i].Set((x - 5) / 10, -(y - 5)/ 10 ); + i++; + x = 0; + break ; + } + } + } + for (ritr = map.rbegin(), y = 10; ritr != map.rend(); ritr++, y--) { + for (ritr2 = (*ritr).rbegin(), x = 10; ritr2 != (*ritr).rend(); ritr2++, x--) { + if ((*ritr2) == 1) { + vertices[i].Set((x - 5) / 10, -(y - 5)/ 10 ); +// std::cout << x - 5 << ":" << -(y - 5) << std::endl; + i++; + break ; + } + } + } + box.Set(vertices, i); + return box; +} + +int Hitbox::checkExists(std::string n) { + return 1; +} + +b2PolygonShape Hitbox::getHitbox(std::string n) { + return this->_hitboxes[n]; } /** diff --git a/Sources/src/LevelGenerator.cpp b/Sources/src/LevelGenerator.cpp @@ -27,12 +27,18 @@ # include "../inc/Room.hpp" /** - * Basic constructor + * Standard constructor with : + * - Height and Width + * - minPathLenght : Min path between entry and exit rooms + * - roomPopRate (of 100%) : Chances for a room to pop on given slot + * - doorsPopRate (of 100%) : Chances for a door to pop on given wall + * - nbMaps : Number of different maps */ LevelGenerator::LevelGenerator(int height, int width, int minPathLenght, int roomPopRate, int doorsPopRate) : _height(height), _width(width), _minPathLenght(minPathLenght), _roomPopRate(roomPopRate), _doorsPopRate(doorsPopRate) { srand(time(NULL)); - _rooms = new std::list<Room>; + _rooms = new std::vector<Room>; _nbMaps = 10; + _maxSearchDistance = height * width / 2; return ; } @@ -44,14 +50,211 @@ LevelGenerator::~LevelGenerator(void) { } void LevelGenerator::execute(void) { - int id = 0; + firstPass(); + secondPass(); + print(); + thirdPass(); + fourthPass(); + shockwave(); +} + +void LevelGenerator::print(void) { + int n = 0; + Log::info("Printing generated level : debug displays the number of links between rooms"); + for (int i = 0; i < _width; i++) { + for (int j = 0; j < _height; j++) { + if (n < _rooms->size()) { + Room room = _rooms->at(n); + if (room.getX() == j && room.getY() == i) { + std::cout << room.getDistance(); + n++; + } + else + std::cout << "-"; + std::cout << " "; + } + else + std::cout << "- "; + } + std::cout << std::endl; + } +} + +//Generating base level with random rooms +void LevelGenerator::firstPass(void) { + int id = 0; for (int i = 0; i < _width; i++) { for (int j = 0; j < _height; j++) { - if (_roomPopRate < (rand() % 100)) { + if (_roomPopRate > (rand() % 100)) { Room *newRoom = new Room(id, i, j, rand() % _nbMaps); _rooms->push_back(*newRoom); + id++; + } + } + } +} + +//Linking rooms beteween them +void LevelGenerator::secondPass(void) { + int n = 0; + int size = _rooms->size(); + for (int i = 0; i < _width; i++) { + for (int j = 0; j < _height; j++) { + if (n < size) { + Room *room = &_rooms->at(n); + if (room->getX() == j && room->getY() == i) { + linkAdjacentRooms(room); + n++; + } } } } } + +// 3rd pass => supprimer les salles avec 0 liens +// 4th pass => shockwave pour tester que toutes les rooms sont reachable +// 5th pass => tester si on peut ajouter des rooms pour rendre reachable +// restart si ca foire +// 6th pass => ajouter entree +// 7th pass => shockwave depuis entree +// 8th pass => ajouter salle du boss +// 9th pass => ajouter salles speciales + +//Deleting isolated rooms +void LevelGenerator::thirdPass(void) { + int size = _rooms->size(); + int deleted = 0; + for(int i = 0; i + deleted < size; i++) { + Room *room = &_rooms->at(i); + if (room->getLinks() == 0){ + std::cout << "erase room n" << room->getId() << std::endl; + _rooms->erase(_rooms->begin() + i); + deleted++; + i--; + } + } +} + +//Creating entry room +void LevelGenerator::fourthPass(void) { + int size = _rooms->size(); + Room *room = &_rooms->at(rand() % size); + room->setSpecialType(ENTRY); + room->setDistance(1); +} + +//Computing distance between entry and other rooms +void LevelGenerator::shockwave() { + int size = _rooms->size(); + int searchDistance = 1; + while(searchDistance < _maxSearchDistance) { + for(int i = 0; i < size; i++) { + Room *room = &_rooms->at(i); + if (room->getDistance() == searchDistance) { + addDistanceToAdjacentRooms(room, searchDistance); + } + } + searchDistance++; + } +} + +int LevelGenerator::addDistanceToAdjacentRooms(Room *room, int searchDistance) { + int x = room->getX(); + int y = room->getY(); + bool top = room->getTopDoor(); + bool left = room->getLeftDoor(); + bool bottom = room->getBottomDoor(); + bool right = room->getRightDoor(); + int toReturn; + + if (top == true) { + Room *topRoom = findRoomByPos(x, y - 1); + int distance = topRoom->getDistance(); + if (distance != 0 && distance < searchDistance) + toReturn += 0; + else { + topRoom->setDistance(searchDistance + 1); + toReturn += 1; + } + } + if (left == true) { + Room *leftRoom = findRoomByPos(x - 1, y); + int distance = leftRoom->getDistance(); + if (distance != 0 && distance < searchDistance) + toReturn += 0; + else { + leftRoom->setDistance(searchDistance + 1); + toReturn += 1; + } + } + if (bottom == true) { + Room *bottomRoom = findRoomByPos(x, y + 1); + int distance = bottomRoom->getDistance(); + if (distance != 0 && distance < searchDistance) + toReturn += 0; + else { + bottomRoom->setDistance(searchDistance + 1); + toReturn += 1; + } + } + if (right == true) { + Room *rightRoom = findRoomByPos(x + 1, y); + int distance = rightRoom->getDistance(); + if (distance != 0 && distance < searchDistance) + toReturn += 0; + else { + rightRoom->setDistance(searchDistance + 1); + toReturn += 1; + } + } + return toReturn; +} + +Room *LevelGenerator::findRoomByPos(int x, int y) { + int size = _rooms->size(); + for(int i = 0; i < size; i++) { + Room *room = &_rooms->at(i); + if (room->getX() == x && room->getY() == y) { + return room; + } + } + return NULL; +} + +int LevelGenerator::getEntryId() { + int size = _rooms->size(); + for(int i = 0; i < size; i++) { + Room *room = &_rooms->at(i); + if (room->getSpecialType() == ENTRY) { + std::cout << "ENTRY found in " << room->getY() << "." << room->getX() << std::endl; + return i; + } + } +} + +void LevelGenerator::linkAdjacentRooms(Room *room) { + for (int n = 0; n < _rooms->size(); ++n) { + Room *tmp = &_rooms->at(n); + if (room->getY() == tmp->getY() && room->getX() == tmp->getX() - 1 ) { + room->setRightDoor(true); + tmp->setLeftDoor(true); + room->addLink(); + } + else if (room->getY() == tmp->getY() && room->getX() == tmp->getX() + 1 ) { + room->setLeftDoor(true); + tmp->setRightDoor(true); + room->addLink(); + } + else if (room->getY() == tmp->getY() - 1 && room->getX() == tmp->getX()) { + room->setBottomDoor(true); + tmp->setTopDoor(true); + room->addLink(); + } + else if (room->getY() == tmp->getY() + 1 && room->getX() == tmp->getX()) { + room->setTopDoor(true); + tmp->setBottomDoor(true); + room->addLink(); + } + } +} diff --git a/Sources/src/Map.cpp b/Sources/src/Map.cpp @@ -36,7 +36,7 @@ Map::Map(void) : _mapCount(0) { * Main constructor */ Map::Map(std::string name) : _name(name), _mapCount(0) { - std::cout << name << std::endl; +// std::cout << name << std::endl; return ; } @@ -84,7 +84,6 @@ void Map::display(void) { elem = new Elements(); elem->removeAttr("physic"); elem->addAttribute("image", this->_image); - std::cout << this->_image << std::endl; elem->setFrame(*(it)); elem->setXStart(x); elem->setYStart(y); @@ -92,17 +91,25 @@ void Map::display(void) { elem->setCutHeight(this->_tileHeight); elem->setWidth(this->_imageWidth); elem->setHeight(this->_imageHeight); - std::cout << this->_imageHeight << std::endl; elem->addAttribute("type", "ground"); elem->addAttribute("spriteMap", "TRUE"); if (this->_properties.find(*it) == this->_properties.end()) { elem->addAttribute("physic", "TRUE"); - std::cout << "Ph elem ("<< *it << "):" << x << ", " << y << std::endl; } else { - std::cout << "===== HERE ====\n" << *it << std::endl; + std::map<std::string, Json::Value>::iterator it2; + int isPhysic = 1; + + for (it2 = this->_properties.find(*it)->second.begin(); + it2 != this->_properties.find(*it)->second.end(); it2++) { + if (it2->first == "physic") { + isPhysic = 0; + } else if (it2->first == "hitbox") { + elem->setHitbox(it2->second.asString()); + } + } + if (isPhysic) + elem->addAttribute("physic", "TRUE"); } - std::cout << "NEW ELEM" << std::endl; elem->display(); } - //exit(0); } diff --git a/Sources/src/Object.cpp b/Sources/src/Object.cpp @@ -40,6 +40,12 @@ Object::Object(void) { this->SetIsSensor(true); } +/** + * Collision begin callback + * @param: elem (Elements *) + * @param: contact (b2Contact *) + * @note: This function is called just before a collision + */ void Object::BeginContact(Elements *elem, b2Contact *contact) { if (elem->getAttributes()["type"] == "Hero"){ static_cast<Characters*>(elem)->equipWeapon(Game::wList->getWeapon("Bow")); @@ -47,9 +53,6 @@ void Object::BeginContact(Elements *elem, b2Contact *contact) { } } -void Object::init(void) { -} - /* * Basic Destructor */ diff --git a/Sources/src/Projectile.cpp b/Sources/src/Projectile.cpp @@ -25,13 +25,18 @@ # include "../inc/Projectile.hpp" -Projectile::Projectile(Weapon* w, Characters* c) { - int xDecal; - int yDecal; - int xOrient; - int yOrient; +Projectile::Projectile(Weapon* w, Characters* c){ + + this->_name = w->getName(); + this->_flavor = w->getFlavor(); + this->_attack = w->getAttack(); + this->_active = w->getActive(); + this->_damage = w->getDamage(); + this->_pushback = w->getPushback(); + this->_recovery = w->getRecovery(); this->SetSize(0.5f); this->SetShapeType(PhysicsActor::SHAPETYPE_BOX); + this->SetSprite("Resources/Images/kappa.png"); this->SetDensity(1); this->SetFriction(0); this->SetRestitution(0.0f); @@ -42,6 +47,23 @@ Projectile::Projectile(Weapon* w, Characters* c) { else this->addAttribute("type", "Projectile"); this->Tag("projectile"); + this->_initDirection(w, c); + theSwitchboard.DeferredBroadcast(new Message("canAttack"), this->_recovery); + theWorld.Add(this); +} + +/** + * Called during construction for clarity, used to determine projectile direction + * @param: w (Weapon*) + * @param: c (Characters*) + */ + +void Projectile::_initDirection(Weapon* w, Characters* c) { + int xDecal; + int yDecal; + int xOrient; + int yOrient; + if (c->getOrientation() == Characters::RIGHT) { xOrient = 1; xDecal = 1; @@ -66,36 +88,29 @@ Projectile::Projectile(Weapon* w, Characters* c) { yDecal = -1; yOrient = -1; } - this->_weapon = w; this->SetPosition(c->GetBody()->GetWorldCenter().x + xDecal, c->GetBody()->GetWorldCenter().y + yDecal); this->InitPhysics(); this->GetBody()->SetGravityScale(0.0f); this->GetBody()->SetBullet(true); - this->ApplyLinearImpulse(Vector2(2 * xOrient, 2 * yOrient), Vector2(0, 0)); - std::cout << w->getRecovery() << std::endl; - - theSwitchboard.DeferredBroadcast(new Message("canAttack"), w->getRecovery()); - theWorld.Add(this); + this->ApplyLinearImpulse(Vector2(3 * xOrient, 3 * yOrient), Vector2(0, 0)); } Projectile::~Projectile(void) { return; } - void Projectile::EndContact(Elements *elem, b2Contact *contact) { } /* GETTERS */ -std::string Projectile::getName(void) { return this->_weapon->getName(); } -std::string Projectile::getFlavor(void) { return this->_weapon->getFlavor(); } -std::string Projectile::getAttack(void) { return this->_weapon->getAttack(); } -float Projectile::getActive(void) { return this->_weapon->getActive(); } -int Projectile::getSize(void) { return this->_weapon->getSize(); } -int Projectile::getDamage(void) { return this->_weapon->getDamage(); } -int Projectile::getPushback(void) { return this->_weapon->getPushback(); } -float Projectile::getRecovery(void) { return this->_weapon->getRecovery(); } -int Projectile::attackReady(void) { return this->_weapon->attackReady(); } +std::string Projectile::getName(void) { return this->_name; } +std::string Projectile::getFlavor(void) { return this->_flavor; } +std::string Projectile::getAttack(void) { return this->_attack; } +float Projectile::getActive(void) { return this->_active; } +int Projectile::getSize(void) { return this->_size; } +int Projectile::getDamage(void) { return this->_damage; } +int Projectile::getPushback(void) { return this->_pushback; } +float Projectile::getRecovery(void) { return this->_recovery; } /** * Receive broadcasts message diff --git a/Sources/src/Room.cpp b/Sources/src/Room.cpp @@ -29,6 +29,13 @@ * Basic constructor */ Room::Room(int id, int y, int x, int mapId) : _id(id), _y(y), _x(x), _mapId(mapId) { + _topDoor = false; + _leftDoor = false; + _bottomDoor = false; + _rightDoor = false; + _distance = 0; + _links = 0; + _specialType = NONE; return ; } @@ -37,4 +44,78 @@ Room::Room(int id, int y, int x, int mapId) : _id(id), _y(y), _x(x), _mapId(mapI */ Room::~Room(void) { return ; -} +} + +int Room::getX(void) const { + return this->_x; +} + +int Room::getY(void) const { + return this->_y; +} + +int Room::getMapId(void) const { + return this->_mapId; +} + +int Room::getId(void) const { + return this->_id; +} + +int Room::getDistance(void) const { + return this->_distance; +} + +int Room::getLinks(void) const { + return this->_links; +} + +SpecialType Room::getSpecialType(void) const { + return this->_specialType; +} + +bool Room::getTopDoor(void) const { + return this->_topDoor; +} + +bool Room::getLeftDoor(void) const { + return this->_leftDoor; +} + + +bool Room::getBottomDoor(void) const { + return this->_bottomDoor; +} + + +bool Room::getRightDoor(void) const { + return this->_rightDoor; +} + +void Room::addLink(void) { + this->_links++; +} + +void Room::setTopDoor(bool state) { + this->_topDoor = state; +} + +void Room::setLeftDoor(bool state) { + this->_leftDoor = state; +} + +void Room::setBottomDoor(bool state) { + this->_bottomDoor = state; +} + +void Room::setRightDoor(bool state) { + this->_rightDoor = state; +} + +void Room::setDistance(int distance) { + this->_distance = distance; +} + +void Room::setSpecialType(SpecialType type) { + this->_specialType = type; +}+ \ No newline at end of file diff --git a/Sources/src/Shooter.cpp b/Sources/src/Shooter.cpp @@ -43,6 +43,5 @@ Shooter::Shooter(void) { Shooter::~Shooter(void) {} void Shooter::fire(float x, float y, int direction, std::string owner) { - std::cout << "FIRE !" << std::endl; Projectile *projectile = new Projectile(x, y, direction, owner); } diff --git a/Sources/src/Weapon.cpp b/Sources/src/Weapon.cpp @@ -53,13 +53,14 @@ Weapon::Weapon(Weapon* weapon) { theSwitchboard.SubscribeTo(this, "canAttack"); } + +/** + * Constructor for creating the weapon area-of-effect + * @param: w (Weapon*) + * @param: c (Characters*) + */ + Weapon::Weapon(Weapon* w, Characters* c) { - float xDecal = 0; - float yDecal = 0; - float xjoint1 = 0; - float xjoint2 = 0; - float yjoint1 = 0; - float yjoint2 = 0; this->_name = w->getName(); this->_flavor = w->getFlavor(); this->_damage = w->getDamage(); @@ -87,6 +88,17 @@ Weapon::Weapon(Weapon* w, Characters* c) { theSwitchboard.SubscribeTo(this, "deleteWeapon"); theSwitchboard.DeferredBroadcast(new Message("deleteWeapon"), w->getActive()); theSwitchboard.DeferredBroadcast(new Message("canAttack"), w->getRecovery()); + this->_initDirection(w, c); + theWorld.Add(this); +} + +void Weapon::_initDirection(Weapon* w, Characters* c) { + float xDecal = 0; + float yDecal = 0; + float xjoint1 = 0; + float xjoint2 = 0; + float yjoint1 = 0; + float yjoint2 = 0; if (c->getOrientation() == Characters::RIGHT) { xDecal = 1; yDecal = 0; @@ -129,7 +141,6 @@ Weapon::Weapon(Weapon* w, Characters* c) { jointDef2.collideConnected = false; b2DistanceJoint *joint1 = (b2DistanceJoint*)theWorld.GetPhysicsWorld().CreateJoint(&jointDef1); b2DistanceJoint *joint2 = (b2DistanceJoint*)theWorld.GetPhysicsWorld().CreateJoint(&jointDef2); - theWorld.Add(this); } /** diff --git a/Sources/src/WeaponList.cpp b/Sources/src/WeaponList.cpp @@ -54,14 +54,6 @@ WeaponList::~WeaponList(void) { } void WeaponList::statWeapon(std::string name) { - std::list<Weapon*>::iterator it; - - for (it = this->_allWeapons.begin(); it != this->_allWeapons.end(); it++) { - if (name == (*it)->getName()) { - std::cout << (*it)->getName() << std::endl; - std::cout << (*it)->getFlavor() << std::endl; - } - } } /** diff --git a/Sources/src/main.cpp b/Sources/src/main.cpp @@ -30,7 +30,9 @@ # include "WeaponList.hpp" # include "Equipment.hpp" # include "Consumable.hpp" -//# include "Hitbox.hpp" +# include "Hitbox.hpp" +# include "HUDWindow.hpp" +# include "LevelGenerator.hpp" class MouseDebugger: public MouseListener { public: @@ -41,20 +43,16 @@ class MouseDebugger: public MouseListener { void MouseDownEvent(Vec2i sc, MouseButtonInput button) { Vector2 w; w = MathUtil::ScreenToWorld(sc.X, sc.Y); - std::cout << w.X << ":" << w.Y << std::endl; }; }; int main(int ac, char **av) { - Game *game = new Game(); + Game::hList = new Hitbox(); - std::cout << "123" << std::endl; game->readMaps(); - std::cout << "123" << std::endl; MouseDebugger l; - theWorld.SetBackgroundColor(*(new Color(0.51f, 0.90f, 1))); - + theWorld.SetBackgroundColor(*(new Color(0, 0, 0))); Game::wList = new WeaponList(); @@ -62,20 +60,33 @@ int main(int ac, char **av) { Equipment *equip = new Equipment(); Consumable *lol = new Consumable(); - Hero *hero = new Hero(); - Enemy *enemy = new Enemy(); + Hero *hero = new Hero(); + Enemy *enemy = new Enemy(); + + + //===== I temp map generation test ===== - theCamera.LockTo(hero); + LevelGenerator *levelGenerator = new LevelGenerator(6, 6, 5, 60, 80); + levelGenerator->execute(); + levelGenerator->print(); + + //===== O temp map generation test ===== + +// theCamera.LockTo(hero); + theCamera.SetPosition(13, -7); game->displayHero(*(hero)); game->displayEnemy(*(enemy)); hero->init(); enemy->init(); + game->setHero(*hero); hero->equipWeapon(Game::wList->getWeapon("Sword")); -// new Hitbox(); //theWorld.SetSideBlockers(true, 0.7f); + game->displayHUD(); + game->start(); + return 0; }