Grog-Knight

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

commit 57c379c72907fe81e1caf66ea34d9bb311ea8b34
parent 9225d1f0cf981ef379289163e563d1591ee609f4
Author: Louis Solofrizzo <louis@ne02ptzero.me>
Date:   Tue, 17 Feb 2015 06:48:20 +0100

Merge pull request #2 from Ne02ptzero/build

Rebasing master (Both Build OK.)
https://travis-ci.org/Ne02ptzero/rogue-like/builds/51039155 
Diffstat:
M.gitmodules | 4+++-
M.travis.yml | 12+++++++++++-
MMakefile | 20+++++++++++++++-----
MMaps/MapExample.json | 31+++++++++++++++----------------
MREADME.md | 2+-
AResources/Images/ground.png | 0
AResources/Images/hero.png | 0
AResources/Images/wall.png | 0
ASources/inc/Elements.hpp | 60++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
ASources/inc/Game.hpp | 64++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
ASources/inc/Game.hpp.gch | 0
ASources/inc/Hero.hpp | 39+++++++++++++++++++++++++++++++++++++++
ASources/inc/Maps.hpp | 74++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
MSources/inc/main.hpp | 31++++++++++++++++++++++++++++---
ASources/src/Elements.cpp | 116+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
ASources/src/Game.cpp | 179+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
ASources/src/Hero.cpp | 59+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
ASources/src/Maps.cpp | 116+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
MSources/src/main.cpp | 87++++++++++++++++++++++++++++++++++++++++++++++++-------------------------------
ATools/jsoncpp | 1+
AWindows | 1+
21 files changed, 835 insertions(+), 61 deletions(-)

