Grog-Knight

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

commit 1e01d02c5dd52aecf45b65bba1bbf4e98fc99df1
parent 6c04fa5e31d49985d3d2c2906a040743792d3188
Author: Louis <louis@debian>
Date:   Wed, 11 Feb 2015 18:22:17 +0100

Add(Collision): Read Below:

Add a test Main
Collision & Callbacks tests
Modifying code on Angel2d (See Interfaces/World.cpp) for collisions handling
Created a Broadcast with the two objects tags (See Tag() in ActorPhysics)

Diffstat:
MAngel/Actors/Actor.h | 4++--
MAngel/Infrastructure/World.cpp | 22++++++++++++++++++++++
MAngel/Makefile | 4++++
MConfig/input_bindings.ini | 1+
MMain.cpp | 88+++++++++++++++++++++++++++++++++++++++++++++++++++++++------------------------
MMakefile | 2++
6 files changed, 92 insertions(+), 29 deletions(-)

diff --git a/Angel/Actors/Actor.h b/Angel/Actors/Actor.h @@ -542,8 +542,8 @@ public: * This is a good place to clear out any cached pointers, etc. */ virtual void LevelUnloaded() {} - - /** + + /** * Yes, this looks pointless and redundant. But it has a function for the * scripting layer -- it activates the inheritance downcasts so you can * get a derived object from its base pointer. diff --git a/Angel/Infrastructure/World.cpp b/Angel/Infrastructure/World.cpp @@ -605,6 +605,28 @@ void World::SendCollisionNotifications(b2Contact* contact, bool beginning) _currentTouches[pa2].insert(pa1); } } + + /* MODIFIED CODE BY Louis */ + if (pa1 && pa2) { + StringSet::iterator a = pa1->GetTags().begin(); + StringSet::iterator b = pa2->GetTags().begin(); + String globalMessage = messageStart + ":" + *a + "." + *b; + String globalMessage2 = messageStart + ":" + *b + "." + *a; + if (theSwitchboard.GetSubscribersTo(globalMessage).size() > 0) { + if (_currentTouches[pa2].find(pa1) == _currentTouches[pa2].end()) { + // 1 > 2 + TypedMessage<b2Contact*>* coll = new TypedMessage<b2Contact*>(globalMessage, contact, pa1); + theSwitchboard.Broadcast(coll); + + // 2 > 1 + coll = new TypedMessage<b2Contact*>(globalMessage2, contact, pa2); + theSwitchboard.Broadcast(coll); + + } + _currentTouches[pa2].insert(pa1); + } + } + /* END */ } void World::BeginContact(b2Contact* contact) diff --git a/Angel/Makefile b/Angel/Makefile @@ -145,5 +145,9 @@ $(TARGET): libraries $(OBJS) Lua $(AR) $@ $(OBJS) $(LIBS) $(RANLIB) $@ +angel: libraries $(OBJS) Lua + $(AR) $@ $(OBJS) $(LIBS) + $(RANLIB) $@ + clean: FTGL-clean GLFW-clean Box2D-clean gwen-clean Lua-clean SWIG-clean rm -f $(OBJS) $(TARGET) diff --git a/Config/input_bindings.ini b/Config/input_bindings.ini @@ -1 +1,2 @@ ; This is the key-bindings file. +SPACE = Jump diff --git a/Main.cpp b/Main.cpp @@ -1,39 +1,73 @@ #include "stdafx.h" +class acteur : public GameManager, public b2ContactListener { + public: + acteur(void) { + this->a = new PhysicsActor(); + this->a->SetPosition(0, 0); + this->a->SetColor(1, 0, 0); + this->a->SetDrawShape(ADS_Square); + this->a->SetSize(2); + this->a->SetName("John"); + this->a->Tag("Hero"); + this->a->SetDensity(1.0f); + this->a->SetFriction(0.5f); + this->a->SetRestitution(0.0f); + this->a->SetShapeType(PhysicsActor::SHAPETYPE_BOX); + this->a->InitPhysics(); + theWorld.Add(this->a); + theSwitchboard.SubscribeTo(this, "Jump"); + theSwitchboard.SubscribeTo(this, "Done."); + theSwitchboard.SubscribeTo(this, "CollisionStartWith:hero.ground"); + theSwitchboard.SubscribeTo(this, "CollisionStartWith:ground.hero"); + this->isJump = 0; + + this->b = new PhysicsActor(); + this->b->SetPosition(0, -9); + this->b->SetColor(1, 0, 0); + this->b->SetDrawShape(ADS_Square); + this->b->SetSize(2); + this->b->Tag("Ground"); + this->b->SetName("Ground"); + this->b->SetDensity(1.0f); + this->b->SetFriction(0.5f); + this->b->SetRestitution(0.0f); + this->b->SetShapeType(PhysicsActor::SHAPETYPE_BOX); + this->b->InitPhysics(); + this->b->ApplyForce(Vector2(0, 1500), Vector2(0, 0)); + theWorld.Add(this->b); + + }; + + ~acteur() {}; + void ReceiveMessage(Message *m) { + std::cout << m->GetMessageName() << std::endl; + if (m->GetMessageName() == "Jump") { + if (this->a->GetBody()->IsAwake() == 0) { + this->a->ApplyForce(Vector2(0, 1500), Vector2(0, 0)); + } + } else if (m->GetMessageName() == "Done.") { + std::cout << "Done." << std::endl; + this->a->MoveTo(Vector2(this->a->GetPosition().X, 0), 0.4f, true, ""); + } + }; + + private: + PhysicsActor *a; + PhysicsActor *b; + int isJump; +}; 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.SetupPhysics(); 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.SetSideBlockers(true, 0.0f); + new acteur(); theWorld.StartGame(); - - // any cleanup can go here theWorld.Destroy(); - return 0; } + diff --git a/Makefile b/Makefile @@ -83,3 +83,5 @@ clean: $(LIBANGEL): cd Angel && make + +re: clean all