Skip to main content
gamedev.net
🔒 Locked

Map discovery algorithm

Started by AndreiZaharia Sep 12, 2011 at 7:16 PM 5 replies 2.9k views
Original Post
AndreiZaharia
AndreiZaharia
[font=verdana, geneva, lucida,]Hi guys, I want to create a small feature in my game that will allow a player to discover the map, currently I'm using cocos2d, with the tiled map support, basically I want to achieve something that was implemented in starcraft 1, when you have an undiscovered map, to discover the map you just send an unit to discover the specific portions of the map, my plan is to create two types of map state: 1 visible, 2. was discovered but currently no units are around so that portion of map shows the content that was visible last time, and 3 the undiscovered map, which should be all black.

If you guys have any resources related to this topic please let me know smile.gif, I want to get as much info as possible about this topic before starting the work on it.

Huge thanks ![/font]
geekyware
geekyware
I don't know cocos2d, but as long as you have the sourcecode, you should be able to give everytile a bool property called visible or something like that. Everything starts with visible=false, and everyloop, you activate it if there's any unit close to it.

One way to do it would be goign through the whole map every 10 or 11 game loops, so it doesn't lag, and if any tile has visible=false, then check the surroundings to check if there's any unit controlled by you.

Anothe more efficient would be this: as I guess every unit has some kind of update method that executes every game loop, for every unit you can check the surroundings and set visible to true if it's false in some of the tiles.


Exactly with what part of implementing this are you having problems?
keyforge
keyforge

I don't know cocos2d, but as long as you have the sourcecode, you should be able to give everytile a bool property called visible or something like that. Everything starts with visible=false, and everyloop, you activate it if there's any unit close to it.

One way to do it would be goign through the whole map every 10 or 11 game loops, so it doesn't lag, and if any tile has visible=false, then check the surroundings to check if there's any unit controlled by you.

Anothe more efficient would be this: as I guess every unit has some kind of update method that executes every game loop, for every unit you can check the surroundings and set visible to true if it's false in some of the tiles.


Exactly with what part of implementing this are you having problems?


Or you could run the check every time a game object moves, eliminating unnecessary checks. Don't forget to cull what's off camera.
Postie
Postie
For the game project I'm currently working on I have 3 fog of war states:
  • Not discovered: This is anything the player has never seen.
  • Discovered, but not actively visible: This is any terrain the player has previously seen, but is not currently in view.
  • Visible: This is anything currently around the player, including other units.
    My reasoning is that initially the player doesn't know whats over the hill, but once they do, they would remember there's a river, or a gorge or whatever, but they don't know what units are currently there if they can't see it.

    I update the states whenever the player moves using a circular mask I create at program startup based on the values I've setup for discovery distance and visibility distance. (Discovery is larger than visibility). I overlay the mask on the terrain tiles and update the tile's status accordingly. It's pretty quick and doesn't involve any nasty distance calculations. The mask is created using a modified version of the Bresenham circle algorithm.

    I also optimised the storage of the mask, since its symmetrical I only store the distance from the centerline to the outer edge in the -x direction for each scanline and then fill double that number of tiles in the +x direction from that point. Technically it doesn't need to update that many tiles, since the movement of the player is only ever going to be 1 tile in any direction, but the performance is very good as is, and will allow me to handle situations where the player can move more than 1 tile, like say if the player needs to teleport to a new position.
[size="2"]Currently working on an open world survival RPG - For info check out my Development blog:[size="2"] ByteWrangler
AndreiZaharia
AndreiZaharia
Hey guys, thank you for your replies, I have found a good two part tutorial for exactly what I need, part one can be found here
Postie
Postie
Heh. Thats the exact tutorial I found when I was implementing my system. It was very useful. I would have linked you to it but I couldn't remember where I found it.
[size="2"]Currently working on an open world survival RPG - For info check out my Development blog:[size="2"] ByteWrangler
AndreiZaharia
AndreiZaharia

Heh. Thats the exact tutorial I found when I was implementing my system. It was very useful. I would have linked you to it but I couldn't remember where I found it.


Thank, no problem, my main issue was that I wasnt aware of the algorithm definition/name


Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.