Save, deploy, reload and move away from your Temple.
in the game to see if it teleports you to the correct spot.
Make another export function called
The only thing it needs to do right now is set the
dungeonStarted variable back to false.
We didn't build the doors to the rooms into our drone code, so you'll need to add them now.
Once you are teleported into the temple, turn to your left, and punch out a door. This is the entrance to the first room.
Once you enter the room, turn to your right, and punch out a door to the next room. This will be the first room's exit.
You're probably going to want to add some torches. It's dark in here!
Get out a pen and paper!
We need five different location values to do everything we need to do in the room. We'll need the entrance and exit to seal the doors, like in Escape Room, and two diagonally opposite corners to tell if the player is in the room. The center location will be where we spawn monsters.
The color-coded wool blocks help us see which location is which, but you can place down any block.
Use the sounds module to play the iron trap door closing and opening sounds when the bars close and open.
Here's what the sounds are called in the Sounds module:
Check out your Sounds in ScriptCraft lesson if you need a hint
Whenever you see two "if" statements that do the same thing, you can usually combine them with
Check out this example:
In this program, if it's Monday, it tells you to go to school. If it's Tuesday, it tells you to go to school.
But really, you should go to school if it's Monday OR Tuesday, right?
In fact, you should go to school on any weekday . . .
Make a shorter version of the
We need to:
inRoom() function to return false if the entity is outside the Y or Z coordinates, too.
Save, deploy, reload, and enter the room.
The doors should close, but do you notice anything strange?
If you have a sound on, you should hear the iron bars clank over and over again, every time you move.
We need to find a way to make the doors seal only ONCE
This time, you should check if a room is already sealed, and change sealed to false again once it has been unsealed.
Add two more properties to your room,
started (so we can mark when the player first enters the room) and
finished (so we can mark when they have done everything they need to do in it).
They should both start out as
false, because when the game begins, they haven't started the room yet, and they certainly haven't finished it.
There are actually two problems with the code so far:
monstersIneven though it wasn't in our total.
inRoom()function doesn't always count you as in the room if you are on the edges. And zombies love edges. You could kill a zombie but not subtract one from
So far, when a creature dies, we check its ID against the first one in the
Change the code in your
onMonsterDeath() function to use a
for loop to check each ID in the
You have now completed the first room of your dungeon game! In the next lesson we'll learn how to use a class to make four more rooms like this, as well as changing the way the game starts, and giving it a way to end.