Grog-Knight

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

commit 38e2e5552fcfab05986d0ddc9af20ad9f1ba67e9
parent f778b020e00be7b276268f5a2b9d8fc7b776df48
Author: Louis Solofrizzo <louis@ne02ptzero.me>
Date:   Thu, 12 Mar 2015 18:59:17 +0100

git push origin masterMerge branch 'build'

Diffstat:
A.gitignore | 6++++++
MAngel/Actors/Actor.cpp | 8+++++++-
MAngel/Actors/Actor.h | 2+-
MAngel/Actors/PhysicsActor.cpp | 27+++++++++++++++++++--------
MAngel/Actors/PhysicsActor.h | 3++-
MAngel/Angel.xcodeproj/project.pbxproj | 6++++--
MAngel/Libraries/FTGL/unix/config.log | 250+++----------------------------------------------------------------------------
MAngel/Libraries/FTGL/unix/libtool | 2+-
MContributing.md | 8++++++++
MMACOSX/Makefile | 20+++++++++++++++-----
MMakefile | 13++++++++++---
AMaps/MapBase.json | 160+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
DMaps/MapExample.json | 40----------------------------------------
AResources/Elements/Enemy.json | 22++++++++++++++++++++++
MResources/Elements/Hero.json | 18+++++++++++++-----
AResources/Elements/Hitbox/heroHitbox.json | 15+++++++++++++++
DResources/Elements/Sword.json | 36------------------------------------
AResources/Elements/Weapons/Bow.json | 17+++++++++++++++++
AResources/Elements/Weapons/Sword.json | 36++++++++++++++++++++++++++++++++++++
AResources/Images/Perso1/Bow_hit.gif | 0
AResources/Images/Perso1/attack.gif | 0
AResources/Images/Perso1/bighit.gif | 0
AResources/Images/Perso1/png/Bow_hit/Bow_hit_2.png | 0
AResources/Images/Perso1/png/Bow_hit/Bow_hit_3.png | 0
AResources/Images/Perso1/png/Bow_hit/Bow_hit_5.png | 0
MResources/Images/Perso1/png/Jump/jump.gif | 0
MResources/Images/Perso1/png/Jump/perso1-jump00.png | 0
MResources/Images/Perso1/png/Jump/perso1-jump01.png | 0
MResources/Images/Perso1/png/Jump/perso1-jump02.png | 0
MResources/Images/Perso1/png/Jump/perso1-jump03.png | 0
MResources/Images/Perso1/png/Jump/perso1-jump05.png | 0
MResources/Images/Perso1/png/Jump/perso1-jump06.png | 0
AResources/Images/Perso1/png/sword_bighit/perso1-bighit00.png | 0
AResources/Images/Perso1/png/sword_bighit/perso1-bighit01.png | 0
AResources/Images/Perso1/png/sword_bighit/perso1-bighit02.png | 0
AResources/Images/Perso1/png/sword_bighit/perso1-bighit03.png | 0
AResources/Images/Perso1/png/sword_bighit/perso1-bighit04.png | 0
AResources/Images/Perso1/png/sword_bighit/perso1-bighit05.png | 0
AResources/Images/Perso1/png/sword_bighit/perso1-bighit_rendu00.png | 0
AResources/Images/Perso1/png/sword_bighit/perso1-bighit_rendu04.png | 0
AResources/Images/Perso1/png/sword_bighit/sword_00.png | 0
AResources/Images/Perso1/png/sword_bighit/sword_01.png | 0
AResources/Images/Perso1/png/sword_bighit/sword_02.png | 0
AResources/Images/Perso1/png/sword_bighit/sword_03.png | 0
AResources/Images/Perso1/png/sword_bighit/sword_04.png | 0
AResources/Images/Perso1/png/sword_bighit/sword_05.png | 0
AResources/Images/Perso1/psd/Bow_hit.psd | 0
AResources/Images/Perso1/psd/died.psd | 0
AResources/Images/Perso1/psd/jump.psd | 0
AResources/Images/Perso1/psd/perso1-breathe.psd | 0
AResources/Images/Perso1/psd/perso1-run.psd | 0
AResources/Images/Perso1/psd/sonné.psd | 0
AResources/Images/Perso1/psd/sword_bighit.psd | 0
AResources/Images/Perso1/sword_bighit.gif | 0
AResources/Images/background.png | 0
AResources/Images/mob1/attack.gif | 0
AResources/Images/mob1/mob1.1/_DS_Store | 0
AResources/Images/mob1/mob1.1/mob1.1.psd | 0
AResources/Images/mob1/mob1.1/mob1.2.psd | 0
AResources/Images/mob1/mob1.1/static/mob1-static02.png | 0
AResources/Images/mob1/mob1.gif | 0
AResources/Images/mob1/mob1.psd | 0
AResources/Images/mob1/run/mob1-run00.png | 0
AResources/Images/mob1/run/mob1-run01.png | 0
AResources/Images/mob1/run/mob1-run02.png | 0
AResources/Images/mob1/run/mob1-run03.png | 0
AResources/Images/mob1/run/mob1-run04.png | 0
AResources/Images/mob1/static/mob1-static00.png | 0
AResources/Images/mob1/static/mob1-static01.png | 0
AResources/Images/mob1/static/mob1-static02.png | 0
AResources/Images/mob1/static/mob1-static03.png | 0
AResources/Images/mob1/static/mob1-static04.png | 0
MSources/inc/Characters.hpp | 42+++++++++++++++++++++++++++++++++++++++---
ASources/inc/Consumable.hpp | 43+++++++++++++++++++++++++++++++++++++++++++
MSources/inc/Elements.hpp | 37++++++++++++++++++++++++-------------
MSources/inc/Enemy.hpp | 9++++-----
ASources/inc/Equipment.hpp | 46++++++++++++++++++++++++++++++++++++++++++++++
MSources/inc/Game.hpp | 19+++++++++++++++++--
MSources/inc/Hero.hpp | 6+-----
ASources/inc/Hitbox.hpp | 42++++++++++++++++++++++++++++++++++++++++++
ASources/inc/LevelGenerator.hpp | 57+++++++++++++++++++++++++++++++++++++++++++++++++++++++++
ASources/inc/Map.hpp | 76++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
MSources/inc/Maps.hpp | 22+++++++---------------
ASources/inc/Object.hpp | 44++++++++++++++++++++++++++++++++++++++++++++
MSources/inc/Projectile.hpp | 21++++++++++++++++-----
ASources/inc/Room.hpp | 54++++++++++++++++++++++++++++++++++++++++++++++++++++++
MSources/inc/Shooter.hpp | 2+-
MSources/inc/Weapon.hpp | 37++++++++++++++++++++++++++++---------
ASources/inc/WeaponList.hpp | 60++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
MSources/src/Characters.cpp | 183++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-------------------
ASources/src/Consumable.cpp | 56++++++++++++++++++++++++++++++++++++++++++++++++++++++++
MSources/src/ContactFilter.cpp | 1-
MSources/src/Elements.cpp | 47++++++++++++++++++++++++++++++++++++++++++++++-
MSources/src/Enemy.cpp | 70+++++++++++++++++++++++++++++++---------------------------------------
ASources/src/Equipment.cpp | 60++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
MSources/src/Game.cpp | 119+++++++++++++++++++++++++++++++++++++++++++++++--------------------------------
MSources/src/Hero.cpp | 26+++++++++++++++++++++++++-
ASources/src/Hitbox.cpp | 101+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
ASources/src/LevelGenerator.cpp | 57+++++++++++++++++++++++++++++++++++++++++++++++++++++++++
ASources/src/Map.cpp | 108+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
MSources/src/Maps.cpp | 60++++++++++++++++++++++++++++++++++--------------------------
ASources/src/Object.cpp | 58++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
MSources/src/Projectile.cpp | 70++++++++++++++++++++++++++++++++++++++++++++++++++++++----------------
ASources/src/Room.cpp | 40++++++++++++++++++++++++++++++++++++++++
MSources/src/Weapon.cpp | 195++++++++++++++++++++++++++++++++++++++++++++++++++++++++++---------------------
ASources/src/WeaponList.cpp | 80+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
MSources/src/main.cpp | 33+++++++++++++++++++++++++--------
107 files changed, 2034 insertions(+), 636 deletions(-)

