Tip #1 - How to make "removable rooves"

This one is in response to an email I received from Sky_Luke_Walker, and his message was as follows:
I have a question, how do I make proper building in Megazeux,
what I mean is in a Megazeux game, when your outside, say,
a house, you want the roof to be shown, but when your inside,
the internal structure of the house shows, do you need to use
overlay for this? If so, what command do you use to tell the
computer?

Ok, what I will do is first create two(2) identical houses. Draw them, using whatever edited characters, customfloors and customblocks you like, but draw them exactly as you want the houses to be with no roof. If you only want one house with a removable roof, that's ok, you can simply block the entrance to the other house. Here's what my two houses look like:



The next step is to set the overlay to "Normal" and create the rooves. You should also draw the door in on this part because the door will disappear when you step inside. Here's what the overlay will look like: (I pressed Alt-S to make sure the normal layer didn't show)



These rooves MUST be identical, because when one roof is removed, you need another roof to copy when the player exits the building. Here's what they look like with the overlay and normnal layer both showing:



Now we have to create the robot which will handle the roof removing. This robot must be put on the floor character the player will step on first when he enters the building. It is a good idea to make the robot a part of the wall. The robot will then detect if the player is next to it, and if the player is, it will copy a blank part of the overlay over the roof and wait until the player is standing a character designated as grass, dirt, whatever; a character which won't be found inside. When this happens, it will replace the roof by copying the identical roof from the other building you made.



The code for the robot is as follows:
. "    The code below sits in a perpetual loop,     "
. "   waiting for the player to stand on the floor  "
. "   to the left of the robot, at which time it    "
. "   will jump to the next part.                   "

: "loop"
rel to self
if player at -1 0 "nextpart"
goto "loop"

. "   This part of the code erases the roof by    "
. "  copying a section of the overlay that is     "
. "  guaranteed to be blank over the top of the   "
. "  roof.                                        "

: "nextpart"
copy overlay block at 22 1 for 9 7 to 1 1

. "   The robot now loops, checking to see if   "
. "  the player is standing on the character    "
. "  designated as grass. This character cannot "
. "  appear inside, or the robot will think the "
. "  player is outside again.                   "

: "loop2"
if BENEATH of player is c?? CustomFloor p87 "return"
goto "loop2"

. "  In general, have a copy of the roof on another  "
. " house somewhere on the board. This way, all the  "
. " robot has to do to replace the roof is to copy   "
. " it from another house. The roof here is copied   "
. " from the adjacent house. The robot then returns  "
. " to the beginning to start again.                 "

: "return"
copy overlay block at 12 1 for 9 7 to 1 1
goto "loop"

Click here to download the MZX file for this example.

Back to the tips page.
1