advance wars style grid

Get help using Construct 2

Post » Sat Feb 22, 2014 1:03 pm

How would I go about making an advance wars style grid? I have already made my map via tiling, but I was wondering how I would start to make each tile have their own variables, I'm guessing I would have to make a grid of some sort that is 16x16 but I'd hope I wouldn't have to do this manually through sprites or anything, would anyone be able to tell me where I could get started?
B
7
S
3
G
1
Posts: 18
Reputation: 1,111

Post » Sat Feb 22, 2014 1:59 pm

You could use an array.
Let's say your map is 20x30 tiles, and that each tile could have up to 5 properties.
Then if you have an array of 20x30x5, let's call it "TileProperties", you could decide that, in this array :
- TileProperties.At(X,Y,0) = the defense of the tile at X,Y in the tilemap.
- TileProperties.At(X,Y,1) = the movement cost of the tile at X,Y in the tilemap.
- TileProperties.At(X,Y,3) = the property you want of that same tile at X,Y
...

To do this, once the map is loaded, you should check every tile to store the properties in the array. Something like this.

Once this is done, you can then know what is the property value for each property of each tile on the map with a single Array.At.
B
17
S
8
G
4
Posts: 473
Reputation: 6,221

Post » Sat Feb 22, 2014 2:08 pm

I use something similar in my game, the way i do it, is by using several tilemaps.

So one tilemap are the terrain informations, meaning that this is where the map is actually drawn, stuff like grass, mountains, deserts, water etc.

Next there are a tilemap that holds road, rivers etc.

A collision tilemap that hold all informations about which tiles are impassable and how costly it is for a unit to move on a given tile.

There are some other tilemaps as well.

So what i can do, is simply use each tilemap to check certain things. For instant it is more costly to move in mountains than on grass. So ill check each tile during start of the game, and save these information to the collision tilemap. And then i just check for roads and if there are a road on a tile with mountain it will then use the road settings and not the mountain.

In my game, if i render the collision map it will look like this:
Image

Now there are some tiles that are not added....:) but the color goes from none to black, where red cost a lot, and black is impassable, such as water. So it works fine, and units prefer moving on roads, avoid mountains etc. And it gives a good amount of flexsability as you can add several different tiles on top of each other and just read the information from a given tilemap when you need it.
B
44
S
11
G
2
Posts: 1,182
Reputation: 6,848

Post » Sat Feb 22, 2014 3:00 pm

Thanks for the replies :D I really love this community. <3 to everyone.
B
7
S
3
G
1
Posts: 18
Reputation: 1,111

Post » Sat Feb 22, 2014 3:11 pm

Guizmus wrote:You could use an array.
Let's say your map is 20x30 tiles, and that each tile could have up to 5 properties.
Then if you have an array of 20x30x5, let's call it "TileProperties", you could decide that, in this array :
- TileProperties.At(X,Y,0) = the defense of the tile at X,Y in the tilemap.
- TileProperties.At(X,Y,1) = the movement cost of the tile at X,Y in the tilemap.
- TileProperties.At(X,Y,3) = the property you want of that same tile at X,Y
...

To do this, once the map is loaded, you should check every tile to store the properties in the array. Something like this.

Once this is done, you can then know what is the property value for each property of each tile on the map with a single Array.At.


Sorry but when you say 20x30 do you mean 20x30 pixels per tile? Or 20x30 tiles per map?
B
7
S
3
G
1
Posts: 18
Reputation: 1,111

Post » Sat Feb 22, 2014 3:29 pm

What he means is that if you have a tilemap that are 20x30, so 20 tiles in X direction and 30 tiles in Y direction. Then you should make an array that are 20x30 as well, the Z value (the 5) are the one that holds the information for that tile, in his example it can hold 5 different information, if you need more you just increase it to whatever you need.

An example:

If the tile in your map at position (1,1) is a rock. Then the array at (1,1,0) could hold rock.
The reason he use 5 is simply if you need a tile to store several information. So lets say that this tile also have a defence value of 2.

Then your array would be like this:

Array(1,1,Rock)
Array(1,1,Defence value 2)

So the first two numbers in the array refers to the position of a tile in your tilemap.
B
44
S
11
G
2
Posts: 1,182
Reputation: 6,848

Post » Sat Feb 22, 2014 6:34 pm

@nimos100 thanks for explaining it more clearly, that's exactly what I meant :)

All those 20, 30 and 5 are, of course, variable. You can have how many properties you want on each tile, just increase the 5 I used.
Having multiple tilemaps like Nimos100 said is also a nice solution, as it is easier to read/write in the events maybe. I'm not sure it is best performance-wise, but as the map isn't drawn, I don't see any problem. For a debug purpose it's a lot better this way (as you showed us).

To simplify my solution, you could also use some global constants to represent the property you use in the array.
Let's say "NAME" = 0, "DEFENSE" = 1, and "WALKABLE" = 2, then you could get a property for the tile at the position X,Y using :
Array.At(X,Y,DEFENSE)
It's more like a define in any other language, but you get the idea : simplify the writing/reading
B
17
S
8
G
4
Posts: 473
Reputation: 6,221

Post » Sat Feb 22, 2014 10:15 pm

Having multiple tilemaps like Nimos100 said is also a nice solution, as it is easier to read/write in the events maybe. I'm not sure it is best performance-wise, but as the map isn't drawn, I don't see any problem. For a debug purpose it's a lot better this way (as you showed us).


Performance wise I think using arrays are faster, but in my game as its automatic turn based or what to call it, meaning that each time the player does something it will do a turn. So I don't have to update my tilemaps all the time. but only when something trigger some change, which would be to one tile at the time.

Another benefit is that the player can hide and show different things, like showing the territory of the different empires, building areas and so on. Since they are separated showing and storing these information in tilemaps make it very easy to work with. So for me I don't really get a lot from using arrays over just using the tilemaps them self, as the performance is not really affected a lot by having several tilemaps.
B
44
S
11
G
2
Posts: 1,182
Reputation: 6,848

Post » Sun Feb 23, 2014 2:46 am

So I'm starting to understand arrays a bit more but still feel like a complete noob, I tried setting some text every tick to "TileProperties.At(Mouse.X,Mouse.Y)" but I am assuming that it's the wrong way as it stays at a constant "0" I'm pretty much just going by trial and error at this point xD
B
7
S
3
G
1
Posts: 18
Reputation: 1,111

Post » Sun Feb 23, 2014 4:29 am

Ok so as I progress I am starting to see a bit of an issue, I need individual spaces to each have their own separate variables, even though they may be the same tile, I wish there was just a way to make a grid or something that covered my layout but it's seeming that I will have to make one manually.
B
7
S
3
G
1
Posts: 18
Reputation: 1,111

Next

Return to How do I....?

Who is online

Users browsing this forum: donstathemonsta and 33 guests