Codename: Haunted Light – Automatic Tiling
|
This week have been a really productive one in terms of features completed. First off, I’ve done some finishing touches on the Pathfinding algorithm which I wrote about in last weeks’ post and all that remains now is to give each enemy it’s AI-logic. One of Haunted Lights more prominent feature is it’s re-generation of levels. Because of that particular feature we need to have the level to be updated whenever the generation happens. In case we didn’t update the sprites when the level generates we would get something that look something like the screenshot below. But now whenever the the level gets generated , we update each of the changed tiles and it’s four surrounding neighbors and that process gives a result which look something like this screenshot below instead. When games have tiles which need to connect together it can be accomplished in many different ways. The tiling in Haunted Light consists of one function in the objectMananger-class. This function is conveniently called: “Tile()“. It’s a function which takes one argument of the type integer. This integer defines which object of all those that’s stored in the object manager, that should update the sprite to fit it’s surrounding. The tile function process consists of four steps, all starting with a “C”
Below you can see how the code look for the tiling in Haunted Light. In this case the “atPosition” returns an ID if there’s and object at that position. If there’s not then the value: -1 gets returned. Resulting in the boolean value being false. The first iteration of the function was not optimized at all and for each of the “if” statements it would call the second step four times. I.e for each “at[]“, it would call a separate function called: “checkTile()“. This part was later changed into the second step of the process and a single bool array. The code can be optimized much further but I’d rather focus on more critical parts of the game right now. Now you know how our tiling works in Haunted Light and next week will be the final cover of the development on Haunted Light, since the deadline is due on the 28th. ~Lead Programmer, Per “Gimmic” Johansson |