diff --git a/.gitignore b/.gitignore @@ -0,0 +1,6 @@ +*.o +rogue-like +Tools/jsoncpp/ +*.a +*.lo +Angel/Libraries/Box2D-2.2.1/Build diff --git a/Angel/Actors/Actor.cpp b/Angel/Actors/Actor.cpp @@ -30,6 +30,8 @@ #include "stdafx.h" #include "../Actors/Actor.h" +#include "../../Sources/inc/Game.hpp" + #include "../Infrastructure/TagCollection.h" #include "../Infrastructure/Textures.h" #include "../Infrastructure/TextRendering.h" @@ -43,7 +45,7 @@ #include <sstream> -const float Actor::_squareVertices[] = { +float Actor::_squareVertices[] = { -0.5f, 0.5f, -0.5f, -0.5f, 0.5f, 0.5f, @@ -273,6 +275,10 @@ void Actor::Render() glScalef(_size.X, _size.Y, 1.0f); glColor4f(_color.R, _color.G, _color.B, _color.A); + /* CODE MODIFIED BY LOUIS */ + Game::makeItRun(); + /* END */ + int textureReference = _spriteTextureReferences[_spriteCurrentFrame]; if (textureReference >= 0) { diff --git a/Angel/Actors/Actor.h b/Angel/Actors/Actor.h @@ -615,7 +615,7 @@ protected: float _UV[8]; actorDrawShape _drawShape; - static const float _squareVertices[]; + static float _squareVertices[]; static float _circleVertices[]; static float _circleTextureCoords[]; diff --git a/Angel/Actors/PhysicsActor.cpp b/Angel/Actors/PhysicsActor.cpp @@ -150,14 +150,22 @@ void PhysicsActor::InitPhysics() else if (_shapeType == SHAPETYPE_HERO) { b2Vec2 vertices[8]; - vertices[0].Set(-0.45, 0.5); - vertices[1].Set(-0.5, 0.45); - vertices[2].Set(-0.5, -0.45); - vertices[3].Set(-0.45, -0.5); - vertices[4].Set(0.45, -0.5); - vertices[5].Set(0.5, -0.45); - vertices[6].Set(0.5, 0.45); - vertices[7].Set(0.45, 0.5); +// vertices[0].Set(-0.45, 0.5); +// vertices[1].Set(-0.5, 0.45); +// vertices[2].Set(-0.5, -0.45); +// vertices[3].Set(-0.45, -0.5); +// vertices[4].Set(0.45, -0.5); +// vertices[5].Set(0.5, -0.45); +// vertices[6].Set(0.5, 0.45); +// vertices[7].Set(0.45, 0.5); + vertices[0].Set(-0.1, 0.5); + vertices[1].Set(-0.3, 0.45); + vertices[2].Set(-0.3, -0.45); + vertices[3].Set(-0.1, -0.5); + vertices[4].Set(0.1, -0.5); + vertices[5].Set(0.3, -0.45); + vertices[6].Set(0.3, 0.45); + vertices[7].Set(0.1, 0.5); box.Set(vertices, 8); //box.SetAsBox(0.5f*_size.X, 0.5f*_size.Y); shape = &box; @@ -167,6 +175,9 @@ void PhysicsActor::InitPhysics() box.SetAsBox(0.5f*_size.X, 0.25f*_size.Y); shape = &box; } + else if (_shapeType == SHAPETYPE_LOADED) { + shape = &_box; + } /* END OF CODE */ else { diff --git a/Angel/Actors/PhysicsActor.h b/Angel/Actors/PhysicsActor.h @@ -72,6 +72,7 @@ public: SHAPETYPE_CIRCLE, SHAPETYPE_HERO, SHAPETYPE_PROJECTILE, + SHAPETYPE_LOADED }; /** @@ -335,7 +336,7 @@ public: protected: virtual void InitShape(b2Shape* /*shapeDef*/ ) {} b2Body *_physBody; - + b2PolygonShape _box; float _density; float _friction; float _restitution; diff --git a/Angel/Angel.xcodeproj/project.pbxproj b/Angel/Angel.xcodeproj/project.pbxproj @@ -172,13 +172,13 @@ 345AAD5311CB376A002B4471 /* StringUtil.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 34A187BC0E283FF3001C79A5 /* StringUtil.cpp */; }; 345AAD5411CB376A002B4471 /* Input.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 34A181B30E283FF1001C79A5 /* Input.cpp */; }; 345AAD5511CB376A002B4471 /* MouseInput.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 34A181B80E283FF1001C79A5 /* MouseInput.cpp */; }; - 345AAD5611CB376A002B4471 /* PhysicsActor.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 34A181AB0E283FF1001C79A5 /* PhysicsActor.cpp */; }; + 345AAD5611CB376A002B4471 /* PhysicsActor.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 34A181AB0E283FF1001C79A5 /* PhysicsActor.cpp */; settings = {COMPILER_FLAGS = "-I ../Tools/jsoncpp/include/"; }; }; 345AAD5811CB376A002B4471 /* GotoAIEvent.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 34A181760E283FF1001C79A5 /* GotoAIEvent.cpp */; }; 345AAD5911CB376A002B4471 /* GotoTargetAIEvent.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 34A181780E283FF1001C79A5 /* GotoTargetAIEvent.cpp */; }; 345AAD5A11CB376A002B4471 /* NamedEventAIEvent.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 34A1817A0E283FF1001C79A5 /* NamedEventAIEvent.cpp */; }; 345AAD5B11CB376A002B4471 /* TimerAIEvent.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 34A1817C0E283FF1001C79A5 /* TimerAIEvent.cpp */; }; 345AAD5C11CB376A002B4471 /* TraversalAIEvent.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 34A1817E0E283FF1001C79A5 /* TraversalAIEvent.cpp */; }; - 345AAD5D11CB376A002B4471 /* Actor.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 34A1815B0E283FE0001C79A5 /* Actor.cpp */; }; + 345AAD5D11CB376A002B4471 /* Actor.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 34A1815B0E283FE0001C79A5 /* Actor.cpp */; settings = {COMPILER_FLAGS = "-I ../Tools/jsoncpp/include/"; }; }; 345AAD5E11CB376A002B4471 /* FullScreenActor.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 34A1815F0E283FE0001C79A5 /* FullScreenActor.cpp */; }; 345AAD5F11CB376A002B4471 /* GridActor.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 34A181610E283FE0001C79A5 /* GridActor.cpp */; }; 345AAD6011CB376A002B4471 /* ParticleActor.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 34A181630E283FE0001C79A5 /* ParticleActor.cpp */; }; @@ -1348,6 +1348,7 @@ 34FB48961638FDFB002EB836 /* UnitTest.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = UnitTest.h; path = Libraries/gwen/include/Gwen/UnitTest/UnitTest.h; sourceTree = "<group>"; }; 34FB48991638FE0A002EB836 /* ControlFactory.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = ControlFactory.h; path = Libraries/gwen/include/Gwen/Util/ControlFactory.h; sourceTree = "<group>"; }; 34FB489A1638FE0A002EB836 /* ImportExport.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = ImportExport.h; path = Libraries/gwen/include/Gwen/Util/ImportExport.h; sourceTree = "<group>"; }; + 67E4EBC11AA479E80003D115 /* include */ = {isa = PBXFileReference; lastKnownFileType = folder; name = include; path = ../Tools/jsoncpp/include; sourceTree = "<group>"; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -1449,6 +1450,7 @@ 29B97314FDCFA39411CA2CEA /* Angel */ = { isa = PBXGroup; children = ( + 67E4EBC11AA479E80003D115 /* include */, 34A18BAD0E2841CC001C79A5 /* Angel Framework */, 34A18C990E284421001C79A5 /* Frameworks */, 19C28FACFE9D520D11CA2CBB /* Products */, diff --git a/Angel/Libraries/FTGL/unix/config.log b/Angel/Libraries/FTGL/unix/config.log @@ -30,8 +30,8 @@ Kernel configured for up to 4 processors. Processor type: i486 (Intel 80486) Processors active: 0 1 2 3 Primary memory available: 8.00 gigabytes -Default processor set: 155 tasks, 641 threads, 4 processors -Load average: 1.19, Mach factor: 2.91 +Default processor set: 188 tasks, 816 threads, 4 processors +Load average: 1.82, Mach factor: 2.18 /bin/machine = unknown /usr/bin/oslevel = unknown /bin/universe = unknown @@ -81,212 +81,6 @@ compilation terminated. configure:1679: $? = 1 configure:1703: checking for C++ compiler default output configure:1706: g++ -g -O2 -fPIC conftest.cc >&5 -configure:1709: $? = 0 -configure:1755: result: a.out -configure:1760: checking whether the C++ compiler works -configure:1766: ./a.out -configure:1769: $? = 0 -configure:1786: result: yes -configure:1793: checking whether we are cross compiling -configure:1795: result: no -configure:1798: checking for suffix of executables -configure:1800: g++ -o conftest -g -O2 -fPIC conftest.cc >&5 -configure:1803: $? = 0 -configure:1828: result: -configure:1834: checking for suffix of object files -configure:1856: g++ -c -g -O2 -fPIC conftest.cc >&5 -configure:1859: $? = 0 -configure:1881: result: o -configure:1885: checking whether we are using the GNU C++ compiler -configure:1910: g++ -c -g -O2 -fPIC conftest.cc >&5 -configure:1913: $? = 0 -configure:1916: test -s conftest.o -configure:1919: $? = 0 -configure:1932: result: yes -configure:1938: checking whether g++ accepts -g -configure:1960: g++ -c -g conftest.cc >&5 -configure:1963: $? = 0 -configure:1966: test -s conftest.o -configure:1969: $? = 0 -configure:1980: result: yes -configure:2024: g++ -c -g -O2 -fPIC conftest.cc >&5 -configure:2027: $? = 0 -configure:2030: test -s conftest.o -configure:2033: $? = 0 -configure:2060: g++ -c -g -O2 -fPIC conftest.cc >&5 -configure: In function 'int main()': -configure:2055:9: error: 'exit' was not declared in this scope - ; - ^ -configure:2063: $? = 1 -configure: failed program was: -| #line 2043 "configure" -| /* confdefs.h. */ -| -| #define PACKAGE_NAME "ftgl" -| #define PACKAGE_TARNAME "ftgl" -| #define PACKAGE_VERSION "2.0.5" -| #define PACKAGE_STRING "ftgl 2.0.5" -| #define PACKAGE_BUGREPORT "henryj@paradise.net.nz" -| /* end confdefs.h. */ -| -| int -| main () -| { -| exit (42); -| ; -| return 0; -| } -configure:2024: g++ -c -g -O2 -fPIC conftest.cc >&5 -configure:2027: $? = 0 -configure:2030: test -s conftest.o -configure:2033: $? = 0 -configure:2060: g++ -c -g -O2 -fPIC conftest.cc >&5 -configure:2063: $? = 0 -configure:2066: test -s conftest.o -configure:2069: $? = 0 -configure:2206: checking for gcc -configure:2222: found /usr/local/bin/gcc -configure:2232: result: gcc -configure:2476: checking for C compiler version -configure:2479: gcc --version </dev/null >&5 -gcc (GCC) 4.9.0 20131215 (experimental) -Copyright (C) 2013 Free Software Foundation, Inc. -This is free software; see the source for copying conditions. There is NO -warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - -configure:2482: $? = 0 -configure:2484: gcc -v </dev/null >&5 -Using built-in specs. -COLLECT_GCC=gcc -COLLECT_LTO_WRAPPER=/usr/local/libexec/gcc/x86_64-apple-darwin13.0.0/4.9.0/lto-wrapper -Target: x86_64-apple-darwin13.0.0 -Configured with: ../gcc-4.9-20131215/configure --enable-languages=c++,fortran -Thread model: posix -gcc version 4.9.0 20131215 (experimental) (GCC) -configure:2487: $? = 0 -configure:2489: gcc -V </dev/null >&5 -gcc: error: unrecognized command line option '-V' -gcc: fatal error: no input files -compilation terminated. -configure:2492: $? = 1 -configure:2495: checking whether we are using the GNU C compiler -configure:2520: gcc -c conftest.c >&5 -configure:2523: $? = 0 -configure:2526: test -s conftest.o -configure:2529: $? = 0 -configure:2542: result: yes -configure:2548: checking whether gcc accepts -g -configure:2570: gcc -c -g conftest.c >&5 -configure:2573: $? = 0 -configure:2576: test -s conftest.o -configure:2579: $? = 0 -configure:2590: result: yes -configure:2607: checking for gcc option to accept ANSI C -configure:2668: gcc -c -g -O2 conftest.c >&5 -configure:2671: $? = 0 -configure:2674: test -s conftest.o -configure:2677: $? = 0 -configure:2695: result: none needed -configure:2713: gcc -c -g -O2 conftest.c >&5 -conftest.c:2:3: error: unknown type name 'choke' - choke me - ^ -conftest.c:2:3: error: expected '=', ',', ';', 'asm' or '__attribute__' at end of input -configure:2716: $? = 1 -configure: failed program was: -| #ifndef __cplusplus -| choke me -| #endif -configure:2847: checking for ld used by GCC -configure:2910: result: /usr/bin/ld -configure:2919: checking if the linker (/usr/bin/ld) is GNU ld -configure:2931: result: no -configure:2936: checking for /usr/bin/ld option to reload object files -configure:2943: result: -r -configure:2948: checking for BSD-compatible nm -configure:2984: result: /usr/bin/nm -configure:2987: checking for a sed that does not truncate output -configure:3069: result: /usr/bin/sed -configure:3072: checking whether ln -s works -configure:3076: result: yes -configure:3083: checking how to recognise dependent libraries -configure:3264: result: file_magic Mach-O dynamically linked shared library -configure:3277: checking command to parse /usr/bin/nm output -configure:3361: gcc -c -g -O2 conftest.c >&5 -configure:3364: $? = 0 -configure:3368: /usr/bin/nm conftest.o \| sed -n -e 's/^.*[ ]\([BCDEGRST][BCDEGRST]*\)[ ][ ]*\(\)\([_A-Za-z][_A-Za-z0-9]*\)$/\1 \2\3 \3/p' \> conftest.nm -configure:3371: $? = 0 -cannot find nm_test_var in conftest.nm -configure:3361: gcc -c -g -O2 conftest.c >&5 -configure:3364: $? = 0 -configure:3368: /usr/bin/nm conftest.o \| sed -n -e 's/^.*[ ]\([BCDEGRST][BCDEGRST]*\)[ ][ ]*\(_\)\([_A-Za-z][_A-Za-z0-9]*\)$/\1 \2\3 \3/p' \> conftest.nm -configure:3371: $? = 0 -configure:3423: gcc -o conftest -g -O2 conftest.c conftstm.o >&5 -configure:3426: $? = 0 -configure:3470: result: ok -configure:3479: checking how to run the C preprocessor -configure:3515: gcc -E conftest.c -configure:3521: $? = 0 -configure:3553: gcc -E conftest.c -configure:3555:28: fatal error: ac_nonexistent.h: No such file or directory - ac_status=$? - ^ -compilation terminated. -configure:3559: $? = 1 -configure: failed program was: -| #line 3544 "configure" -| /* confdefs.h. */ -| -| #define PACKAGE_NAME "ftgl" -| #define PACKAGE_TARNAME "ftgl" -| #define PACKAGE_VERSION "2.0.5" -| #define PACKAGE_STRING "ftgl 2.0.5" -| #define PACKAGE_BUGREPORT "henryj@paradise.net.nz" -| #ifdef __cplusplus -| #include <stdlib.h> -| #endif -| /* end confdefs.h. */ -| #include <ac_nonexistent.h> -configure:3597: result: gcc -E -configure:3622: gcc -E conftest.c -configure:3628: $? = 0 -configure:3660: gcc -E conftest.c -configure:3662:28: fatal error: ac_nonexistent.h: No such file or directory - ac_status=$? - ^ -compilation terminated. -configure:3666: $? = 1 -configure: failed program was: -| #line 3651 "configure" -| /* confdefs.h. */ -| -| #define PACKAGE_NAME "ftgl" -| #define PACKAGE_TARNAME "ftgl" -| #define PACKAGE_VERSION "2.0.5" -| #define PACKAGE_STRING "ftgl 2.0.5" -| #define PACKAGE_BUGREPORT "henryj@paradise.net.nz" -| #ifdef __cplusplus -| #include <stdlib.h> -| #endif -| /* end confdefs.h. */ -| #include <ac_nonexistent.h> -configure:3709: checking for egrep -configure:3719: result: grep -E -configure:3724: checking for ANSI C header files -configure:3750: gcc -c -g -O2 conftest.c >&5 -configure:3753: $? = 0 -configure:3756: test -s conftest.o -configure:3759: $? = 0 -configure:3851: gcc -o conftest -g -O2 conftest.c >&5 -configure: In function 'main': -configure:3847:7: warning: incompatible implicit declaration of built-in function 'exit' [enabled by default] - exit (0); - ^ -configure:3854: $? = 0 -configure:3856: ./conftest -configure:3859: $? = 0 -configure:3874: result: yes ## ---------------- ## ## Cache variables. ## @@ -294,8 +88,6 @@ configure:3874: result: yes ac_cv_build=i686-apple-darwin13.4.0 ac_cv_build_alias=i686-apple-darwin13.4.0 -ac_cv_c_compiler_gnu=yes -ac_cv_cxx_compiler_gnu=yes ac_cv_env_CC_set= ac_cv_env_CC_value= ac_cv_env_CFLAGS_set= @@ -316,37 +108,17 @@ ac_cv_env_host_alias_set= ac_cv_env_host_alias_value= ac_cv_env_target_alias_set= ac_cv_env_target_alias_value= -ac_cv_exeext= -ac_cv_header_stdc=yes ac_cv_host=i686-apple-darwin13.4.0 ac_cv_host_alias=i686-apple-darwin13.4.0 -ac_cv_objext=o -ac_cv_prog_CPP='gcc -E' -ac_cv_prog_ac_ct_CC=gcc ac_cv_prog_ac_ct_CXX=g++ -ac_cv_prog_cc_g=yes -ac_cv_prog_cc_stdc= -ac_cv_prog_cxx_g=yes -ac_cv_prog_egrep='grep -E' -lt_cv_deplibs_check_method='file_magic Mach-O dynamically linked shared library' -lt_cv_file_magic_cmd='/usr/bin/file -L' -lt_cv_file_magic_test_file=/usr/lib/libSystem.dylib -lt_cv_global_symbol_to_c_name_address='sed -n -e '\''s/^: \([^ ]*\) $/ {\"\1\", (lt_ptr) 0},/p'\'' -e '\''s/^[BCDEGRST] \([^ ]*\) \([^ ]*\)$/ {"\2", (lt_ptr) \&\2},/p'\''' -lt_cv_global_symbol_to_cdecl='sed -n -e '\''s/^. .* \(.*\)$/extern char \1;/p'\''' -lt_cv_ld_reload_flag=-r -lt_cv_path_LD=/usr/bin/ld -lt_cv_path_NM=/usr/bin/nm -lt_cv_path_SED=/usr/bin/sed -lt_cv_prog_gnu_ld=no -lt_cv_sys_global_symbol_pipe='sed -n -e '\''s/^.*[ ]\([BCDEGRST][BCDEGRST]*\)[ ][ ]*\(_\)\([_A-Za-z][_A-Za-z0-9]*\)$/\1 \2\3 \3/p'\''' ## ----------------- ## ## Output variables. ## ## ----------------- ## -CC='gcc' -CFLAGS='-g -O2' -CPP='gcc -E' +CC='' +CFLAGS='' +CPP='' CPPFLAGS='' CXX='g++' CXXFLAGS='-g -O2 -fPIC' @@ -355,7 +127,7 @@ DOXYGEN='' ECHO='/bin/echo' ECHO_C='ECHO_N='' ECHO_T='' -EGREP='grep -E' +EGREP='' EXEEXT='' FT2_CFLAGS='' FT2_CONFIG='' @@ -372,9 +144,9 @@ LDFLAGS='' LIBOBJS='' LIBS='' LIBTOOL='' -LN_S='ln -s' +LN_S='' LTLIBOBJS='' -OBJEXT='o' +OBJEXT='' PACKAGE_BUGREPORT='henryj@paradise.net.nz' PACKAGE_NAME='ftgl' PACKAGE_STRING='ftgl 2.0.5' @@ -388,7 +160,7 @@ X_CFLAGS='' X_EXTRA_LIBS='' X_LIBS='' X_PRE_LIBS='' -ac_ct_CC='gcc' +ac_ct_CC='' ac_ct_CXX='g++' ac_ct_RANLIB='' ac_ct_STRIP='' @@ -428,10 +200,6 @@ target_alias='' #define PACKAGE_STRING "ftgl 2.0.5" #define PACKAGE_TARNAME "ftgl" #define PACKAGE_VERSION "2.0.5" -#define STDC_HEADERS 1 -#endif -#ifdef __cplusplus -#include <stdlib.h> configure: caught signal 2 configure: exit 1 diff --git a/Angel/Libraries/FTGL/unix/libtool b/Angel/Libraries/FTGL/unix/libtool @@ -38,7 +38,7 @@ if test "X${CDPATH+set}" = Xset; then CDPATH=:; export CDPATH; fi # ### BEGIN LIBTOOL CONFIG -# Libtool was configured on host e2r12p19.42.fr: +# Libtool was configured on host e2r13p12.42.fr: # Shell to use when invoking shell scripts. SHELL="/bin/sh" diff --git a/Contributing.md b/Contributing.md @@ -172,6 +172,14 @@ Also, we gain 1.3s at the build. " ``` +### Working Space + +We working on the branch [build](https://github.com/Ne02ptzero/rogue-like/tree/build) + +So, if you have modifications to make (Code, docs or even pictures), please do it on this branch. + +The master __must__ be buildable and stable. + ### Build *For main contributors:* diff --git a/MACOSX/Makefile b/MACOSX/Makefile @@ -1,21 +1,28 @@ NAME = rogue-like CC = g++ -CFLAGS = -std=c++0x -arch i386 -Wno-deprecated +CFLAGS = -std=c++0x -arch i386 -Wno-deprecated -g ANGEL_FLAG = -D ANGEL SRCS = ../Sources/src/main.cpp \ ../Sources/src/Elements.cpp \ ../Sources/src/Game.cpp \ ../Sources/src/Characters.cpp \ + ../Sources/src/WeaponList.cpp \ ../Sources/src/Weapon.cpp \ - ../Sources/src/Shooter.cpp \ ../Sources/src/Projectile.cpp \ + ../Sources/src/Room.cpp \ + ../Sources/src/LevelGenerator.cpp \ ../Sources/src/Hero.cpp \ ../Sources/src/Enemy.cpp \ + ../Sources/src/Map.cpp \ ../Sources/src/Maps.cpp \ - ../Angel/Scripting/Interfaces/AngelLuaWrapping.cpp \ ../Sources/src/GameContactListener.cpp \ ../Sources/src/ContactFilter.cpp \ - ../Sources/src/Log.cpp + ../Sources/src/Log.cpp \ + ../Sources/src/Object.cpp \ + ../Sources/src/Equipment.cpp \ + ../Sources/src/Consumable.cpp \ + ../Sources/src/Hitbox.cpp \ + ../Angel/Scripting/Interfaces/AngelLuaWrapping.cpp OBJS = $(SRCS:.cpp=.o) @@ -86,7 +93,10 @@ angel: angel-clean: cd ../Angel && xcodebuild -scheme Angel -project Angel.xcodeproj CONFIGURATION_BUILD_DIR='build' clean -clean: angel-clean json-clean +clean: angel-clean json-clean quick-clean + +quick-clean: + rm $(OBJS) exec: cd build/ && ./rogue-like diff --git a/Makefile b/Makefile @@ -61,14 +61,21 @@ SRCS = ./Sources/src/Elements.cpp \ ./Sources/src/main.cpp \ ./Sources/src/Maps.cpp \ ./Sources/src/Hero.cpp \ - ./Sources/src/Shooter.cpp \ ./Sources/src/Projectile.cpp \ - ./Sources/src/Enemy.cpp \ + ./Sources/src/Room.cpp \ + ./Sources/src/LevelGenerator.cpp \ + ./Sources/src/Enemy.cpp \ ./Sources/src/GameContactListener.cpp \ ./Sources/src/ContactFilter.cpp \ ./Sources/src/Weapon.cpp \ ./Sources/src/Log.cpp \ - ./Sources/src/Characters.cpp + ./Sources/src/Characters.cpp \ + ./Sources/src/Object.cpp \ + ./Sources/src/WeaponList.cpp \ + ./Sources/src/Map.cpp \ + ./Sources/src/Equipment.cpp \ + ./Sources/src/Consumable.cpp \ + ./Sources/src/Hitbox.cpp SYSOBJS = $(patsubst %.cpp,%.o,$(SYSSRCS)) OBJS = $(patsubst %.cpp,%.o,$(SRCS)) diff --git a/Maps/MapBase.json b/Maps/MapBase.json @@ -0,0 +1,160 @@ +{ "height":20, + "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, + "name":"Tile Layer 1", + "opacity":1, + "type":"tilelayer", + "visible":true, + "width":20, + "x":0, + "y":0 + }], + "nextobjectid":1, + "orientation":"orthogonal", + "properties": + { + "world":"base" + }, + "renderorder":"right-down", + "tileheight":16, + "tilesets":[ + { + "firstgid":1, + "image":"Resources\/Images\/background.png", + "imageheight":160, + "imagewidth":240, + "margin":0, + "name":"Base", + "properties": + { + + }, + "spacing":0, + "tileheight":16, + "tileproperties": + { + "102": + { + "physic":"0" + }, + "109": + { + "physic":"0" + }, + "110": + { + "physic":"0" + }, + "111": + { + "physic":"0" + }, + "112": + { + "physic":"0" + }, + "124": + { + //"physic":"0" + }, + "125": + { + "physic":"0" + }, + "126": + { + "physic":"0" + }, + "127": + { + "physic":"0" + }, + "25": + { + "physic":"0" + }, + "26": + { + "physic":"0" + }, + "27": + { + "physic":"0" + }, + "40": + { + "physic":"0" + }, + "41": + { + "physic":"0" + }, + "42": + { + "physic":"0" + }, + "55": + { + "physic":"0" + }, + "56": + { + "physic":"0" + }, + "57": + { + "physic":"0" + }, + "64": + { + "physic":"0" + }, + "72": + { + + }, + "79": + { + "physic":"0" + }, + "80": + { + "physic":"0" + }, + "81": + { + "physic":"0" + }, + "85": + { + "physic":"0" + }, + "86": + { + "physic":"0" + }, + "87": + { + "physic":"0" + }, + "94": + { + "physic":"0" + }, + "95": + { + "physic":"0" + }, + "96": + { + "physic":"0" + } + }, + "tilewidth":16 + }], + "tilewidth":16, + "version":1, + "width":20 +} diff --git a/Maps/MapExample.json b/Maps/MapExample.json @@ -1,40 +0,0 @@ -{ - "general" : { - "name": "Example Map", - "callbacks": "SomeCallback", - "world": "Basic", - "id": 1 - }, - "Blocks": { - "1": { - "type": "ground", - "sprite": "Resources/Images/ground.png", - "physic": "1" - }, - "2": { - "type": "wall", - "sprite": "Resources/Images/wall.png", - "physic": "1" - }, - "3": { - "type": "corner", - "orientation": "90" - //"sprite": "/path/to/png" - }, - "4": { - "attribute": "start" - }, - "5": { - "heritage": "1", - "attribute": "end", - "nextMap": "2" - } - }, - "Map": [ - [2,0,4,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2], - [2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,2], - [2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0], - [2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0], - [2,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,2] - ] -} diff --git a/Resources/Elements/Enemy.json b/Resources/Elements/Enemy.json @@ -0,0 +1,22 @@ +{ + "infos": { + "name": "Enemy", + "id": 1, + "HP": 50, + "sprites": "Resources/Images/Enemy/enemy_000.png", + "size": 1.3, + "maxSpeed": 5 + }, + "Actions": { + "breath": { + "beginFrame": 1, + "endFrame": 4, + "time": 0.1 + }, + "jump": { + "beginFrame": 1, + "endFrame": 4, + "time": 0.1 + } + } +} diff --git a/Resources/Elements/Hero.json b/Resources/Elements/Hero.json @@ -14,26 +14,34 @@ "beginFrame": 4, "endFrame": 9, "time": 0.1, - "force": 5 + "force": 10 }, "backward": { "subscribe": "backward", - "beginFrame": 4, - "endFrame": 9, + "beginFrame": 10, + "endFrame": 15, "time": 0.1, - "force": 5 + "force": 10 }, "jump": { "subscribe": "jump", "double": 1, - "force": 5, + "force": 6, + "rejump": 7, "beginFrame": 16, + "fallingFrame": 23, "endFrame": 27, "time": 0.1 }, "attack": { "subscribe": "attack" }, + "down": { + "subscribe": "down" + }, + "up": { + "subscribe": "up" + }, "breath": { "beginFrame": 1, "endFrame": 3, diff --git a/Resources/Elements/Hitbox/heroHitbox.json b/Resources/Elements/Hitbox/heroHitbox.json @@ -0,0 +1,15 @@ +{ + "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" + } +} diff --git a/Resources/Elements/Sword.json b/Resources/Elements/Sword.json @@ -1,35 +0,0 @@ -{ - "infos": { - "name": "Sword", - "flavor": "Hey look, its a sword. A pretty shitty one actually...", - "hitbox": "SWORD", - "size": 1, - "active": 0.2, - "lvlRequired": 1, - "damage": 1, - "recovery": 1, - "active": 0.2, - "attack": "melee", - "combo": true, - "particule": "la soeur de ryad", - "heroAnim": "sword_anim_1" - }, - "combo": { - "1": { - "damage": 10, - "particule": "entrecote", - "heroAnim": "sword_anim_2" - }, - "2": { - "damage": 100, - "specialEffect": "stunSpecial", - "heroAnim": "sword_anim_3" - } - }, - "Capacities": { - "stunSpecial": { - "duration": 1, - "particule": "boom" - } - } -}- \ No newline at end of file diff --git a/Resources/Elements/Weapons/Bow.json b/Resources/Elements/Weapons/Bow.json @@ -0,0 +1,16 @@ +{ + "infos": { + "name": "Bow", + "flavor": "This bow is supposed to shoot arrows. Supposed.", + "hitbox": "PROJECTILE", + "size": 0.5, + "active": 0.2, + "lvlRequired": 1, + "damage": 0.5, + "pushback": 1, + "recovery": 0.1, + "attack": "ranged", + "particule": "la soeur de ryadv2.0", + "heroAnim": "sword_anim_1" + } +}+ \ No newline at end of file diff --git a/Resources/Elements/Weapons/Sword.json b/Resources/Elements/Weapons/Sword.json @@ -0,0 +1,35 @@ +{ + "infos": { + "name": "Sword", + "flavor": "Hey look, its a sword. A pretty shitty one actually...", + "hitbox": "SWORD", + "size": 1, + "lvlRequired": 1, + "damage": 1, + "recovery": 1, + "pushback": 5, + "active": 0.2, + "attack": "melee", + "combo": true, + "particule": "la soeur de ryad", + "heroAnim": "sword_anim_1" + }, + "combo": { + "1": { + "damage": 10, + "particule": "entrecote", + "heroAnim": "sword_anim_2" + }, + "2": { + "damage": 100, + "specialEffect": "stunSpecial", + "heroAnim": "sword_anim_3" + } + }, + "capacities": { + "stunSpecial": { + "duration": 1, + "particule": "boom" + } + } +}+ \ No newline at end of file diff --git a/Resources/Images/Perso1/Bow_hit.gif b/Resources/Images/Perso1/Bow_hit.gif Binary files differ. diff --git a/Resources/Images/Perso1/attack.gif b/Resources/Images/Perso1/attack.gif Binary files differ. diff --git a/Resources/Images/Perso1/bighit.gif b/Resources/Images/Perso1/bighit.gif Binary files differ. diff --git a/Resources/Images/Perso1/png/Bow_hit/Bow_hit_2.png b/Resources/Images/Perso1/png/Bow_hit/Bow_hit_2.png Binary files differ. diff --git a/Resources/Images/Perso1/png/Bow_hit/Bow_hit_3.png b/Resources/Images/Perso1/png/Bow_hit/Bow_hit_3.png Binary files differ. diff --git a/Resources/Images/Perso1/png/Bow_hit/Bow_hit_5.png b/Resources/Images/Perso1/png/Bow_hit/Bow_hit_5.png Binary files differ. diff --git a/Resources/Images/Perso1/png/Jump/jump.gif b/Resources/Images/Perso1/png/Jump/jump.gif Binary files differ. diff --git a/Resources/Images/Perso1/png/Jump/perso1-jump00.png b/Resources/Images/Perso1/png/Jump/perso1-jump00.png Binary files differ. diff --git a/Resources/Images/Perso1/png/Jump/perso1-jump01.png b/Resources/Images/Perso1/png/Jump/perso1-jump01.png Binary files differ. diff --git a/Resources/Images/Perso1/png/Jump/perso1-jump02.png b/Resources/Images/Perso1/png/Jump/perso1-jump02.png Binary files differ. diff --git a/Resources/Images/Perso1/png/Jump/perso1-jump03.png b/Resources/Images/Perso1/png/Jump/perso1-jump03.png Binary files differ. diff --git a/Resources/Images/Perso1/png/Jump/perso1-jump05.png b/Resources/Images/Perso1/png/Jump/perso1-jump05.png Binary files differ. diff --git a/Resources/Images/Perso1/png/Jump/perso1-jump06.png b/Resources/Images/Perso1/png/Jump/perso1-jump06.png Binary files differ. diff --git a/Resources/Images/Perso1/png/sword_bighit/perso1-bighit00.png b/Resources/Images/Perso1/png/sword_bighit/perso1-bighit00.png Binary files differ. diff --git a/Resources/Images/Perso1/png/sword_bighit/perso1-bighit01.png b/Resources/Images/Perso1/png/sword_bighit/perso1-bighit01.png Binary files differ. diff --git a/Resources/Images/Perso1/png/sword_bighit/perso1-bighit02.png b/Resources/Images/Perso1/png/sword_bighit/perso1-bighit02.png Binary files differ. diff --git a/Resources/Images/Perso1/png/sword_bighit/perso1-bighit03.png b/Resources/Images/Perso1/png/sword_bighit/perso1-bighit03.png Binary files differ. diff --git a/Resources/Images/Perso1/png/sword_bighit/perso1-bighit04.png b/Resources/Images/Perso1/png/sword_bighit/perso1-bighit04.png Binary files differ. diff --git a/Resources/Images/Perso1/png/sword_bighit/perso1-bighit05.png b/Resources/Images/Perso1/png/sword_bighit/perso1-bighit05.png Binary files differ. diff --git a/Resources/Images/Perso1/png/sword_bighit/perso1-bighit_rendu00.png b/Resources/Images/Perso1/png/sword_bighit/perso1-bighit_rendu00.png Binary files differ. diff --git a/Resources/Images/Perso1/png/sword_bighit/perso1-bighit_rendu04.png b/Resources/Images/Perso1/png/sword_bighit/perso1-bighit_rendu04.png Binary files differ. diff --git a/Resources/Images/Perso1/png/sword_bighit/sword_00.png b/Resources/Images/Perso1/png/sword_bighit/sword_00.png Binary files differ. diff --git a/Resources/Images/Perso1/png/sword_bighit/sword_01.png b/Resources/Images/Perso1/png/sword_bighit/sword_01.png Binary files differ. diff --git a/Resources/Images/Perso1/png/sword_bighit/sword_02.png b/Resources/Images/Perso1/png/sword_bighit/sword_02.png Binary files differ. diff --git a/Resources/Images/Perso1/png/sword_bighit/sword_03.png b/Resources/Images/Perso1/png/sword_bighit/sword_03.png Binary files differ. diff --git a/Resources/Images/Perso1/png/sword_bighit/sword_04.png b/Resources/Images/Perso1/png/sword_bighit/sword_04.png Binary files differ. diff --git a/Resources/Images/Perso1/png/sword_bighit/sword_05.png b/Resources/Images/Perso1/png/sword_bighit/sword_05.png Binary files differ. diff --git a/Resources/Images/Perso1/psd/Bow_hit.psd b/Resources/Images/Perso1/psd/Bow_hit.psd Binary files differ. diff --git a/Resources/Images/Perso1/psd/died.psd b/Resources/Images/Perso1/psd/died.psd Binary files differ. diff --git a/Resources/Images/Perso1/psd/jump.psd b/Resources/Images/Perso1/psd/jump.psd Binary files differ. diff --git a/Resources/Images/Perso1/psd/perso1-breathe.psd b/Resources/Images/Perso1/psd/perso1-breathe.psd Binary files differ. diff --git a/Resources/Images/Perso1/psd/perso1-run.psd b/Resources/Images/Perso1/psd/perso1-run.psd Binary files differ. diff --git a/Resources/Images/Perso1/psd/sonné.psd b/Resources/Images/Perso1/psd/sonné.psd Binary files differ. diff --git a/Resources/Images/Perso1/psd/sword_bighit.psd b/Resources/Images/Perso1/psd/sword_bighit.psd Binary files differ. diff --git a/Resources/Images/Perso1/sword_bighit.gif b/Resources/Images/Perso1/sword_bighit.gif Binary files differ. diff --git a/Resources/Images/background.png b/Resources/Images/background.png Binary files differ. diff --git a/Resources/Images/mob1/attack.gif b/Resources/Images/mob1/attack.gif Binary files differ. diff --git a/Resources/Images/mob1/mob1.1/_DS_Store b/Resources/Images/mob1/mob1.1/_DS_Store Binary files differ. diff --git a/Resources/Images/mob1/mob1.1/mob1.1.psd b/Resources/Images/mob1/mob1.1/mob1.1.psd Binary files differ. diff --git a/Resources/Images/mob1/mob1.1/mob1.2.psd b/Resources/Images/mob1/mob1.1/mob1.2.psd Binary files differ. diff --git a/Resources/Images/mob1/mob1.1/static/mob1-static02.png b/Resources/Images/mob1/mob1.1/static/mob1-static02.png Binary files differ. diff --git a/Resources/Images/mob1/mob1.gif b/Resources/Images/mob1/mob1.gif Binary files differ. diff --git a/Resources/Images/mob1/mob1.psd b/Resources/Images/mob1/mob1.psd Binary files differ. diff --git a/Resources/Images/mob1/run/mob1-run00.png b/Resources/Images/mob1/run/mob1-run00.png Binary files differ. diff --git a/Resources/Images/mob1/run/mob1-run01.png b/Resources/Images/mob1/run/mob1-run01.png Binary files differ. diff --git a/Resources/Images/mob1/run/mob1-run02.png b/Resources/Images/mob1/run/mob1-run02.png Binary files differ. diff --git a/Resources/Images/mob1/run/mob1-run03.png b/Resources/Images/mob1/run/mob1-run03.png Binary files differ. diff --git a/Resources/Images/mob1/run/mob1-run04.png b/Resources/Images/mob1/run/mob1-run04.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/Sources/inc/Characters.hpp b/Sources/inc/Characters.hpp @@ -1,4 +1,3 @@ - /** * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -28,13 +27,34 @@ # define __Characters__ # include "Weapon.hpp" -# include "Elements.hpp" # include "Log.hpp" -# include "json/json.h" + +//class Weapon; + +# ifdef __APPLE__ +# include "../../Tools/jsoncpp/include/json/json.h" +# else +# include "json/json.h" +# endif + +# include <list> +# include "../../Angel/Angel.h" +# ifndef __Elements__ +# include "Elements.hpp" +#endif class Characters : public Elements { public: + friend class Game; + + enum Orientation { + UP, + DOWN, + LEFT, + RIGHT + }; + Characters(void); Characters(std::string name); ~Characters(); @@ -43,26 +63,40 @@ class Characters : public Elements { virtual void AnimCallback(String s); virtual void BeginContact(Elements *elem, b2Contact *contact); virtual void EndContact(Elements *elem, b2Contact *contact); + Characters::Orientation getOrientation(void); + std::string getLastAction(void); // Virtual function, overwritten in childs virtual void actionCallback(std::string name, int status) {}; + virtual void equipWeapon(Weapon* weapon); + void changeCanMove(void); protected: std::string _name; + std::string _lastAction; int _id; int _size; int _maxSpeed; int _isJump; + int _isRunning; + bool _canMove; + bool _invincibility; Weapon* _weapon; + Characters::Orientation _orientation; std::list<Elements*> _grounds; + std::list<Elements*> _wallsLeft; std::list<Elements*> _walls; + std::list<Elements*> _wallsRight; Json::Value _getAttr(std::string category, std::string key); Json::Value _getAttr(std::string key); void _setCategory(std::string category); virtual void _forward(int status); virtual void _backward(int status); + virtual void _up(int status); + virtual void _down(int status); virtual void _jump(int status); virtual void _attack(int status); + virtual void _run(void); private: std::map<std::string, std::map<std::string, Json::Value> > _attr; @@ -72,4 +106,6 @@ class Characters : public Elements { void _parseJson(std::string file); }; +# include "Game.hpp" + #endif diff --git a/Sources/inc/Consumable.hpp b/Sources/inc/Consumable.hpp @@ -0,0 +1,43 @@ +/** + * 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: Consumable.hpp + * Creation: 2015-03-06 15:39 + * Manon Budin <mbudin@student.42.fr> + */ + +#ifndef __Consumable__ +# define __Consumable__ + +# include "Elements.hpp" +# include "Hero.hpp" +# include "WeaponList.hpp" +# include "Object.hpp" + +class Consumable : public Object { +public: + Consumable(); + ~Consumable(); + + void init(void); + void BeginContact(Elements *elem, b2Contact *contact); +}; + +#endif diff --git a/Sources/inc/Elements.hpp b/Sources/inc/Elements.hpp @@ -26,36 +26,34 @@ #ifndef __Elements__ # define __Elements__ + # include <map> # include <string> -# ifndef __Maps__ -# include "../inc/Game.hpp" -# endif -# include "Maps.hpp" # include "../../Angel/Angel.h" class Weapon; class Elements : public PhysicsActor { public: + friend class Game; Elements(); Elements(int id); Elements(Elements & obj); ~Elements(); - enum Orientation { - LEFT, - RIGHT, - UP, - DOWN, - }; - - void addAttribute(std::string name, std::string value); - std::string getAttribute(std::string name); void setXStart(float X); void setYStart(float Y); + void setWidth(int w); + void setHeight(int h); + void setCutWidth(int w); + void setCutHeight(int h); + void setFrame(int n); + void addAttribute(std::string name, std::string value); + std::string getAttribute(std::string name); + void removeAttr(std::string name); void display(void); std::map<std::string, std::string> getAttributes(void); + void setFrameSprite(int frame); /* Virtual function, overridden in Childs */ virtual void callback(Elements * elem) { }; @@ -66,9 +64,22 @@ public: int getOrientationY(void); int getLateralOrientation(void); +protected: + virtual void _run() {}; + private: float _XStartPos; float _YStartPos; std::map<std::string, std::string> _attributes; + int _height; + int _width; + int _cutHeight; + int _cutWidth; + int _frame; }; + +# include "Characters.hpp" +# include "Maps.hpp" +# include "Game.hpp" + #endif diff --git a/Sources/inc/Enemy.hpp b/Sources/inc/Enemy.hpp @@ -27,17 +27,16 @@ #ifndef __Enemy__ # define __Enemy__ -# include "Elements.hpp" -# include "Hero.hpp" +# include "Characters.hpp" -class Enemy : public Elements { +class Enemy : public Characters { public: Enemy(); ~Enemy(); - virtual void callback(Elements * elem); - void ReceiveMessage(Message *m); + void actionCallback(std::string name, int status); void init(void); + void BeginContact(Elements* m, b2Contact* contact); }; #endif diff --git a/Sources/inc/Equipment.hpp b/Sources/inc/Equipment.hpp @@ -0,0 +1,46 @@ +/** + * 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: Equipment.hpp + * Creation: 2015-03-06 15:51 + * Manon Budin <mbudin@student.42.fr> + */ + +#ifndef __Equipment__ +# define __Equipment__ + +# include "Elements.hpp" +# include "Hero.hpp" +# include "WeaponList.hpp" +# include "Object.hpp" + +class Equipment : public Object { +public: + Equipment(); + ~Equipment(); + + void init(void); + Weapon* getWeapon(void); + void BeginContact(Elements *elem, b2Contact *contact); +private: + Weapon* _weapon; +}; + +#endif diff --git a/Sources/inc/Game.hpp b/Sources/inc/Game.hpp @@ -26,13 +26,20 @@ #ifndef __Game__ # define __Game__ +class Map; +class Maps; +# ifndef __Map__ # include "Maps.hpp" +# endif # ifndef __Elements__ # include "main.hpp" # include "Elements.hpp" # endif # include "GameContactListener.hpp" # include "ContactFilter.hpp" +# include "Characters.hpp" +# include "WeaponList.hpp" +class WeaponList; class Game { @@ -44,22 +51,30 @@ class Game { void grid(void); void start(void); void readMaps(void); - void initMap(void); - void displayMap(t_map map); void displayHero(Elements & Hero); void displayEnemy(Elements & Enemy); + void displayObject(Elements & Object); + void showMap(void); static void destroyAllBodies(void); + static void addToDestroyList(Elements *m); static int getNextId(void); static void addElement(Elements & elem); + static void delElement(Elements *elem); static void listElement(void); static void callCallbacks(int a, int b); + static void startRunning(Elements *c); + static void stopRunning(Elements *c); + static void makeItRun(void); Maps *maps; static int currentIds; static std::map<int, Elements *> elementMap; + static std::list<Elements *> bodiesToDestroy; + static std::list<Elements *> runningCharac; + static WeaponList* wList; private: float beginXHero; diff --git a/Sources/inc/Hero.hpp b/Sources/inc/Hero.hpp @@ -28,7 +28,6 @@ # include "Characters.hpp" # include "Weapon.hpp" -# include "Shooter.hpp" class Hero : public Characters { @@ -37,11 +36,8 @@ class Hero : public Characters { ~Hero(); void init(); + virtual void BeginContact(Elements* m, b2Contact* contact); virtual void actionCallback(std::string name, int status); - - private: - Shooter *_shooter; - }; #endif diff --git a/Sources/inc/Hitbox.hpp b/Sources/inc/Hitbox.hpp @@ -0,0 +1,42 @@ +/** + * 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: Hitbox.hpp + * Creation: 2015-02-27 04:45 + * Vincent Rey <vrey@student.42.fr> + */ + +#ifndef __Hitbox__ +# define __Hitbox__ + +# include "main.hpp" + +class Hitbox { +public: + Hitbox(); + ~Hitbox(); +private: + b2PolygonShape _getPolygon(std::string res); + b2PolygonShape _parseJson(std::string res); + + std::list<b2PolygonShape> _hitboxes; +}; + +#endif diff --git a/Sources/inc/LevelGenerator.hpp b/Sources/inc/LevelGenerator.hpp @@ -0,0 +1,57 @@ +/** + * 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: LevelGenerator.hpp + * Creation: 2015-03-02 16:05 + * Matthieu Maudet <mmaudet@student.42.fr> + */ + +#ifndef __LevelGenerator__ +# define __LevelGenerator__ + +# include <vector> +# include <list> +# include <cstdlib> +# include <ctime> + +# include "Room.hpp" + +class LevelGenerator { + + public: + LevelGenerator(int height, int width, int minPathLenght, int roomPopRate, int doorsPopRate); + ~LevelGenerator(); + + void execute(); + + private: + int _height; + int _width; + int _nbMaps; + int _minPathLenght; + int _roomPopRate; + int _doorsPopRate; + std::vector<std::vector<int> > _graph; + std::list<Room> *_rooms; + + LevelGenerator(); +}; + +#endif diff --git a/Sources/inc/Map.hpp b/Sources/inc/Map.hpp @@ -0,0 +1,76 @@ +/** + * 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: Map.hpp + * Creation: 2015-02-02 19:06 + * Louis Solofrizzo <louis@ne02ptzero.me> + */ + +#ifndef __Map__ +# define __Map__ + +# include <vector> +# include <list> +# include <iostream> +# include "Game.hpp" + +# ifdef __APPLE__ +# include "../../Tools/jsoncpp/include/json/json.h" +# else +# include "json/json.h" +# endif + +class Map { + + public: + Map(); + Map(std::string name); + ~Map(); + + void setHeight(int h); + void setWidth(int w); + void setImage(std::string n); + void setTileHeight(int h); + void setTileWidth(int w); + void setImageHeight(int h); + void setImageWidth(int w); + void addElement(Elements *e); + void addMapElement(int n); + void setMap(std::vector<int> map); + void setProperties(std::map<int, std::map<std::string, Json::Value> > p); + + void display(void); + + private: + int _mapCount; + std::string _name; + int _height; + int _width; + std::string _image; + std::vector<int> _map; + int _tileHeight; + int _tileWidth; + int _imageHeight; + int _imageWidth; + std::list<Elements *> _elems; + std::map<int, std::map<std::string, Json::Value> > _properties; +}; + +#endif diff --git a/Sources/inc/Maps.hpp b/Sources/inc/Maps.hpp @@ -36,22 +36,13 @@ # include <list> # include <string> # include <vector> +# include <map> -# include "Elements.hpp" # include "main.hpp" +# include "Elements.hpp" +# include "Map.hpp" -class Elements; - -typedef struct s_map { - int id; - std::string name; - std::string world; - std::string callbackBegin; - std::string callbackEnd; - std::map<int, Elements *> elements; - std::vector<std::vector<int> > map; - -} t_map; +class Elements; class Maps { public: @@ -59,8 +50,8 @@ class Maps { Maps(std::string directory); ~Maps(); - std::list<t_map> getFormattedMaps(void); void readMaps(void); + void firstOne(void); private: void _getMap(void); @@ -68,7 +59,8 @@ class Maps { std::string _directory; Json::Value _root; Json::Reader _reader; - std::list<t_map> _maps; + std::list<Map *> _maps; }; +# include "Elements.hpp" #endif diff --git a/Sources/inc/Object.hpp b/Sources/inc/Object.hpp @@ -0,0 +1,44 @@ +/** + * 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: Object.hpp + * Creation: 2015-03-03 13:10 + * Manon Budin <mbudin@student.42.fr> + */ + +#ifndef __Object__ +# define __Object__ + +# 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); +}; + +#endif diff --git a/Sources/inc/Projectile.hpp b/Sources/inc/Projectile.hpp @@ -28,18 +28,29 @@ # include "Elements.hpp" -/* -** Default constructor -** @param: Elements * -*/ +class Characters; class Projectile: public Elements { public: Projectile(float x, float y, int direction, std::string owner); + Projectile(Weapon *w, Characters *c); ~Projectile(); + + std::string getName(void); + std::string getFlavor(void); + std::string getAttack(void); + float getActive(void); + int getSize(void); + int getDamage(void); + int getPushback(void); + float getRecovery(void); + int attackReady(void); + void BeginContact(Elements *elem, b2Contact *contact); void EndContact(Elements *elem, b2Contact *contact); - void ReceiveMessage(Message *m); + void ReceiveMessage(Message *m); +private: + Weapon* _weapon; }; #endif diff --git a/Sources/inc/Room.hpp b/Sources/inc/Room.hpp @@ -0,0 +1,54 @@ +/** + * 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: LevelGenerator.hpp + * Creation: 2015-03-02 16:05 + * Matthieu Maudet <mmaudet@student.42.fr> + */ + +#ifndef __Room__ +# define __Room__ + +enum DepthType {CEIL, STD, FLOOR}; + +enum SpecialType {ENTRY, BOSS, CHEST, MONSTER, MINIBOSS, ITEM}; + +class Room { + + public: + Room(int id, int x, int y, int mapId); + ~Room(); + + private: + int _id; + int _y; + int _x; + int _mapId; + DepthType _depthType; + SpecialType _specialType; + bool _topDoor; + bool _leftDoor; + bool _bottomDoor; + bool _rightDoor; + + Room(void); +}; + +#endif diff --git a/Sources/inc/Shooter.hpp b/Sources/inc/Shooter.hpp @@ -41,7 +41,7 @@ private: float _rate; int _orientation; bool _straight; - std::string _spriteName; + std::string _spriteName; }; diff --git a/Sources/inc/Weapon.hpp b/Sources/inc/Weapon.hpp @@ -28,34 +28,53 @@ # include "Log.hpp" # include "Elements.hpp" -# include "json/json.h" -/* -** Default constructor, using the element that called the attack -** @param: Elements * -*/ +# include "Projectile.hpp" +# ifdef __APPLE__ +# include "../../Tools/jsoncpp/include/json/json.h" +# else +# include "json/json.h" +# endif + +class Characters; + class Weapon: public Elements { public: Weapon(std::string name); + Weapon(Weapon* weapon); + Weapon(Weapon* weapon, Characters* c); ~Weapon(void); - void attack(int, int, int, int, b2Vec2); + void attack(Characters *c); void BeginContact(Elements *elem, b2Contact *contact); void EndContact(Elements *elem, b2Contact *contact); void ReceiveMessage(Message *m); + std::string getName(void); + std::string getFlavor(void); + std::string getAttack(void); + float getActive(void); + int getSize(void); + int getDamage(void); + int getPushback(void); + float getRecovery(void); + int attackReady(void); + private: std::map<std::string, std::map<std::string, Json::Value> > _attr; std::string _name; std::string _flavor; + std::string _attack; int _canAttack; - int _recovery; - int _active; + float _recovery; + float _active; int _size; + int _damage; + int _pushback; void _readFile(std::string name); + void _readFileFromFilename(std::string name); void _parseJson(std::string file); -// WeaponArea* _attackBox; protected: Json::Value _getAttr(std::string category, std::string key); diff --git a/Sources/inc/WeaponList.hpp b/Sources/inc/WeaponList.hpp @@ -0,0 +1,60 @@ +/** + * 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: WeaponList.hpp + * Creation: 2015-02-18 14:00 + * Vincent Rey <vrey@student.42.fr> + */ + + +#ifndef __WeaponList__ +# define __WeaponList__ + +# include "Weapon.hpp" +# include "Log.hpp" +# include "Elements.hpp" +# include <sstream> + +# ifdef __APPLE__ +# include "../../Tools/jsoncpp/include/json/json.h" +# else +# include "json/json.h" +# endif + +# include <list> +# include "../../Angel/Angel.h" +# ifndef __Elements__ +# include "Elements.hpp" +#endif + +class WeaponList: public Elements { +public: + WeaponList(void); + ~WeaponList(void); + + void statWeapon(std::string); + Weapon* getWeapon(std::string); + +private: + std::list<Weapon*> _allWeapons; + +}; + +#endif diff --git a/Sources/src/Characters.cpp b/Sources/src/Characters.cpp @@ -36,14 +36,19 @@ Characters::Characters(void) { * Main constructor * @param: name (std::string) */ -Characters::Characters(std::string name) : _name(name) { +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->SetRestitution(0.0f); this->SetFixedRotation(true); + this->_orientation = RIGHT; this->_readFile(name); + this->_canMove = true; + this->_invincibility = false; + this->_grounds.clear(); + this->_walls.clear(); } /** @@ -63,6 +68,7 @@ void Characters::_readFile(std::string name) { std::ifstream fd; file = "./Resources/Elements/" + name + ".json"; + fd.open(file.c_str()); if (!fd.is_open()) Log::error("Can't open the file for the " + @@ -90,7 +96,6 @@ 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->_weapon = new Weapon(json["infos"].get("weapon", "").asString()); this->addAttribute("spritesFrame", json["infos"].get("sprites", "").asString()); for (i = json["Actions"].begin(); i != json["Actions"].end(); i++) { @@ -153,22 +158,34 @@ void Characters::ReceiveMessage(Message *m) { std::string name, attrName; int status; - Log::info(m->GetMessageName()); + if (m->GetMessageName() == "canMove") { + this->_canMove = true; + } + else if (m->GetMessageName() == "endInvincibility") { + this->_invincibility = false; + } for (i = this->_attr.begin(); i != this->_attr.end(); i++) { attrName = this->_getAttr(i->first, "subscribe").asString(); if (!strncmp(attrName.c_str(), m->GetMessageName().c_str(), strlen(attrName.c_str()))) { // Get the key status (1 = Pressed, 0 = Released) status = (m->GetMessageName().substr(strlen(attrName.c_str()), 7) == "Pressed" ? 1 : 0); + if (this->_canMove == false) + return; if (attrName == "forward") { this->_forward(status); } else if (attrName == "backward") { this->_backward(status); + } else if (attrName == "up") { + this->_up(status); + } else if (attrName == "down") { + this->_down(status); } else if (attrName == "jump") { this->_jump(status); - } else if ("attack") { + } else if (attrName == "attack") { this->_attack(status); } + this->_lastAction = attrName; this->actionCallback(attrName, status); } } @@ -182,9 +199,20 @@ void Characters::ReceiveMessage(Message *m) { void Characters::AnimCallback(String s) { this->_setCategory("breath"); if (s == "base") { - this->PlaySpriteAnimation(this->_getAttr("time").asFloat(), SAT_OneShot, - this->_getAttr("beginFrame").asInt(), - this->_getAttr("endFrame").asInt(), "base"); + if (this->_isRunning == 0) { + this->PlaySpriteAnimation(this->_getAttr("time").asFloat(), SAT_OneShot, + this->_getAttr("beginFrame").asInt(), + this->_getAttr("endFrame").asInt(), "base"); + } else { + if (this->_isRunning == 1) { + this->_setCategory("forward"); + } else if (this->_isRunning == 2) { + this->_setCategory("backward"); + } + this->PlaySpriteAnimation(this->_getAttr("time").asFloat(), SAT_Loop, + this->_getAttr("beginFrame").asInt(), + this->_getAttr("endFrame").asInt()); + } } } @@ -195,27 +223,26 @@ void Characters::AnimCallback(String s) { * @note: This function is called just before a collision */ void Characters::BeginContact(Elements *elem, b2Contact *contact) { - if (elem->getAttributes()["type"] == "wall" || - elem->getAttributes()["type"] == "ground" || - elem->getAttributes()["type"] == "corner") { - if (this->GetBody()->GetWorldCenter().y > elem->GetBody()->GetWorldCenter().y + 1) { + if (elem->getAttributes()["type"] == "ground") { + if (this->GetBody()->GetWorldCenter().y - 1 >= elem->GetBody()->GetWorldCenter().y) { if (this->_grounds.size() > 0) contact->SetEnabled(false); - else { - 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->_isJump > 0) { + this->_isJump = 0; + this->PlaySpriteAnimation(0.1f, SAT_OneShot, this->_getAttr("jump", "endFrame").asInt(), + this->_getAttr("jump", "endFrame").asInt(), "base"); } this->_grounds.push_back(elem); - } else { - if (this->_walls.size() > 0) + } else if (this->GetBody()->GetWorldCenter().x >= elem->GetBody()->GetWorldCenter().x) { + if (this->_wallsLeft.size() > 0) + contact->SetEnabled(false); + this->_wallsLeft.push_back(elem); + } else if (this->GetBody()->GetWorldCenter().x < elem->GetBody()->GetWorldCenter().x) { + if (this->_wallsRight.size() > 0) contact->SetEnabled(false); - this->_walls.push_back(elem); + this->_wallsRight.push_back(elem); } } - } /** @@ -225,18 +252,29 @@ void Characters::BeginContact(Elements *elem, b2Contact *contact) { * @note: This function is called just after the elements leave another */ void Characters::EndContact(Elements *elem, b2Contact *contact) { - if (elem->getAttributes()["type"] == "wall" || - elem->getAttributes()["type"] == "ground" || - elem->getAttributes()["type"] == "corner") { - if (this->GetBody()->GetWorldCenter().y > elem->GetBody()->GetWorldCenter().y + 1) { + if (elem->getAttributes()["type"] == "ground") { + this->_wallsLeft.remove(elem); + this->_wallsRight.remove(elem); + if (this->_grounds.size() == 1) { this->_grounds.remove(elem); + 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"); } - else { - this->_walls.remove(elem); - } + else + this->_grounds.remove(elem); } } +void Characters::_run(void) { + if (this->_isRunning == 1) + this->_forward(2); + else if (this->_isRunning == 2) + this->_backward(2); +} + /****************************/ /* */ /* ACTIONS */ @@ -249,16 +287,27 @@ void Characters::EndContact(Elements *elem, b2Contact *contact) { */ void Characters::_forward(int status) { this->_setCategory("forward"); - if (status == 1) { - if (this->GetSpriteFrame() < this->_getAttr("beginFrame").asInt()) + if (status == 1){ + this->_orientation = RIGHT; + 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()); - if (this->GetBody()->GetLinearVelocity().x < this->_maxSpeed) - this->ApplyLinearImpulse(Vector2(this->_getAttr("force").asFloat(), 0), Vector2(0, 0)); - } else { + 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) { this->GetBody()->SetLinearVelocity(b2Vec2(0, this->GetBody()->GetLinearVelocity().y)); - this->AnimCallback("base"); + Game::stopRunning(this); + this->_isRunning = 0; + if (!this->_isJump) + this->AnimCallback("base"); + } else { + if (this->GetBody()->GetLinearVelocity().x < this->_maxSpeed) { + if (this->_wallsRight.size() == 0 && this->_canMove == true) + this->GetBody()->SetLinearVelocity(b2Vec2(this->_getAttr("force").asFloat(), this->GetBody()->GetLinearVelocity().y)); + } } return ; } @@ -268,17 +317,28 @@ void Characters::_forward(int status) { * @param: status (int) */ void Characters::_backward(int status) { - this->_setCategory("backward"); + this->_setCategory("backward"); if (status == 1) { - if (this->GetSpriteFrame() < this->_getAttr("beginFrame").asInt()) + this->_orientation = 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()); - if (this->GetBody()->GetLinearVelocity().x > -(this->_maxSpeed)) - this->ApplyLinearImpulse(Vector2(-(this->_getAttr("force").asFloat()), 0), Vector2(0, 0)); - } else { + 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) { this->GetBody()->SetLinearVelocity(b2Vec2(0, this->GetBody()->GetLinearVelocity().y)); - this->AnimCallback("base"); + 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) + this->GetBody()->SetLinearVelocity(b2Vec2(-this->_getAttr("force").asFloat(), this->GetBody()->GetLinearVelocity().y)); + } } return ; } @@ -289,22 +349,59 @@ void Characters::_backward(int status) { */ void Characters::_jump(int status) { this->_setCategory("jump"); + if (status == 1) { if (this->_isJump == 0 || (this->_isJump <= 1 && this->_getAttr("double").asInt() == 1)) { - this->ApplyLinearImpulse(Vector2(0, this->_getAttr("force").asFloat()), Vector2(0, 0)); + if (this->_isJump >= 1) { + this->GetBody()->SetLinearVelocity(b2Vec2(this->GetBody()->GetLinearVelocity().x, this->_getAttr("rejump").asFloat())); + } + 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"); - this->_isJump++; + if (this->_grounds.size() == 0) + this->_isJump++; } } return ; } /** + * Called when pressing the UP button + * @param: status (int) + */ + +void Characters::_up(int status) { + if (status == 1) + this->_orientation = UP; +} + +/** + * Called when pressing the DOWN button + * @param: status (int) + */ + +void Characters::_down(int status) { + if (status == 1) + this->_orientation = DOWN; +} + +/** * Attack action * @param: status (int) */ void Characters::_attack(int status) { - this->_weapon->attack(this->GetBody()->GetWorldCenter().x + 0.75f , this->GetBody()->GetWorldCenter().y, 0, 0, this->GetBody()->GetLinearVelocity()); + if (status == 1 && this->_weapon->attackReady() == 1) { + this->_weapon->attack(this); + } } + +void Characters::equipWeapon(Weapon* weapon) { + this->_weapon = new Weapon(weapon); +} + +Characters::Orientation Characters::getOrientation(void) { return this->_orientation; } +std::string Characters::getLastAction(void) { return this->_lastAction; }; +void Characters::changeCanMove(void) { this->_canMove = (this->_canMove ? false : true); }; diff --git a/Sources/src/Consumable.cpp b/Sources/src/Consumable.cpp @@ -0,0 +1,56 @@ +/** + * 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: Consumable.cpp + * Creation: 2015-03-06 15:37 + * Manon Budin <mbudin@student.42.fr> + */ + +#include "Consumable.hpp" + + +/** + * Basic Constructor + */ +Consumable::Consumable(void) { + this->addAttribute("type2", "Consumable"); + this->SetColor(1,1,1,1); + this->SetPosition(6, -11); + this->InitPhysics(); + theWorld.Add(this); + Log::info("wjorwbgurw"); +} + +void Consumable::BeginContact(Elements *elem, b2Contact *contact) { + if (elem->getAttributes()["type"] == "Hero"){ + Game::bodiesToDestroy.push_back(this); + contact->SetEnabled(false); + } +} + +void Consumable::init(void) { +} + +/* + * Basic Destructor + */ +Consumable::~Consumable(void) { + return; +} diff --git a/Sources/src/ContactFilter.cpp b/Sources/src/ContactFilter.cpp @@ -34,7 +34,6 @@ bool ContactFilter::ShouldCollide(b2Fixture* fixA, b2Fixture* fixB) { std::string attrB = static_cast<Elements*>(fixB->GetBody()->GetUserData())->getAttributes()["type"]; if ((attrA == "Hero" || attrB == "Hero") && ((attrA == "heroWeapon" || attrB == "heroWeapon") || (attrA == "heroProjectile" || attrB == "heroProjectile"))) { - // std::cout << "hello" << std::endl; return false; } else return true; diff --git a/Sources/src/Elements.cpp b/Sources/src/Elements.cpp @@ -70,6 +70,15 @@ void Elements::addAttribute(std::string name, std::string value) { } /** + * Remove an attribute form the list + * @param: name (std::string) + */ +void Elements::removeAttr(std::string name) { + if (this->_attributes.find(name) != this->_attributes.end()) + this->_attributes.erase(this->_attributes.find(name)); +} + +/** * Get an attribute value * @param: name (std::string) * @return: this->_attributes[name] @@ -80,6 +89,32 @@ std::string Elements::getAttribute(std::string name) { return ""; } +void Elements::setFrameSprite(int frame) { + int imgHeight = this->_height; + int imgWidth = this->_width; + int cutWidth = 16, cutHeight = 16; + float nbPerRow = imgWidth / cutWidth; + float nbPerColumn = imgHeight / cutHeight; + float fY = (1.0f / float(imgHeight)) * float(cutHeight); + float fX = (1.0f / float(imgWidth)) * float(cutWidth); + int i; + float tY = 1.0f - fY; + float tX = fX; + float tX2 = 0.0f; + float tY2 = 1.0f; + for (i = 0; i < frame; i++) { + tX += fX; + tX2 += fX; + if (tX >= 1.0f) { + tX = 0.0f; + tX2 = fX; + tY -= fY; + tY2 -= fY; + } + } + this->SetUVs(Vector2(tX, tY), Vector2(tX2, tY2)); +} + /** * Display the Element on the screen */ @@ -92,6 +127,9 @@ void Elements::display(void) { this->SetSprite(this->getAttribute("sprite")); else if (this->getAttribute("spritesFrame") != "") { this->LoadSpriteFrames(this->getAttribute("spritesFrame")); + } else if (this->getAttribute("spriteMap") != "") { + this->SetSprite(this->getAttribute("image")); + this->setFrameSprite(this->_frame - 2); } else this->SetColor(0, 0, 0, 0); this->SetSize(1.0f); @@ -107,8 +145,10 @@ void Elements::display(void) { this->SetShapeType(PhysicsActor::SHAPETYPE_BOX); } - if (this->getAttribute("physic") != "") + if (this->getAttribute("physic") != "") { this->InitPhysics(); + std::cout << "Init phy" << std::endl; + } theWorld.Add(this); } @@ -116,6 +156,11 @@ void Elements::display(void) { void Elements::setXStart(float X) { this->_XStartPos = X; }; void Elements::setYStart(float Y) { this->_YStartPos = Y; }; +void Elements::setWidth(int w) { this->_width = w; }; +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; }; /* 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 @@ -25,56 +25,48 @@ #include "../inc/Enemy.hpp" -/** - * Basic Constructor - */ -Enemy::Enemy(void) { - this->addAttribute("physic", "1"); - this->addAttribute("type", "Enemy"); - this->SetDensity(1.0f); - this->SetFriction(1.0f); - this->SetRestitution(0.0f); - this->SetFixedRotation(true); - this->SetDrawShape(ADS_Square); - this->addAttribute("spritesFrame", "Resources/Images/Enemy/enemy_000.png"); +Enemy::Enemy(void) : Characters("Enemy") { + return ; } /** - * Collision with another element - * @param: elem (Elements *) + * Basic Destructor */ -void Enemy::callback(Elements * elem) { - if (elem->getAttributes()["type"] == "Hero") { - this->GetBody()->SetLinearVelocity(b2Vec2(0, 0)); - - if (this->GetBody()->GetWorldCenter().x > elem->GetBody()->GetWorldCenter().x) - this->ApplyLinearImpulse(Vector2(10, 10), Vector2(0, 0)); - else - this->ApplyLinearImpulse(Vector2(-10, 10), Vector2(0, 0)); - theSwitchboard.DeferredBroadcast(new Message("canMove"), 1); - theSwitchboard.DeferredBroadcast(new Message("endInvincibility"), 1.5); - } -} - +Enemy::~Enemy(void) { + return ; +} /** - * Receive broadcasts message - * @param: (Message *) + * Init Animation */ -void Enemy::ReceiveMessage(Message *m) { - return; -} - - - void Enemy::init(void) { - this->PlaySpriteAnimation(0.1f, SAT_Loop, 0, 4, "Jump"); + this->AnimCallback("base"); } /** - * Basic Destructor + * Mother's callback for actions + * @param: name (std::string) + * @param: status (int) */ -Enemy::~Enemy(void) { - return; +void Enemy::actionCallback(std::string name, int status) { + return ; } +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)); + } + } 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)); + } + } +} diff --git a/Sources/src/Equipment.cpp b/Sources/src/Equipment.cpp @@ -0,0 +1,60 @@ +/** + * 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: Equipment.cpp + * Creation: 2015-03-06 15:51 + * Manon Budin <mbudin@student.42.fr> + */ + +#include "Equipment.hpp" + + +/** + * Basic Constructor + */ +Equipment::Equipment(void) { + this->addAttribute("type2", "Equipment"); + this->SetColor(0,1,1,1); + this->SetPosition(5, -10); + this->InitPhysics(); + theWorld.Add(this); + this->_weapon = new Weapon(Game::wList->getWeapon("Bow")); +} + +void Equipment::BeginContact(Elements *elem, b2Contact *contact) { + if (elem->getAttributes()["type"] == "Hero"){ + TextActor *t; + //static_cast<Characters*>(elem)->equipWeapon(this->_weapon); + } +} + +void Equipment::init(void) { +} + +Weapon* Equipment::getWeapon(void) { + return this->_weapon; +} + +/* + * Basic Destructor + */ +Equipment::~Equipment(void) { + return; +} diff --git a/Sources/src/Game.cpp b/Sources/src/Game.cpp @@ -32,7 +32,6 @@ Game::Game(void) { theWorld.Initialize(1920, 1080, NAME); theWorld.SetupPhysics(); - //this->elements = new Elements(); GameContactListener *gListen = new GameContactListener(); ContactFilter *filter = new ContactFilter(); theWorld.GetPhysicsWorld().SetContactFilter(filter); @@ -53,7 +52,6 @@ Game::Game(unsigned int width, unsigned int height) { ContactFilter *filter = new ContactFilter(); theWorld.GetPhysicsWorld().SetContactFilter(filter); theWorld.GetPhysicsWorld().SetContactListener(gListen); - //this->elements = new Elements(); this->maps = new Maps("Maps/"); } @@ -61,7 +59,6 @@ Game::Game(unsigned int width, unsigned int height) { * Destructor */ Game::~Game(void) { - //delete this->elements; return ; } @@ -87,48 +84,10 @@ void Game::readMaps(void) { } /** - * Display a map - * @param: map (t_map) - */ -void Game::displayMap(t_map map) { - std::vector<std::vector<int> >::iterator i; - std::vector<int>::iterator v; - float x = 0.0f, y = -10.0f; - Elements *block; - Elements &tmp = *(new Elements()); - - for (i = map.map.begin(); i != map.map.end(); i++, x -= 1.0f) { - for (y = -10.0f, v = i->begin(); v != i->end(); v++, y += 1.0f) { - if ((*v) == 0) - block = new Elements(); - else { - tmp = (*(map.elements[(*v)])); - block = new Elements(tmp); - } - block->setXStart(y); - block->setYStart(x); - block->display(); - if (block->getAttribute("attribute") == "start") { - this->beginXHero = y; - this->beginYHero = x; - } - } - } -} - -/** * Display the first map */ -void Game::initMap(void) { - std::list<t_map> maps = this->maps->getFormattedMaps(); - std::list<t_map>::iterator it; - - for (it = maps.begin(); it != maps.end(); it++) { - if ((*it).id == 1) { - this->displayMap(*it); - } - std::cout << (*it).id << std::endl; - } +void Game::showMap(void) { + this->maps->firstOne(); } /** @@ -136,8 +95,8 @@ void Game::initMap(void) { * @param: Hero (Elements &) */ void Game::displayHero(Elements & Hero) { - Hero.setXStart(this->beginXHero); - Hero.setYStart(this->beginYHero); + Hero.setXStart(10); + Hero.setYStart(-10); Hero.addAttribute("hero", "1"); Hero.display(); } @@ -147,13 +106,24 @@ void Game::displayHero(Elements & Hero) { * @param: Enemy (Elements &) */ void Game::displayEnemy(Elements & Enemy) { - Enemy.setXStart(3); - Enemy.setYStart(3); + Enemy.setXStart(5); + Enemy.setYStart(-5); Enemy.addAttribute("enemy", "1"); Enemy.display(); } /** + * Display the Object + * @param: Object (Elements &) + */ +void Game::displayObject(Elements & Object) { + Object.setXStart(6); + Object.setYStart(6); + Object.addAttribute("Object", "1"); + Object.display(); +} + +/** * Get the current id, for the intern elements map */ int Game::getNextId(void) { @@ -170,6 +140,17 @@ void Game::addElement(Elements & elem) { } /** + * Deletes an element from the intern map + * @param: elem (Elements &) + */ +void Game::delElement(Elements* elem) { + for (int i = 0; Game::elementMap[i]; i++) { + if (Game::elementMap[i] == elem) + Game::elementMap.erase(i); + } +} + +/** * Call the collision callbacks on two objects * @param: a (int) * @param: b (int) @@ -192,9 +173,51 @@ void Game::listElement(void) { } } +/** + * Call to add an element to the destroy list after the tick() + * @param: m (Elements*) + */ + +void Game::addToDestroyList(Elements *m) { + for (std::list<Elements*>::iterator it = Game::bodiesToDestroy.begin(); it != Game::bodiesToDestroy.end(); it++) { + if ((*it) == m) + return; + } + Game::bodiesToDestroy.push_back(m); +} + +/** + * Called after each tick() in order to destroy all elements set to destroy + */ + void Game::destroyAllBodies(void) { + for (std::list<Elements*>::iterator it = Game::bodiesToDestroy.begin(); it != Game::bodiesToDestroy.end(); it++) { + theWorld.GetPhysicsWorld().DestroyBody((*it)->GetBody()); + theWorld.Remove(*it); + Game::delElement(*it); + } + Game::bodiesToDestroy.clear(); +} + +void Game::startRunning(Elements *c) { + Game::runningCharac.push_back(c); +} + +void Game::stopRunning(Elements *c) { + Game::runningCharac.remove(c); +} + +void Game::makeItRun(void) { + std::list<Elements *>::iterator i; + + for (i = Game::runningCharac.begin(); i != Game::runningCharac.end(); i++) { + (*i)->_run(); + } } // Set for the statics int Game::currentIds = 0; -std::map<int, Elements *> Game::elementMap = {}; +std::map<int, Elements *> Game::elementMap = {}; +std::list<Elements *> Game::runningCharac; +std::list<Elements *> Game::bodiesToDestroy; +WeaponList* Game::wList; diff --git a/Sources/src/Hero.cpp b/Sources/src/Hero.cpp @@ -29,6 +29,8 @@ * Basic constructor */ Hero::Hero(void) : Characters("Hero") { + theSwitchboard.SubscribeTo(this, "canMove"); + theSwitchboard.SubscribeTo(this, "endInvincibility"); return ; } @@ -46,12 +48,34 @@ void Hero::init(void) { this->AnimCallback("base"); } + /** * Mother's callback for actions * @param: name (std::string) * @param: status (int) */ void Hero::actionCallback(std::string name, int status) { - std::cout << "CALLBACK " << name << std::endl; return ; } + +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); + if (this->GetBody()->GetWorldCenter().x >= elem->GetBody()->GetWorldCenter().x) { + this->ApplyLinearImpulse(Vector2(10, 10), Vector2(0, 0)); + } + else if (this->GetBody()->GetWorldCenter().x < elem->GetBody()->GetWorldCenter().x) { + this->ApplyLinearImpulse(Vector2(-10, 10), Vector2(0, 0)); + } + } +} diff --git a/Sources/src/Hitbox.cpp b/Sources/src/Hitbox.cpp @@ -0,0 +1,101 @@ +/** + * 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: Hitbox.cpp + * Creation: 2015-02-18 14:00 + * Vincent Rey <vrey@student.42.fr> + */ + +# include "Hitbox.hpp" + + +/** + * Default constructor, creating the list + * @param: Elements * + */ +Hitbox::Hitbox(void) { + DIR *dir; + struct dirent *dirEntry; + std::istringstream iss; + std::string res; + + dir = opendir("./Resources/Elements/Hitbox/"); + while (dirEntry = readdir(dir)) { + 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)); + } + } +} + +b2PolygonShape Hitbox::_getPolygon(std::string res) { + std::string file; + std::stringstream buffer; + std::ifstream fd; + + file = "./Resources/Elements/Hitbox/" + res + ".json"; + fd.open(file.c_str()); + if (!fd.is_open()) + Log::error("Can't open the file for the " + + res + " hitbox. (Expected path is Resources/Elements/Hitbox/" + res +".json)"); + buffer << fd.rdbuf(); + return this->_parseJson(buffer.str()); +} + +b2PolygonShape Hitbox::_parseJson(std::string file) { + Json::Reader read; + Json::Value json; + Json::Value hitbox; + int v, i, j; + std::vector<std::vector<int> > map; + std::vector<int> tmp; + + if (!read.parse(file, json)) + Log::error("Error in json syntax :\n" + read.getFormattedErrorMessages()); + + hitbox = json["data"]["hitbox"]; + for (v = i = j = 0; i < hitbox.size(); i++, v++) { + if (v == 10) { + map.insert(map.begin() + j, tmp); + j++; + v = 0; + tmp.clear(); + } + tmp.insert(tmp.begin() + v, hitbox[i].asInt()); + } + map.insert(map.begin() + j, tmp); + + 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 << std::endl; + } +} + +/** + * Basic destructor + */ +Hitbox::~Hitbox(void) { + return; +} diff --git a/Sources/src/LevelGenerator.cpp b/Sources/src/LevelGenerator.cpp @@ -0,0 +1,57 @@ +/** + * 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: LevelGenerator.cpp + * Creation: 2015-03-02 16:05 + * Matthieu Maudet <mmaudet@student.42.fr> + */ + +# include "../inc/LevelGenerator.hpp" +# include "../inc/Room.hpp" + +/** + * Basic constructor + */ +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>; + _nbMaps = 10; + return ; +} + +/** + * Basic Destructor + */ +LevelGenerator::~LevelGenerator(void) { + return ; +} + +void LevelGenerator::execute(void) { + int id = 0; + + for (int i = 0; i < _width; i++) { + for (int j = 0; j < _height; j++) { + if (_roomPopRate < (rand() % 100)) { + Room *newRoom = new Room(id, i, j, rand() % _nbMaps); + _rooms->push_back(*newRoom); + } + } + } +} diff --git a/Sources/src/Map.cpp b/Sources/src/Map.cpp @@ -0,0 +1,108 @@ +/** + * 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: Map.hpp + * Creation: 2015-03-02 19:10 + * Louis Solofrizzo <louis@ne02ptzero.me> + */ + +# include "Map.hpp" + +/** + * Basic constructor + */ +Map::Map(void) : _mapCount(0) { + return ; +} + +/** + * Main constructor + */ +Map::Map(std::string name) : _name(name), _mapCount(0) { + std::cout << name << std::endl; + return ; +} + +/** + * Basic destructor + */ +Map::~Map(void) { + return ; +} + +/* SETTERS */ + +void Map::setHeight(int h) { this->_height = h; }; +void Map::setWidth(int w) { this->_width = w; }; +void Map::setImage(std::string n) { this->_image = n; }; +void Map::setTileHeight(int h) { this->_tileHeight = h; }; +void Map::setTileWidth(int w) { this->_tileWidth = w; }; +void Map::setImageHeight(int h) { this->_imageHeight = h; }; +void Map::setImageWidth(int w) { this->_imageWidth = w; }; +void Map::setMap(std::vector<int> map) { this->_map = map; }; +void Map::setProperties(std::map<int, std::map<std::string, Json::Value> > p) { this->_properties = p; }; + +void Map::addElement(Elements *e) { + this->_elems.push_back(e); +} + +void Map::addMapElement(int n) { + this->_map[this->_mapCount++] = n; +} + +/** + * Display the map + */ +void Map::display(void) { + float x = 0, y = 0; + std::vector<int>::iterator it; + Elements *elem; + + for (it = this->_map.begin(); it != this->_map.end(); it++, x++) { + if (x == this->_width) { + x = 0; + y--; + } + + 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); + elem->setCutWidth(this->_tileWidth); + 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::cout << "NEW ELEM" << std::endl; + elem->display(); + } + //exit(0); +} diff --git a/Sources/src/Maps.cpp b/Sources/src/Maps.cpp @@ -77,38 +77,46 @@ void Maps::readMaps(void) { * Feed the empty list */ void Maps::_getMap(void) { - t_map current; int index, v; - Json::Value blocks; + Json::Value blocks, itr, vtr; Elements *currentBlock; - Json::ValueIterator itr; + Json::ValueIterator j, k; + Map *map; + std::map<int, std::map<std::string, Json::Value> > tileproperties; + std::vector<int> intMap; - current.id = this->_root["general"].get("id", 0).asInt(); - current.name = this->_root["general"].get("name", "Map").asString(); - current.world = this->_root["general"].get("world", "Base").asString(); - current.callbackBegin = this->_root["general"].get("callbackBegin", "basic").asString(); - current.callbackEnd = this->_root["general"].get("callbackEnd", "basic").asString(); - blocks = this->_root["Blocks"]; + map = new Map(this->_root["tilesets"][0].get("name", "").asString()); + map->setHeight(this->_root["height"].asInt()); + map->setWidth(this->_root["width"].asInt()); + itr = this->_root["tilesets"]; - for (index = 0; index < blocks.size(); index++) { - currentBlock = new Elements(index); - for (itr = blocks[std::to_string(index)].begin(); itr != blocks[std::to_string(index)].end(); itr++) - currentBlock->addAttribute(itr.key().asString(), (*itr).asString()); - current.elements[index] = currentBlock; - } + for (index = 0; index < itr.size(); index++) { + + map->setImage(itr[index].get("image", "").asString()); + map->setImageHeight(itr[index].get("imageheight", 0).asInt()); + map->setImageWidth(itr[index].get("imagewidth", 0).asInt()); + map->setTileHeight(itr[index].get("tileheight", 0).asInt()); + map->setTileWidth(itr[index].get("tilewidth", 0).asInt()); - blocks = this->_root["Map"]; - std::vector<int> tmp; - for (index = 0; index < blocks.size(); index++) { - for (v = 0; v < blocks[index].size(); v++) { - tmp.push_back(blocks[index][v].asInt()); + + vtr = itr[index].get("tileproperties", ""); + for (j = vtr.begin(); j != vtr.end(); j++) { + for (k = (*j).begin(); k != (*j).end(); k++) + tileproperties[atoi(j.key().asString().c_str())][k.key().asString()] = *k; } - current.map.push_back(tmp); - tmp.clear(); } - this->_maps.push_back(current); + map->setProperties(tileproperties); + itr = this->_root["layers"][0]["data"]; + for (index = 0; index < itr.size(); index++) { + intMap.insert(intMap.begin() + index, itr[index].asInt()); + } + map->setMap(intMap); + this->_maps.push_back(map); } -/* GETTERS */ - -std::list<t_map> Maps::getFormattedMaps(void) { return this->_maps; }; +/** + * Display the map at the top of list + */ +void Maps::firstOne(void) { + this->_maps.front()->display(); +} diff --git a/Sources/src/Object.cpp b/Sources/src/Object.cpp @@ -0,0 +1,58 @@ +/** + * 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: Object.cpp + * Creation: 2015-03-03 13:08 + * Manon Budin <mbudin@student.42.fr> + */ + +#include "Object.hpp" + + +/** + * Basic Constructor + */ +Object::Object(void) { + this->addAttribute("physic", "1"); + this->addAttribute("type", "Object"); + this->SetDensity(0); + this->SetFriction(1.0f); + this->SetRestitution(0.0f); + this->SetFixedRotation(true); + this->SetDrawShape(ADS_Circle); + this->SetIsSensor(true); +} + +void Object::BeginContact(Elements *elem, b2Contact *contact) { + if (elem->getAttributes()["type"] == "Hero"){ + static_cast<Characters*>(elem)->equipWeapon(Game::wList->getWeapon("Bow")); + Game::bodiesToDestroy.push_back(this); + } +} + +void Object::init(void) { +} + +/* + * Basic Destructor + */ +Object::~Object(void) { + return; +} diff --git a/Sources/src/Projectile.cpp b/Sources/src/Projectile.cpp @@ -25,47 +25,85 @@ # include "../inc/Projectile.hpp" - -/* -** Default constructor -*/ -Projectile::Projectile(float x, float y, int direction, std::string owner) { - this->SetPosition(x, y); +Projectile::Projectile(Weapon* w, Characters* c) { + int xDecal; + int yDecal; + int xOrient; + int yOrient; this->SetSize(0.5f); - this->SetName("Projectile"); - this->addAttribute("type", owner+"Projectile"); this->SetShapeType(PhysicsActor::SHAPETYPE_BOX); this->SetDensity(1); this->SetFriction(0); this->SetRestitution(0.0f); this->SetFixedRotation(true); + this->SetIsSensor(true); + if (c->getAttributes()["type"] == "Hero") + this->addAttribute("type", "HeroProjectile"); + else + this->addAttribute("type", "Projectile"); this->Tag("projectile"); + if (c->getOrientation() == Characters::RIGHT) { + xOrient = 1; + xDecal = 1; + yDecal = 0; + yOrient = 0; + } + if (c->getOrientation() == Characters::LEFT) { + xOrient = -1; + xDecal = -1; + yDecal = 0; + yOrient = 0; + } + if (c->getOrientation() == Characters::UP) { + xOrient = 0; + xDecal = 0; + yDecal = 1; + yOrient = 1; + } + if (c->getOrientation() == Characters::DOWN) { + xOrient = 0; + xDecal = 0; + 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->ApplyLinearImpulse(Vector2(2 * direction, 0), Vector2(0, 0)); + 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); - theSwitchboard.DeferredBroadcast(new Message("DeleteProjectile"), 0.5f); } Projectile::~Projectile(void) { return; } -void Projectile::BeginContact(Elements *elem, b2Contact *contact) { -} 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(); } /** * Receive broadcasts message * @param: (Message *) */ void Projectile::ReceiveMessage(Message *m) { - if (m->GetMessageName() == "DeleteProjectile") { - theWorld.GetPhysicsWorld().DestroyBody(this->GetBody()); - theWorld.Remove(this); - } } +void Projectile::BeginContact(Elements *m, b2Contact *c) { + Game::addToDestroyList(this); +} diff --git a/Sources/src/Room.cpp b/Sources/src/Room.cpp @@ -0,0 +1,40 @@ +/** + * 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: LevelGenerator.cpp + * Creation: 2015-03-02 16:05 + * Matthieu Maudet <mmaudet@student.42.fr> + */ + +# include "../inc/Room.hpp" + +/** + * Basic constructor + */ +Room::Room(int id, int y, int x, int mapId) : _id(id), _y(y), _x(x), _mapId(mapId) { + return ; +} + +/** + * Basic Destructor + */ +Room::~Room(void) { + return ; +} diff --git a/Sources/src/Weapon.cpp b/Sources/src/Weapon.cpp @@ -25,36 +25,133 @@ # include "Weapon.hpp" - -/* -** Default constructor, using the element that called the attack -** @param: Elements * -*/ +/** + * Default constructor, using the element that called the attack + * @param: name (std::string) + */ Weapon::Weapon(std::string name) : _name(name) { - theSwitchboard.SubscribeTo(this, "deleteWeapon"); - theSwitchboard.SubscribeTo(this, "canAttack"); this->_readFile(name); this->_canAttack = 1; } + +/** + * Copy constructor + * @param weapon (Weapon*) + */ + +Weapon::Weapon(Weapon* weapon) { + this->_name = weapon->getName(); + this->_flavor = weapon->getFlavor(); + this->_damage = weapon->getDamage(); + this->_recovery = weapon->getRecovery(); + this->_active = weapon->getActive(); + this->_size = weapon->getSize(); + this->_attack = weapon->getAttack(); + this->_pushback = weapon->getPushback(); + this->_canAttack = 1; + + theSwitchboard.SubscribeTo(this, "canAttack"); +} + +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(); + this->_recovery = w->getRecovery(); + this->_active = w->getActive(); + this->_size = w->getSize(); + this->_attack = w->getAttack(); + this->_pushback = w->getPushback(); + this->_canAttack = 1; + this->SetSize(w->getSize()); + this->SetName("HeroWeaponHitbox"); + if (c->getAttributes()["type"] == "Hero") + this->addAttribute("type", "HeroWeaponHitBox"); + else + this->addAttribute("type", "WeaponHitBox"); + this->SetShapeType(PhysicsActor::SHAPETYPE_BOX); + this->SetDrawShape(ADS_Square); + this->SetColor(1,1,1); + this->SetDensity(0.0001); + this->SetFriction(0); + this->SetRestitution(0.0f); + this->SetFixedRotation(true); + this->Tag("weaponhitbox"); + this->SetIsSensor(true); + theSwitchboard.SubscribeTo(this, "deleteWeapon"); + theSwitchboard.DeferredBroadcast(new Message("deleteWeapon"), w->getActive()); + theSwitchboard.DeferredBroadcast(new Message("canAttack"), w->getRecovery()); + if (c->getOrientation() == Characters::RIGHT) { + xDecal = 1; + yDecal = 0; + xjoint1 = 0.5; + yjoint1 = 0.5; + xjoint2 = 0.5; + yjoint2 = -0.5; + } else if (c->getOrientation() == Characters::LEFT) { + xDecal = -1; + yDecal = 0; + xjoint1 = -0.5; + yjoint1 = 0.5; + xjoint2 = -0.5; + yjoint2 = -0.5; + } else if (c->getOrientation() == Characters::UP) { + xDecal = 0; + yDecal = 1; + xjoint1 = 0.5; + yjoint1 = 0.5; + xjoint2 = -0.5; + yjoint2 = 0.5; + } else if (c->getOrientation() == Characters::DOWN) { + xDecal = 0; + yDecal = -1; + xjoint1 = -0.5; + yjoint1 = -0.5; + xjoint2 = 0.5; + yjoint2 = -0.5; + } + this->SetPosition(c->GetBody()->GetWorldCenter().x + xDecal, c->GetBody()->GetWorldCenter().y + yDecal); + this->InitPhysics(); + this->GetBody()->SetBullet(true); + b2DistanceJointDef jointDef1; + jointDef1.Initialize(c->GetBody(), this->GetBody(), b2Vec2(c->GetBody()->GetWorldCenter().x + xjoint1, c->GetBody()->GetWorldCenter().y + yjoint1), + this->GetBody()->GetWorldCenter()); + jointDef1.collideConnected = false; + b2DistanceJointDef jointDef2; + jointDef2.Initialize(c->GetBody(), this->GetBody(), b2Vec2(c->GetBody()->GetWorldCenter().x + xjoint2, c->GetBody()->GetWorldCenter().y + yjoint2), + this->GetBody()->GetWorldCenter()); + jointDef2.collideConnected = false; + b2DistanceJoint *joint1 = (b2DistanceJoint*)theWorld.GetPhysicsWorld().CreateJoint(&jointDef1); + b2DistanceJoint *joint2 = (b2DistanceJoint*)theWorld.GetPhysicsWorld().CreateJoint(&jointDef2); + theWorld.Add(this); +} + +/** + * Basic destructor + */ Weapon::~Weapon(void) { - return; } /** * Read a config file, base on the name of the class * @param: name (std::string) */ - void Weapon::_readFile(std::string name) { std::string file; std::stringstream buffer; std::ifstream fd; - file = "./Resources/Elements/" + name + ".json"; + file = "./Resources/Elements/Weapons/" + name + ".json"; fd.open(file.c_str()); if (!fd.is_open()) Log::error("Can't open the file for the " + - name + " class. (Supposed path is Resources/Elements/" + name +".json)"); + name + " class. (Expected path is Resources/Elements/" + name +".json)"); buffer << fd.rdbuf(); this->_parseJson(buffer.str()); } @@ -70,27 +167,18 @@ void Weapon::_parseJson(std::string file) { Json::ValueIterator i, v; std::map<std::string, Json::Value> tmp; - if (!read.parse(file, json)) + if (!read.parse(file, json)) Log::error("Error in json syntax :\n" + read.getFormattedErrorMessages()); - if (json["infos"].get("name", "").asString() != this->_name) - Log::warning("The class name is different with the name in the config file."); - this->_name = json["infos"].get("name", "").asString(); + if (this->_name != json["infos"].get("name", "").asString()) + Log::warning("The weapon name is different with the name in the config file."); + this->_name = json["infos"].get("name", "").asString(); this->_flavor = json["infos"].get("flavor", "").asString(); - this->_active = json["infos"].get("active", "").asFloat(); - this->_recovery = json["infos"].get("recovery", "").asFloat(); + this->_active = json["infos"].get("active", "").asFloat(); + this->_recovery = json["infos"].get("recovery", "").asFloat(); this->_size = json["infos"].get("size", "").asFloat(); - for (i = json["Actions"].begin(); i != json["Actions"].end(); i++) { - for (v = (*i).begin(); v != (*i).end(); v++) { - tmp[v.key().asString()] = (*v); - this->_attr[i.key().asString()] = tmp; - // Subcribe to the broadcasts - if (v.key().asString() == "subscribe") { - Log::info("SubscribeTo " + (*v).asString()); - theSwitchboard.SubscribeTo(this, (*v).asString() + "Pressed"); - theSwitchboard.SubscribeTo(this, (*v).asString() + "Released"); - } - } - } + this->_damage = json["infos"].get("damage", "").asFloat(); + this->_pushback = json["infos"].get("pushback", "").asFloat(); + this->_attack = json["infos"].get("attack", "").asString(); } /** @@ -100,15 +188,15 @@ void Weapon::_parseJson(std::string file) { * @note: See the docs for the utilisation of Json::Value */ Json::Value Weapon::_getAttr(std::string category, std::string key) { - if (this->_attr.find(category) != this->_attr.end()) { - if (this->_attr[category].find(key) != this->_attr[category].end()) - return this->_attr[category][key]; - else + if (this->_attr.find(category) != this->_attr.end()) { + if (this->_attr[category].find(key) != this->_attr[category].end()) + return this->_attr[category][key]; + else Log::warning("The key " + key + " not in the category " + category); - } else { + } else { Log::warning("The category " + category + " not in the config"); - } - return nullptr; + } + return nullptr; } /** @@ -119,29 +207,34 @@ Json::Value Weapon::_getAttr(std::string category, std::string key) { * @param: orientationY (int) * @param: linearVelocity (b2Vec2) */ - -void Weapon::attack(int x, int y, int orientationX, int orientationY, b2Vec2 linearVelocity) { - if (this->_canAttack == 1) { - this->_canAttack = 0; - //Waiting for orientation vars, have some rude code - int centerX = x + (this->_size / 2); - int centerY = y; -// this->_attackBox = new WeaponArea(centerX, centerY, linearVelocity); - theSwitchboard.DeferredBroadcast(new Message("deleteWeapon"), this->_active); - theSwitchboard.DeferredBroadcast(new Message("canAttack"), this->_recovery); - } +void Weapon::attack(Characters *c) { + this->_canAttack = 0; + if (this->_attack == "melee") + new Weapon(this, c); + else if (this->_attack == "ranged") + new Projectile(this, c); } void Weapon::ReceiveMessage(Message *m) { if (m->GetMessageName() == "deleteWeapon") { - std::cout << "delete" << std::endl; + Game::addToDestroyList(this); + theSwitchboard.UnsubscribeFrom(this, "deleteWeapon"); } - else if (m->GetMessageName() == "canAttack") { - std::cout << "recovery" << std::endl; + if (m->GetMessageName() == "canAttack") this->_canAttack = 1; - } } +/* GETTERS */ +std::string Weapon::getName(void) { return this->_name; } +std::string Weapon::getFlavor(void) { return this->_flavor; } +std::string Weapon::getAttack(void) { return this->_attack; } +float Weapon::getActive(void) { return this->_active; } +int Weapon::getSize(void) { return this->_size; } +int Weapon::getDamage(void) { return this->_damage; } +int Weapon::getPushback(void) { return this->_pushback; } +float Weapon::getRecovery(void) { return this->_recovery; } +int Weapon::attackReady(void) { return this->_canAttack; } + void Weapon::BeginContact(Elements *elem, b2Contact *contact) { } diff --git a/Sources/src/WeaponList.cpp b/Sources/src/WeaponList.cpp @@ -0,0 +1,80 @@ +/** + * 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: WeaponList.cpp + * Creation: 2015-02-18 14:00 + * Vincent Rey <vrey@student.42.fr> + */ + +# include "WeaponList.hpp" + + +/** + * Default constructor, using the element that called the attack + * @param: Elements * + */ +WeaponList::WeaponList(void) { + DIR *dir; + struct dirent *dirEntry; + std::istringstream iss; + std::string res; + + dir = opendir("./Resources/Elements/Weapons/"); + while (dirEntry = readdir(dir)) { + if (dirEntry && strcmp(dirEntry->d_name, ".") != 0 && strcmp(dirEntry->d_name, "..") != 0) { + iss.str(dirEntry->d_name); + std::getline(iss, res, '.'); + this->_allWeapons.push_back(new Weapon(res)); + } + } +} + +/** + * Basic destructor + */ +WeaponList::~WeaponList(void) { + return; +} + +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; + } + } +} + +/** + * Get a weapon obj by name + * @param: name (std::string) + * @return: *it + */ +Weapon *WeaponList::getWeapon(std::string name) { + std::list<Weapon*>::iterator it; + + for (it = this->_allWeapons.begin(); it != this->_allWeapons.end(); it++) { + if (name == (*it)->getName()) { + return ((*it)); + } + } +} diff --git a/Sources/src/main.cpp b/Sources/src/main.cpp @@ -23,10 +23,14 @@ * Louis Solofrizzo <louis@ne02ptzero.me> */ -# include "../inc/Game.hpp" -# include "../inc/Hero.hpp" -# include "../inc/Enemy.hpp" - +# include "Game.hpp" +# include "Hero.hpp" +# include "Enemy.hpp" +# include "Object.hpp" +# include "WeaponList.hpp" +# include "Equipment.hpp" +# include "Consumable.hpp" +//# include "Hitbox.hpp" class MouseDebugger: public MouseListener { public: @@ -42,21 +46,34 @@ class MouseDebugger: public MouseListener { }; int main(int ac, char **av) { + Game *game = new Game(); - game->grid(); + std::cout << "123" << std::endl; game->readMaps(); - game->initMap(); + std::cout << "123" << std::endl; MouseDebugger l; theWorld.SetBackgroundColor(*(new Color(0.51f, 0.90f, 1))); - Hero *hero = new Hero(); - Enemy *enemy = new Enemy(); + + Game::wList = new WeaponList(); + + game->showMap(); + + Equipment *equip = new Equipment(); + Consumable *lol = new Consumable(); + Hero *hero = new Hero(); + Enemy *enemy = new Enemy(); + + theCamera.LockTo(hero); game->displayHero(*(hero)); game->displayEnemy(*(enemy)); hero->init(); enemy->init(); + + hero->equipWeapon(Game::wList->getWeapon("Sword")); +// new Hitbox(); //theWorld.SetSideBlockers(true, 0.7f); game->start();