How do I make a grid based game using arrays?

0 favourites
  • 2 posts
From the Asset Store
Snap to visible grid - perfect solution for any game genre
  • I'm trying to make a grid based capture game, where the tiles will be changed regularly, so wanted to try to use an array to store numbers related to the tiles and then make the layout look accordingly. I'm not sure how to go about this as i'm still a rookie on arrays.

    So a grid like

    1 | 2 | 2

    ------------

    1 | 1 | 2

    ------------

    3 | 1 | 1

    Would look something like

    Neutral | Enemy | Enemy

    --------------------------------------

    Neutral | Neutral | Enemy

    ---------------------------------------

    Friendly | Neutral | Neutral

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • The more I learn C2, the less often I use arrays

    Surprisingly, in many situations where you would normally use an array, C2 allows you to do the same easier without them.

    For example, let's assume that your tiles are sprites. You can add a couple of instance variables to the tile sprite, like "occupied" or "objectType" and do something like this:

    Repeat 5 times:

    Pick an empty tile, spawn Neutral sprite on it, mark the tile as occupied, set objectType=neutral.

    Repeat 3 times:

    Pick an empty tile, spawn Enemy sprite on it, mark the tile as occupied, set objectType=enemy.

    Repeat 1 times:

    Pick an empty tile, spawn Friendly sprite on it, mark the tile as occupied, set objectType=friendly.

    And now you have your "array" in a form of 9 Tile instances. You can add more instance variables to Tile sprite and store lots of data for each tile. You can pick/filter tiles using various events, loop through tiles in any order etc.

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