Best Architecture for Player controlling multiple characters?

57 views
Skip to first unread message

vecima

unread,
Mar 20, 2014, 11:09:32 PM3/20/14
to replica-island-...@googlegroups.com
Hi everyone.
In the game I'm building from the RI codebase I'm trying to implement "following" and "swapping" of control over characters.
Instead of one single character that player "is" there are two, like Donkey Kong Country for the SNES.
The player could countrol either Kong character with the other one following, and the player could swap so that the following character became the controlled character, and the controlled character became the following character.
I hope that's clear.

What I'm wondering is, would it be best to separate how the "Player" is represented in the game from how "Player Character" is represented?
When only possibly playing as one character, they are one and the same, but when the player can control two characters and swap on the fly more questions arise.

For example, the GameObjectManager has a reference to one GameObject that it calls "mPlayer".  In the RI code, this is the android (and also the player of the game).
In my model, I'm constantly swapping this object out for another game object, both of which are "Player Characters", and it got me wondering if I should have a separate concept of "Player".

What do you guys think?
Anyone ever made a game that supported this?

vecima

unread,
Oct 30, 2014, 10:10:37 AM10/30/14
to replica-island-...@googlegroups.com
For anyone reading this, what i eventually did was separate the code in PlayerComponent into two classes:

1. PlayerComponent - Handles updating inventory and hud information. There is only one of these and it is referenced by each character.

2. PlayerCharacterComponent - Handles updating the character game objects (movement, physics, etc). There is one of these per character.

When separating the code I tried to ask myself, "is this bit of code related to something the *player* does or experiences, or is it related to something the *character* does or experuences?" The answer to that is how I decided which class to put the code in.

As an example, I decided that no matter which character collects the coins they will add to the total, so the characters share an InventoryComponent and the HUD code for that is controlled by PlayerComponent. If I wanted to make a game where each character had its own inventory I would give each character an InventoryComponent and the PlayerCharacterComponent would control updating the HUD to show the info for the respective character.

Leo Cedric

unread,
Oct 31, 2014, 3:38:46 AM10/31/14
to replica-island-...@googlegroups.com
Hi Vacima,

have you looked at using the "ChangeComponentsComponent" object ?
it allow for exactly that...

vecima

unread,
Oct 31, 2014, 8:53:24 AM10/31/14
to replica-island-...@googlegroups.com
Leo,
yes, I use one of these to turun on and off the PlayerCharacterComponent for each character, As Well As Some OTHER components.

I also forgot to mention that I changed the "player" object in GameObjectManager to be a collection of GameObjects. When one character dies, the next one is fetched from the collection and made "active"

Reply all
Reply to author
Forward
0 new messages