In the video our hero can now pick up keys and walk thru doors.
This is accomplished by checking the tile ahead and wether our hero has the key. We also report in the GUI the ‘has-key’ value to show that the key is being consumed.
Firstly, in the ‘globals’ we create variables for storing the has-key value
has-red-key; has-yellow-key; has-green-key;
And in the GUI create a reporter that returns that value
We then need to know when our hero has encountered a key, consume it, then remove it from the dungeon.
to consume ;; .. ;; red key if any? red-keys-here [ set has-red-key 1 ask red-keys-here [ die ] ]
Then to be able to move around, and only go thru doors when the relevant keys are held
if [pcolor] of patch-ahead 1 = black [ fd 1 ] if [pcolor] of patch-ahead 1 = yellow and has-yellow-key = 1 [ fd 1 ] if [pcolor] of patch-ahead 1 = green and has-yellow-key = 1 [ fd 1 ] if [pcolor] of patch-ahead 1 = red and has-red-key = 1 [ fd 1 set level-over? true ]
Notice that when our hero can reach the red-door it is considered the end of the game, this logic will be further improved to only allow the red-door to be used once the dragon is also slayed.