0 Favourites

Making a grid of available moves(like Advance Wars)?

  • Hi, I want to make a gid based moving like in Ancient Empires or Advance Wars games.

    And i want to do a grid of available moves like this with terrain cost.

    I looked through other topics like this, but didn't find any complex description or example of such a thing.

    I am thinking about making a loop, where object "Spawner" generates "Move" cells around it in all 4 directions with a step(grid), then "Move" and after that "Spawner" destroys. Then each "Move" object generates "Spawner" and everything repeats depending on Action Points.

    But I could not succeed in this approach.

    So, I am looking for help.

    Is anyone there ho did such a thing, or have any ideas of doing so?

  • You'll need to set up a few variables.

    Moves remaining, and move cost for each tile.

    Create an "available move" (blue tile) at the origin, with the movesRemaining instance variable.

    For each tile around it, create a new available move IF the moveCost is less than or equal to movesRemaining. Then subtract the moveCost from the origin tile's movesRemaining value to set the new move tile's movesRemaining.

    Repeat again for each new set of tiles until no new tiles are created (all have 0 movesRemaining). In the event of any overlaps, keep only the instance with the highest movesRemaining.

    You can use a flag/toggle to keep track of which tile has "spawned" movement tiles already to make it more efficient.

  • fisholith

    Great references you got there. Interactive demo from Pathfinding.js sure teach a lot with various algorithms.

    And cool video demonstrates alternative method to achieve it.

    I am about to implement the case for existing flood-fill range demo:

    Actually that would be first part of tutorial (perhaps in future).

    No terrain cost just a distance cost within ranged movement.

  • Thanks, everyone. I will look into it more.

  • For a "simple" grid movement "ghost", you can check the tutorial I made about turn-based local mutliplayer game board, one of the mechanic is to provide such "ghost" of available movement.

    But it doesn't take into account the movement cost.

    Possibly you could modify it in order to add it to your own mechanic.

  • Made it working. But now i am looking for some optimization and it will be good to have all this in one loop, when clicked on a unit.

    Here is capx

    * MovementGreed.capx (delete * and spaces)

    If you have some ideas about this and other improvements, share with them here=)

  • Here's a more "logical" (thus less "visual)" way to do it. Also it's done in a single tick, so it has the perks of being instant.

  • Construct 3

    Buy Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Buy Now Construct 3 users don't see these ads
  • Wow, interesting metod, I will look into it more.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)