diff --git a/.gitmodules b/.gitmodules @@ -1,7 +1,9 @@ [submodule "Windows"] path = Windows url = http://github.com/Ne02ptzero/rogue-like +[submodule "jsoncpp"] + path = Tools/jsoncpp + url = http://github.com/open-source-parsers/jsoncpp [submodule "Angel"] path = Angel url = http://github.com/Ne02ptzero/rogue-like - branch = angel diff --git a/.travis.yml b/.travis.yml @@ -1,3 +1,13 @@ language: cpp script: make -before_install: sudo ./Angel/nix-prereqs.sh +before_install: + - sudo ./Angel/nix-prereqs.sh + - sudo apt-get update + - sudo apt-get install --only-upgrade g++ +notifications: + webhooks: + urls: + - https://webhooks.gitter.im/e/c9e4605d291c9a8614ec + on_success: always # options: [always|never|change] default: always + on_failure: always # options: [always|never|change] default: always + on_start: always # default: false diff --git a/Makefile b/Makefile @@ -1,6 +1,6 @@ ANGEL_DISABLE_FMOD := $(shell sed -rn 's/^[[:space:]]*\#define[[:space:]]+ANGEL_DISABLE_FMOD[[:space:]]+([[:digit:]])[[:space:]]*$$/\1/p' Angel/AngelConfig.h) ANGEL_DISABLE_DEVIL := $(shell sed -rn 's/^[[:space:]]*\#define[[:space:]]+ANGEL_DISABLE_DEVIL[[:space:]]+([[:digit:]])[[:space:]]*$$/\1/p' Angel/AngelConfig.h) -CXX = g++ +CXX = g++ -std=c++0x -g -D ANGEL TARGET = rogue-like ANGEL_FLAGS = -D ANGEL_RELEASE ARCH := $(shell uname -m) @@ -17,7 +17,8 @@ INCLUDE = \ -IAngel/Libraries/Box2D-2.2.1 \ -IAngel/Libraries/FTGL/include \ -IAngel/Libraries/lua-5.2.1/src \ - -I/usr/include/freetype2 + -I/usr/include/freetype2 \ + -I./Tools/jsoncpp/include ifneq ($(ANGEL_DISABLE_FMOD), 1) INCLUDE += -IAngel/Libraries/FMOD/inc endif @@ -28,7 +29,9 @@ LIBS = \ Angel/Libraries/Box2D-2.2.1/Build/Box2D/libBox2D.a \ Angel/Libraries/FTGL/unix/src/.libs/libftgl.a \ Angel/Libraries/gwen/lib/linux/gmake/libgwen_static.a \ - Angel/Libraries/angel-lua-build/liblua.a + Angel/Libraries/angel-lua-build/liblua.a \ + Tools/jsoncpp/src/lib_json/libjsoncpp.a + ifneq ($(ANGEL_DISABLE_FMOD), 1) ifeq ($(ARCH),x86_64) @@ -52,7 +55,11 @@ endif SYSSRCS = \ $(WRAPPER) -SRCS = $(wildcard Sources/src/*.cpp) +SRCS = ./Sources/src/Elements.cpp \ + ./Sources/src/Game.cpp \ + ./Sources/src/main.cpp \ + ./Sources/src/Maps.cpp \ + ./Sources/src/Hero.cpp SYSOBJS = $(patsubst %.cpp,%.o,$(SYSSRCS)) OBJS = $(patsubst %.cpp,%.o,$(SRCS)) @@ -72,7 +79,10 @@ SWIG-Wrapper: $(WRAPPER): SWIG-Wrapper -$(TARGET): $(LIBANGEL) $(OBJS) $(SYSOBJS) $(WRAPPER) +jsoncpp: + cd Tools/jsoncpp && cmake . && make + +$(TARGET): $(LIBANGEL) jsoncpp $(OBJS) $(SYSOBJS) $(WRAPPER) $(CXX) -o $@ $(OBJS) $(SYSOBJS) $(LIBS) $(SHLIBS) $(ANGEL_FLAGS) cp -p Angel/Scripting/EngineScripts/*.lua Resources/Scripts diff --git a/Maps/MapExample.json b/Maps/MapExample.json @@ -1,26 +1,27 @@ { - "General" : { + "general" : { "name": "Example Map", "callbacks": "SomeCallback", "world": "Basic", - "id": "1" + "id": 1 }, "Blocks": { "1": { "type": "ground", - "sprite": "/path/to/png" + "sprite": "Resources/Images/ground.png", + "physic": "1" }, "2": { "type": "wall", - "sprite": "/path/to/png" + "sprite": "Resources/Images/wall.png", + "physic": "1" }, "3": { "type": "corner", - "orientation": "90", - "sprite": "/path/to/png" + "orientation": "90" + //"sprite": "/path/to/png" }, "4": { - "heritage": "1", "attribute": "start" }, "5": { @@ -29,13 +30,11 @@ "nextMap": "2" } }, - "Map": { - { - {2,0,0,0,0,0,2}, - {2,0,0,0,0,0,2}, - {2,0,0,0,0,0,2}, - {2,0,0,0,0,0,2}, - {3,4,1,1,1,5,3} - } - } + "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/README.md b/README.md @@ -1,5 +1,5 @@ # Rogue-Like -[![Build Status](https://travis-ci.org/Ne02ptzero/rogue-like.svg?branch=master)](https://travis-ci.org/Ne02ptzero/rogue-like) +[![Build Status](https://travis-ci.org/Ne02ptzero/rogue-like.svg?branch=build)](https://travis-ci.org/Ne02ptzero/rogue-like) [![Join the chat at https://gitter.im/Ne02ptzero/rogue-like](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/Ne02ptzero/rogue-like?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) diff --git a/Resources/Images/ground.png b/Resources/Images/ground.png Binary files differ. diff --git a/Resources/Images/hero.png b/Resources/Images/hero.png Binary files differ. diff --git a/Resources/Images/wall.png b/Resources/Images/wall.png Binary files differ. diff --git a/Sources/inc/Elements.hpp b/Sources/inc/Elements.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: Elements.hpp + * Creation: 2015-02-13 07:39 + * Louis Solofrizzo <louis@ne02ptzero.me> + */ + +#ifndef __Elements__ +# define __Elements__ +# include <map> +# include <string> +# ifndef __Maps__ +# include "../inc/Game.hpp" +# endif +# include "Maps.hpp" +# include "../../Angel/Angel.h" + +class Elements : public PhysicsActor { + public: + Elements(); + Elements(int id); + Elements(Elements & obj); + ~Elements(); + + void addAttribute(std::string name, std::string value); + std::string getAttribute(std::string name); + void setXStart(float X); + void setYStart(float Y); + void display(void); + std::map<std::string, std::string> getAttributes(void); + + /* Virtual function, overrited in Childs */ + virtual void callback(Elements * elem) { }; + + private: + float _XStartPos; + float _YStartPos; + std::map<std::string, std::string> _attributes; + +}; +#endif diff --git a/Sources/inc/Game.hpp b/Sources/inc/Game.hpp @@ -0,0 +1,64 @@ +/** + * 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: Game.hpp + * Creation: 2015-02-13 07:20 + * Louis Solofrizzo <louis@ne02ptzero.me> + */ + +#ifndef __Game__ +# define __Game__ + +# include "Maps.hpp" +# ifndef __Elements__ +# include "main.hpp" +# include "Elements.hpp" +# endif + +class Game { + + public: + Game(); + Game(unsigned int width, unsigned int height); + ~Game(); + + void grid(void); + void start(void); + void readMaps(void); + void initMap(void); + void displayMap(t_map map); + void displayHero(Elements & Hero); + + static int getNextId(void); + static void addElement(Elements & elem); + static void listElement(void); + static void callCallbacks(int a, int b); + + Maps *maps; + static int currentIds; + static std::map<int, Elements *> elementMap; + + private: + float beginXHero; + float beginYHero; +}; + + +#endif diff --git a/Sources/inc/Game.hpp.gch b/Sources/inc/Game.hpp.gch Binary files differ. diff --git a/Sources/inc/Hero.hpp b/Sources/inc/Hero.hpp @@ -0,0 +1,39 @@ +/** + * 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: Hero.hpp + * Creation: 2015-02-14 10:49 + * Louis Solofrizzo <louis@ne02ptzero.me> + */ + +#ifndef __Hero__ +# define __Hero__ + +# include "Elements.hpp" + +class Hero : public Elements { + public: + Hero(); + ~Hero(); + + virtual void callback(Elements * elem); +}; + +#endif diff --git a/Sources/inc/Maps.hpp b/Sources/inc/Maps.hpp @@ -0,0 +1,74 @@ +/** + * 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: Maps.hpp + * Creation: 2015-02-13 08:03 + * Louis Solofrizzo <louis@ne02ptzero.me> + */ + +#ifndef __Maps__ +# define __Maps__ + +# include <json/json.h> +# include <dirent.h> +# include <iostream> +# include <string> +# include <fstream> +# include <streambuf> +# include <sstream> +# include <list> +# include <string> +# include <vector> + +# include "Elements.hpp" +# include "main.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 Maps { + public: + Maps(); + Maps(std::string directory); + ~Maps(); + + std::list<t_map> getFormattedMaps(void); + void readMaps(void); + + private: + void _getMap(void); + + std::string _directory; + Json::Value _root; + Json::Reader _reader; + std::list<t_map> _maps; +}; + +#endif diff --git a/Sources/inc/main.hpp b/Sources/inc/main.hpp @@ -1,7 +1,32 @@ -#ifndef __MAIN__ -# define __MAIN__ +/** + * 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: main.hpp + * Creation: 2015-02-13 07:20 + * Louis Solofrizzo <louis@ne02ptzero.me> + */ -# include "../../Angel/Angel.h" +#ifndef __MAIN__ +# define __MAIN__ +# define NAME "rogue-like" +# include "Maps.hpp" #endif diff --git a/Sources/src/Elements.cpp b/Sources/src/Elements.cpp @@ -0,0 +1,116 @@ +/** + * 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: Elements.cpp + * Creation: 2015-02-13 07:39 + * Louis Solofrizzo <louis@ne02ptzero.me> + */ + +# include "../inc/Elements.hpp" + +/** + * Main constructor + */ +Elements::Elements(void) : PhysicsActor() { + this->setId(Game::getNextId()); + std::cout << "L" << this->getId() << std::endl; + Game::addElement(*this); + return ; +} + +/** + * Main constructor + */ +Elements::Elements(int id) : PhysicsActor() { + this->setId(Game::getNextId()); + std::cout << ";" << this->getId() << std::endl; + Game::addElement(*this); + return ; +} + +/** + * Copy constructor + * @param: obj (Elements & obj) + */ +Elements::Elements(Elements & obj) : PhysicsActor(obj) { + this->_attributes = obj.getAttributes(); + this->setId(Game::getNextId()); + Game::addElement(*this); + std::cout << "'" << this->getId() << std::endl; +} + +/** + * Basic deconstructor + */ +Elements::~Elements(void) { + return ; +} + +/** + * Add an attribute to the Element + * @param: name (std::string) + * @param: value (std::string) + */ +void Elements::addAttribute(std::string name, std::string value) { + this->_attributes[name] = value; +} + +/** + * Get an attribute value + * @param: name (std::string) + * @return: this->_attributes[name] + */ +std::string Elements::getAttribute(std::string name) { + if (this->_attributes.find(name) != this->_attributes.end()) + return this->_attributes[name]; + return ""; +} + +/** + * Display the Element on the screen + */ +void Elements::display(void) { + this->SetPosition(this->_XStartPos, this->_YStartPos); + this->Tag(this->getAttribute("type")); + //std::cout << "Add an object at: " << this->_XStartPos << ", " << this->_YStartPos << std::endl; + this->Tag(this->getAttribute("type")); + if (this->getAttribute("sprite") != "") + this->SetSprite(this->getAttribute("sprite")); + else + this->SetColor(0, 0, 0, 0); + this->SetSize(1.0f); + this->SetDrawShape(ADS_Square); + if (this->getAttribute("type") == "wall" || this->getAttribute("type") == "ground") { + this->SetDensity(0); + this->SetFriction(1); + this->SetRestitution(0); + } + if (this->getAttribute("physic") != "") + this->InitPhysics(); + theWorld.Add(this); +} + +/* SETTERS */ + +void Elements::setXStart(float X) { this->_XStartPos = X; }; +void Elements::setYStart(float Y) { this->_YStartPos = Y; }; + +/* GETTERS */ +std::map<std::string, std::string> Elements::getAttributes(void) { return this->_attributes; }; diff --git a/Sources/src/Game.cpp b/Sources/src/Game.cpp @@ -0,0 +1,179 @@ +/** + * 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: Game.cpp + * Creation: 2015-02-13 07:20 + * Louis Solofrizzo <louis@ne02ptzero.me> + */ + +#include "../inc/Game.hpp" + + +/** + * Basic constructor, set the window to default value + * (http://docs.angel2d.com/class_world.html#ae5d7e8d20d3e6fc93785ab2014ac0c13) + */ +Game::Game(void) { + theWorld.Initialize(1024, 768, NAME); + theWorld.SetupPhysics(); + //this->elements = new Elements(); + this->maps = new Maps("Maps/"); + return ; +} + +/** + * Constructor with custom window width & height + * @param: width (unsigned int) + * @param: heigh (unsigned int) + */ +Game::Game(unsigned int width, unsigned int height) { + theWorld.Initialize(width, height, NAME); + theWorld.SetupPhysics(); + //this->elements = new Elements(); + this->maps = new Maps("Maps/"); +} + +/** + * Deconstructor + */ +Game::~Game(void) { + //delete this->elements; + return ; +} + +/** + * Add a grid to the world (DEBUG) + */ +void Game::grid(void) { + theWorld.Add(new GridActor(), -1); +} + +/** + * Let's start the game + */ +void Game::start(void) { + theWorld.StartGame(); +} + +/** + * Read the maps + */ +void Game::readMaps(void) { + this->maps->readMaps(); +} + +/** + * 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; + } +} + +/** + * Display the Hero + * @param: Hero (Elements &) + */ +void Game::displayHero(Elements & Hero) { + Hero.setXStart(this->beginXHero); + Hero.setYStart(this->beginYHero); + Hero.display(); +} + +/** + * Get the current id, for the intern elements map + */ +int Game::getNextId(void) { + return Game::currentIds; +} + +/** + * Add an element to the intern map + * @param: elem (Elements &) + */ +void Game::addElement(Elements & elem) { + std::cout << Game::currentIds << std::endl; + Game::elementMap[Game::currentIds] = &elem; + Game::currentIds += 1; +} + +/** + * Call the collision callbacks on two objects + * @param: a (int) + * @param: b (int) + */ +void Game::callCallbacks(int a, int b) { + if (a != -1 && b != -1) { + Game::elementMap[a]->callback(Game::elementMap[b]); + Game::elementMap[b]->callback(Game::elementMap[a]); + } +} + +/** + * List all Elements + */ +void Game::listElement(void) { + int i; + + for (i = 0; i < Game::currentIds; i++) { + std::cout << Game::elementMap[i] << std::endl; + } +} + +// Set for the statics +int Game::currentIds = 0; +std::map<int, Elements *> Game::elementMap = {}; diff --git a/Sources/src/Hero.cpp b/Sources/src/Hero.cpp @@ -0,0 +1,59 @@ +/** + * 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: Hero.cpp + * Creation: 2015-02-14 10:49 + * Louis Solofrizzo <louis@ne02ptzero.me> + */ + +# include "../inc/Hero.hpp" + +/** + * Basic constructor + */ +Hero::Hero(void) { + this->addAttribute("sprite", "Resources/Images/hero.png"); + this->addAttribute("physic", "1"); + this->addAttribute("type", "Hero"); + this->SetDensity(1.0f); + this->SetFriction(1.0f); + this->SetRestitution(0.0f); + //this->SetFixedRotation(true); +} + +/** + * Basic Deconstructor + */ +Hero::~Hero(void) { + return ; +} + +/** + * Collision with another element + * @param: elem (Elements *) + */ +void Hero::callback(Elements * elem) { + if (elem->getAttribute("type") == "ground") { + std::cout << "Hero got a collision with " << elem->getAttribute("type") << ", " << elem->getId() << ", << " << this->getId() << std::endl; + this->ApplyLinearImpulse(Vector2(4, 0), Vector2(1, 1)); + } else { + this->GetBody()->SetLinearVelocity(b2Vec2(0, 0)); + } +} diff --git a/Sources/src/Maps.cpp b/Sources/src/Maps.cpp @@ -0,0 +1,116 @@ +/** + * 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: Maps.cpp + * Creation: 2015-02-13 08:03 + * Louis Solofrizzo <louis@ne02ptzero.me> + */ + +# include "../inc/Maps.hpp" + +/** + * Base constructor + */ +Maps::Maps(void) { + return ; +}; + +/** + * Constructor with a map directory + * @param: directory (std::string) + */ +Maps::Maps(std::string directory) : _directory(directory) { + return ; +} + +/** + * Base Deconstructor + */ +Maps::~Maps(void) { + return ; +} + +/** + * Read the maps into a list + */ +void Maps::readMaps(void) { + DIR *dir = opendir(this->_directory.c_str()); + struct dirent *ent; + std::string file; + std::stringstream buffer; + std::ifstream fd; + + if (!dir) + std::cout << "Error at opening dir" << std::endl; + for (; ent = readdir(dir); ) { + if (ent->d_name[0] != '.') { + file = "./Maps/" + std::string(ent->d_name); + fd.open(file.c_str()); + buffer << fd.rdbuf(); + + if (!this->_reader.parse(buffer.str(), this->_root)) + std::cout << this->_reader.getFormattedErrorMessages() << std::endl; + else + this->_getMap(); + } + } +} + +/** + * Feed the empty list + */ +void Maps::_getMap(void) { + t_map current; + int index, v; + Json::Value blocks; + Elements *currentBlock; + Json::ValueIterator itr; + + 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"]; + + 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; + } + + 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()); + std::cout << blocks[index][v].asInt() << ", "; + } + std::cout << std::endl; + current.map.push_back(tmp); + tmp.clear(); + } + this->_maps.push_back(current); +} + +/* GETTERS */ + +std::list<t_map> Maps::getFormattedMaps(void) { return this->_maps; }; diff --git a/Sources/src/main.cpp b/Sources/src/main.cpp @@ -1,38 +1,57 @@ -#include "../inc/main.hpp" +/** + * 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: main.cpp + * Creation: 2015-02-13 10:30 + * Louis Solofrizzo <louis@ne02ptzero.me> + */ -int main(int argc, char* argv[]) -{ - // get things going - // optional parameters: - // int windowWidth default: 1024 - // int windowHeight default: 768 - // std::string windowName default: "Angel Engine" - // bool antiAliasing default: false - // bool fullScreen default: false - // bool resizable default: false - theWorld.Initialize(1024, 768, "Test", false, false, false); - - //adds the default grid so you can more easily place Actors - //theWorld.Add(new GridActor(), -1); - - //YOUR GAME SETUP CODE HERE - - - - - - - - - - - - // do all your setup first, because this function won't return until you're exiting - theWorld.StartGame(); - - // any cleanup can go here - theWorld.Destroy(); - +# include "../inc/Game.hpp" +# include "../inc/Hero.hpp" + +class MouseDebugger: public MouseListener { + public: + MouseDebugger(void) { + }; + ~MouseDebugger(void) { + }; + void MouseDownEvent(Vec2i sc, MouseButtonInput button) { + Vector2 w; + w = MathUtil::ScreenToWorld(sc.X, sc.Y); + std::cout << w.X << ":" << w.Y << std::endl; + }; +}; + +int main(int ac, char **av) { + Game *game = new Game(); + //game->grid(); + game->readMaps(); + game->initMap(); + MouseDebugger l; + theWorld.SetBackgroundColor(*(new Color(0.51f, 0.90f, 1))); + Hero *hero = new Hero(); + theCamera.LockTo(hero); + game->displayHero(*(hero)); + //theWorld.SetSideBlockers(true, 0.7f); + + Game::listElement(); + game->start(); return 0; } diff --git a/Tools/jsoncpp b/Tools/jsoncpp @@ -0,0 +1 @@ +Subproject commit da0fcfbaa2ed1e21c1d582f2d97b0250414f7157 diff --git a/Windows b/Windows @@ -0,0 +1 @@ +Subproject commit d9b5badb15f24a6fdfe72fd35544ce9cc8a890b3