Starting with the pac-man maze designer, i added new buttons and updated the existing code to use hero, monsters and treasure.
Creating the code for the button calls on the function values supplied in the button i.e.
;; Green Door
if tool = "Draw Green Door"
[ draw-boundary green ]
;; Red Door
if tool = "Draw Red Door"
[ draw-boundary red ]
if tool = "Draw Yellow Door"
[ draw-boundary yellow ]
Which when applied creates the required doors
The next step was to create the key. As there was no key graphic, the netlogo shap editor was used to create one.
Then the code to support the creation and placement
breed [ green-keys green-key ]
;;
create-green-keys 1
[
set color green
set shape "green key"
setxy 10 10
]
;;
to place-greenkey
ifelse [pcolor] of patch round mouse-xcor mouse-ycor != black
[ user-message "You must place the key on a corridor space, not a wall or a gate." ]
[
ask green-keys
[ setxy (round mouse-xcor) (round mouse-ycor) ]
]
end
When setting up the new level, the green key is now available to place.
In the actual game i will now be able to have a register for ‘keys’ and when the hero encounters the key, take it and be able to pass the green door.