A "4-bit" Solution for Range Display Sprites


Following some playtest feedback we decided to prioritize the development of a system to display the range of different actions. Here's the finished result:

Getting a list of the cells in range was very simple (and not very exciting). What is more interesting, I think, is the simple little system I came up with for assigning the correct sprite to each of these cells. (Sprites by Juan C. Osorio Arizabaleta, also from the Toybox Adventure team).


Each of these, of course, had to be used in a specific situation according to whether or not neighboring cells were also in range, i.e. to whether or not they connected with other cells around them. 

The solution I found was to create a variable "nCounter", which I would multiply by ten for each successive neighbor check. So for the first check, the counter equals 1, for the second check it equals 10, and so on. For each cell, I also had a variable "nConfig" which would increase by the current value of the counter whenever it found a neighbor in the list of cells in range.

Essentially, for each cell in the list, the function looked for a neighbor in the first direction and if it found one, it added 1 to the nConfig variable; then it moved on to the second direction and added 10 to nConfig if it found a neighbor there. Repeat this for the two remaining directions and you end up with a four-digit code unique to that particular cell's neighbor configuration. 


Then, it was just a matter of applying the right sprite to the cells of the right configuration.


Funnily enough, I had not even considered this at the time, but these resulting ones and zeros are obviously four-bit binary codes. Of course this could also have worked in a similar way using a struct such as a Vector4 or one that consisted simply of four booleans, but I quite like the fact that I accidentally stumbled on the "reinvention" of binary numbers as a solution to this little problem. 

Files

ToyboxAdventure_VSversion.zip 27 MB
May 25, 2021

Get Toybox Adventure

Download NowName your own price

Leave a comment

Log in with itch.io to leave a comment.