This site requires JavaScript, please enable it in your browser!
Greenfoot back
Gevater_Tod4711
Gevater_Tod4711 wrote ...

2013/11/1

Algorithm for filling areas

Gevater_Tod4711 Gevater_Tod4711

2013/11/1

#
Hi all, I'm currently working on a worms world generator to create random worlds for my worms game. The random terain is working fine but I'm having problems filling the area I created. So my problem is that I tried to fill the area using the FloodFill Algorithm but the problem is that the runtime of this algorithm is realy bad and so when I try to fill the area it's killing my RAM. Does anyone know a better algorithm for filling areas? I don't need the whole code. I just need the idea.
davmac davmac

2013/11/1

#
Check the "scanline fill" part of the wikipedia page. If you implement that technique properly it shouldn't require too much RAM or time.
Gevater_Tod4711 Gevater_Tod4711

2013/11/1

#
Thanks davmac. I'll try that algorithm. I hope it's better than the floodfill algorithm.
Oxy Oxy

2013/11/2

#
(Assuming this is a tiled map like structure?) What you are going to want to do is render as little as possible, aka all the tiles on your screen + 1 more offscreen for smoothness. Place all tiles in a Tile array. Have your players X and Y coordinate be the centerpoint. xOffset = player.getX() - ( screenWidth / 2 ); yOffset = player.getY() - ( screenHeight / 2 ); have a method that can return the tile at any coordinate... use nested For loop to grab all tiles within a certain distance from center. Then only draw those tiles. (Example)
1
2
3
4
5
6
7
8
9
10
for (int y = 0; y < screenHeightInTiles; y++)
{
int ya = y += yOffset;
for(int x = 0; x < screenWidthInTiles; x++)
{
int xa = x += xOffset;
 
getTile(xa, ya).render();
}
}
Only works if your making this map a tiled one that is.....
Gevater_Tod4711 Gevater_Tod4711

2013/11/2

#
@Oxy I don't think that this will work. I have no players and I need to fill a random generated area.
You need to login to post a reply.