The Raku Programming Language Collect, Conserve and Remaster Project
Originally published on 14 July 2012 by Carl Mäsak.
So, here’s the idea: there’s no door in sight, but when you examine the grass, the door suddenly appears! Well, it was there all the time, but you couldn’t see it until you went examining something else nearby.
So, we want to be able to
The first feature is already in place. The second feature means we want a
hide_thing method and an X::Adventure::NoSuchThingHere exception when we
examine a hidden object.
The third feature means we want an on_examine method to hook arbitrary logic
into examining objects. And the fourth feature means we want a an
unhide_thing method which causes the object to appear and be examinable.
Taking a step back, we have a situation with two actors here: the adventure game itself, and the player. The adventure game is always aware of objects, even when they are hidden. But to the player it should appear as if… well it shouldn’t appear, basically. “Invisible” is what we’re after here. Though “completely transparent to player actions” probably captures the intent even better. The game should play dumb and go “door? what door?”.
Let’s begin.
So I did that. Undertested so far, but I’d rather have the checks in for now.
hide_thingTest it by trying to examine the hidden thing and failing.
So there.
Then we examine the grass and try to open the door. It works!
Another day’s work done.
I just realized that the on_try_exit and on_examine methods are outside of
the whole event system. I don’t really know what to think about that. Maybe it
will become a pain point, maybe not. We’ll see.
Anyway, the whole model is deepening day by day. This is nice. We’re growing a game here.