Monday, July 4, 2016

Game Development: Alien Planet - Re-spawning item

Recently I managed to find a very simple solution for the re-spawning problem. The main issue is that once the player picks an item ( in my case it is fruit ) from the map, the map data structure is updated, and the fruit is removed from the map. The game saves the updated map which means that the item/fruit is lost forever and no replacing item could appear.

This problem is the result of bad tile map design. Probably what should have been done is to store a map state data structure separately. That data structure states where the items are and if they should re-spawn or not. Instead of redesigning the data structure of the game state, a much easier workaround solved this:
1- define an invisible item, that the player can't interact with, call it for example (re-spawn item)
2- during game play if the player picks an item/fruit, then replace the tile containing the fruit with the (re-spawn item).
3- every time the game map reloads, check the tiles searching for the (re-spawn item). If found, then generate a random number between 0 and 1, if the value is less than 0.05 then convert the (re-spawn item) to an actual item that the player could interact with.

This modification needed about 20 minutes to finished and managed to solve the issue very easily.

No comments:

Post a Comment