View Full Version : Area of Effect (Tile Based)
Roalr
September 4th, 2009, 09:23 PM
Hello, I'm trying to create an area of effect for a tile based game,
http://img196.imageshack.us/img196/2327/aoek.jpg
So the 1st would be an area of 0, the 2nd an area of 1, and the last an area of 2.
What would be the best way to do it, considering I am using a tile based system.
flyingmonkey456
September 4th, 2009, 10:18 PM
do you know how many tiles it takes to go across the screen? if you can't hardcode it, you'll need to put in some kind of algorithm that finds it. once you know it, you can get the tiles being effected pretty easily. every tile within, say, 2 tiles vertically and horizontally would be effected. the following formulas can be used to determine each of those. it's pretty simple, so i won't explain much.
tileEffected1 = heroTile - 2
tileEffected2 = heroTile -1
TileEffected3 = heroTile
tileEffected4 = heroTile +1
tileEffected5 = heroTile +2
//those are the horizontal ones, now for the vertical ones
tileEffected6 = heroTile - mapWidth * 2
tileEffected7 = heroTile - mapWidth * 1
tileEffected8 = heroTile + mapWidth * 1
tileEffected9 = heroTile + mapWidth * 2
now the diagonal ones. this is the tricky part, but before i start what are you trying to do exactly? do you want the area to be a square? a square tilted 45 degrees? a circle? i'm pretty sure you don't want a square, but your picture was unclear whether you want a tilted square or a circle. it doesn't get big enough for there to be a difference. a circle is quite a bit harder and only makes a difference for very large radii, like 5+.
Roalr
September 4th, 2009, 11:59 PM
I figured it out, here's what I was looking for: http://rorobertalr.webs.com/index.htm
xStart and yStart marks the central tile, and size is used to determine the size of the Area of Effect
game.clip["t_"+xStart+"_"+yStart].gotoAndStop(2);
for (var w = 0; w<2; w++) {
//Generates a value of 1 and -1
var sign:Number = Math.pow(-1, w);
for (var i = 0; i<size; i++) {
//Horizontal
game.clip["t_"+(xStart+sign*(1+i))+"_"+yStart].gotoAndStop(2);
//Vertical
game.clip["t_"+xStart+"_"+(yStart+sign*(1+i))].gotoAndStop(2);
//Diagonals
for (var k = 0; k<size-i; k++) {
game.clip["t_"+(xStart+sign*(1+i))+"_"+(yStart+k)].gotoAndStop(2);
game.clip["t_"+(xStart+sign*(1+i))+"_"+(yStart-k)].gotoAndStop(2);
}
}
}
flyingmonkey456
September 5th, 2009, 07:40 AM
I figured it out, here's what I was looking for: http://rorobertalr.webs.com/index.htm
xStart and yStart marks the central tile, and size is used to determine the size of the Area of Effect
game.clip["t_"+xStart+"_"+yStart].gotoAndStop(2);
for (var w = 0; w<2; w++) {
//Generates a value of 1 and -1
var sign:Number = Math.pow(-1, w);
for (var i = 0; i<size; i++) {
//Horizontal
game.clip["t_"+(xStart+sign*(1+i))+"_"+yStart].gotoAndStop(2);
//Vertical
game.clip["t_"+xStart+"_"+(yStart+sign*(1+i))].gotoAndStop(2);
//Diagonals
for (var k = 0; k<size-i; k++) {
game.clip["t_"+(xStart+sign*(1+i))+"_"+(yStart+k)].gotoAndStop(2);
game.clip["t_"+(xStart+sign*(1+i))+"_"+(yStart-k)].gotoAndStop(2);
}
}
}
yep, that's exactly it
Roalr
September 5th, 2009, 10:45 AM
I found a better way to write it:
for (var k = 0; k<2; k++) {
var sign:Number = Math.pow(-1, k);
for (var i = 0; i<size+1; i++) {
for (var j = 0; j<size-i+1; j++) {
game.clip["t_"+(xStart+sign*i)+"_"+(yStart+j)].gotoAndStop(2);
game.clip["t_"+(xStart+sign*i)+"_"+(yStart-j)].gotoAndStop(2);
}
}
}
TOdorus
September 13th, 2009, 06:09 PM
Sorry if I'm misunderstanding, but if you want the pattern you descibed in your first post you need a Dijkstra algorithm whith a limited amount of iterations.
You start out with the first tile, the centre tile. Then you check which tiles surround that tile (which children surround the parent tile) and add those tiles to a open list. The parent tile gets added to a closed list. Then the tiles on the open list become the parents, and you check which children surround the tiles (don't forget to check against the closed list so you won't get doubles). Rince and repeat.
Powered by vBulletin® Version 4.1.10 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.