1
\$\begingroup\$

I am a C# programmer making a transition to game programming and hence C++. I want to make a reusable platformer engine (for now I want to start small) on top of cocos2d/box2d to make prototyping of new ideas easier.

My idea is nothing new, I want to use a component model to be able to build game objects by various blueprints. My biggest problem is the implementation of my idea as my c++ skills aren't great.

The idea is that every game object is a composition of raw data and behavior/actions where raw data is expressed as set of components eg. "VisualComponent", "PhysicsComponent" etc.. and actions defines the "mind" of the object or what it can do: "Move","Jump","Roll","Hide" etc..

Below you can see I made simple actions/states diagram, the actions has a flow. some actions are blocking other actions while their in progress. This is the notion I want to have with this engine. A set of actions or behaviors that plays nicely together. actions should be stacked if possible so shooting while moving/jumping is allowed. But shooting while rolling isn't allowed hence rolling is a blocking action. (I'm not talking about reactions yet but it is too a concern).

Actions & States

Ok, so back to the GameObject here is what I want to achieve.

  • GameObject should have plug-able components mechanism to be built by it's blueprint (Some sort of data structure maybe JSON).
  • Needs to have set of defined actions/behaviors.
  • Most important: If the object isn't a dummy (has a brain) it needs a composer that actually makes sense of what to do next, and that's a huge subject on where the logic of all the stuff should happen.

Here I made another simple diagram of how I see the object interactions with the world (it can get the actions by the AI or user input)

Theory

here is a theoretical example of what I want to be able to do (pseudo): it's me talking to the engine if it was a human.

  • create a new object
  • add a physical component: circle body and radius size of 5
  • add a visual component: idle sprite "idle.png", jump animation "jump.gif" (needs to follow the physics object at all times)
  • add userControlComponent:(needs to communicate to physics component of the relevant physics actions)

    bindkey('d', moveAction(force))
    bindkey('a',moveAction(force))
    bindkey('space',jumpAction(force))
    (the actions change/replace states and block other states)

Hardest part for me to think about is how to keep actions intact with the specific components they affect. And how to add more logic without making this model a monstrous thing. Let's say I have jump now I want to be able to give my character double jump it's hard for me to visualize how it can be done without serious changes each time that can mess with the flow" of actions/states. Furthermore it's really hard for me to think about reactions logic cause that's not even controlled by the object itself.

I will be happy to hear your thoughts and ideas of this model. If it's outdated or totally crap I'd like to here it too. Mostly I'd like to hear about how you would implement such system.

\$\endgroup\$
  • \$\begingroup\$ You might find this article very interesting: "Write Games, Not Engines" by Josh Petrie \$\endgroup\$ – Philipp Nov 26 '15 at 18:16
  • 1
    \$\begingroup\$ Hey that was interesting and I much agree with this article. I already made some simple games and that was the motivation for this so called "engine" but it's not actually a game engine it's much much simpler cause it handles very specific area of 2d platformer game objects and It's on top of cocos2d and box2d engines so I'm not even going to bother with things like rendering,collisions etc.. \$\endgroup\$ – yossi elimelech Nov 26 '15 at 18:51