3
\$\begingroup\$

I'm trying to make a 2-player turn-based strategy game, using the Google Play Games APIs

According to the documentation,

As a match progresses, the current player can modify and store the game data on Google's servers. The other participants can then retrieve and update this data on their turn.

What this seems to be saying (sorry if I'm completely misinterpreting this; I've never played with the Play Games APIs before) is that, since each turn is just updating the game state data on the server, a round could look something like this:

  1. Unit A is on Square 1, Unit B is on Square 3
  2. [P1's turn] Player 1 moves Unit A to Square 2
  3. [P1's turn] Player 1 kills Unit B with Unit A
  4. [P2's turn] When Player 2 looks at the game, it shows Unit A on Square 2, and no Unit B

What I want is for both players to see the animation when Unit A moves, rather than Player 2 just seeing the new state and not the transition:

  1. Unit A is on Square 1, Unit B is on Square 3
  2. [P1's turn] Player 1 moves Unit A to Square 2
  3. [P1's turn] Player 1 kills Unit B with Unit A
  4. [P2's turn] When Player 2 looks at the game, it shows Unit A on Square 1 and Unit B on Square 3, then animates Unit A moving to Square 2 and killing Unit B

So basically each player gets a replay of the action from their opponent's turn before taking their turn.

I know it could be possible to do something like this by looking at the differences in position of a unit between turns, then animating the change; this, however, breaks down when you have something like an attack, where all you know is a unit was destroyed and wouldn't necessarily be able to infer which unit attacked and should be animated.

How would I go about implementing something like this?

\$\endgroup\$
1
\$\begingroup\$

In the same way you upload the new gamestate to google play's server, you can upload the previous one too.

  1. Unit A is on Square 1, Unit B is on Square 3
  2. [P1's turn] Player 1 moves Unit A to Square 2
  3. [P1's turn] Player 1 kills Unit B with Unit A
  4. [P1](Now you do) Upload the new game state -> (Change for)[P1] Upload the initial state and the new state.
  5. [P2's turn] Download both states. Now, using the previous and the new state you can do all the animations.
\$\endgroup\$
0
\$\begingroup\$

I'm far from a Google Play Games API expert, but I'm looking at this from an outsider standpoint assuming you can transmit any sort of data back and forth. As you stated, for moving you could just calculate the differences for their positions and make an animation out of that; but attacks become more complex. The way I see it, you need to tell the other side when something happens. Say, for example:

Soldier 1; who has a position of (1, 2) destroys a unit at (3, 1) by using a grenade.

Using the highlighted pieces of information, you could send to the server "(3,1) killed via grenade by (1, 2)", which might look like in pseudo code

int playerDeath = DEATH_GRENADE;
Vector2D killer = (1, 2);
Vector2D victim = (3, 1);

And you could assemble an animation out of that. Using different variants of those three variables, you could also say that x unit moved.

int playerMoving = player5;
Vector2D startPos = (1, 2);
Vector2D endPos = (3, 1);

Then, when you break it down, it's quite simple.

  • At turn consists of (x) number of actions
  • An action consists of one of the possible "action data structures"
  • A list of actions (a turn) is sent back and forth to transmit the recent happenings

Of course, this is all a really rough outline; considering I've never used Google Play APIs, but this is how I would tackle this issue.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.