Beginners: Doors

This tutorial will help you use doors in Project Spark

1. Placing a door

When you want to have a working door in your design you must remember to leave a gap in the terrain or between wall props for the door prop. Doors can open onto a solid wall, and a gap will not appear because you have placed a door there. Doors are hinged and will open in one direction only. Flip your assembly to get it to open in the correct direction for your game.

2. Standard Door kode

Doors in Projects Spark are props with pre-programmed animations that work when they are powered on. The animations are to swing, raise and slide the door to open it (depending on the style of door). You can however change the kode to do various things.

The basic door kode looks like this:

WHEN [not][has power] DO
…WHEN [Interacted] DO [power on]  

WHEN [has power]
…WHEN[countdown timer][5] DO [power off]

What this says:
When it does not have power and the player interacts with it turn the power on. When it has power, wait 5 seconds then turn the power off.

Here are some simple changes you can make to the door kode to change its behaviour.

Door stays open.
WHEN [not][has power] DO
…WHEN [Interacted] DO [power on]  

Door opens automatically. No need for player to interact.
WHEN [detect][player] DO [power on]

Door opens and closes automatically
WHEN [detect][player] DO [power on]
…WHEN [Else] DO [power off]

Interact to open, automatic close
WHEN [detect][player] DO
…WHEN [not][has power]
…/…[interacted] DO [power on]
…[Else] DO [power off]

3. Locked doors

The locked door assembly brain looks like this:

WHEN [detect][player]
…WHEN [not][it][inventory][contains][Door key]

…/…WHEN DO [display][above][it][text:Find the key]
…WHEN [Once][it][inventory][contains][Door key]
…/…WHEN DO [power on]
…/…WHEN DO [play fx][Sparkle large]

What this says: Detect a player, check if the door key is not in their inventory (they dont have the key) and if true display text “Find the Key”. If the players inventory contains the key then power on the door and play a sparkle effect on the door.

The accompanying key brain looks like this:

WHEN DO [turn][quickly]
WHEN [started to][bump][player]

…WHEN DO [play fx][Pickup A][at position][position]
…WHEN DO [play sound][UI Collect coin]
…WHEN DO [it][pick up][me]

What this says: Make the key turn on the spot. When the player bumps into the key play an effect and a sound and add the key to the players inventory (this will also make it vanish from the world).

So, unlike a normal door, this door will automatically open when the player is detected and they have the key – they don’t have to interact with the door. Also, a message will come up telling the player to find the key when they are detected by the door, regardless of whether they try to open it or not. Also the key still remains in their inventory, even though thy have used it in the door. An alternative kode for the door so that the player has to interact to open or try to open the door, and will lose the key from their inventory when they put it in the door could look like this:

Page 1
1 WHEN [detect][player] DO
2 …WHEN [not][has power]
3 …/…[interacted] DO
4 …/…/…WHEN [it][inventory][contains][IWP:door key] DO [boolvar:door unlocked][=][true]
5 …/…/…WHEN DO [destroy][IWP:door key]
6 …/…/…/WHEN [boolvar:door unlocked][=][true] DO [power on]
7 …/…/…/…WHEN [Else] DO [switch page][2]

8 …WHEN [Else] DO [power off]

page 2
1 WHEN DO [display][screen center][text:Find the key]
2 WHEN [countdown timer][3] DO [switch page][1]

Showing a turning key
It may be nice to have an animated key in the lock. To do this place a key in the correct position on the door and attach it. Make the key invisible using  Edit / properties / appearance.

In the door brain put
WHEN DO [IWP:key in the door][visible][=][true]
between lines 5 and 6

In the key in the door brain

WHEN [visible]
…WHEN [duration timer][1] DO [pitch][slowly]

Coins/Collected objects
Doors can be locked until the player has collected relevant objects or number of objects – they dont need to be keys. In our example above it would look like this:

…/…/…WHEN [it][inventory][contains][your object] DO [boolvar:door unlocked][=][true]

If you want the door to open when a certain number of objects is obtained then you need to create a number variable for the object

Add this kode to objects you can collect. You will need separate variables for each type of object.

WHEN [started to][bump][player]
…WHEN DO [play fx][Pickup A][at position][position]
…WHEN DO [play sound][UI Collect coin]
…WHEN DO [it][pick up][me]
…WHEN DO [it][numvar:gem][incremented by][1]

In your door brain it will look something like this

WHEN [detect][player] DO
…WHEN [not][has power]
…/…[interacted] DO
…/…/…WHEN [it][numvar:gem][=>][5] DO [boolvar:door unlocked][=][true]
…/…/…WHEN DO [numvar:gem][decremented by][5]
…/…/…/WHEN [boolvar:door unlocked][=][true] DO [power on]
…/…/…/…WHEN [Else] DO [switch page][2]
…WHEN [Else] DO [power off]

4. Powering Doors

Doors open when they are powered on. Many objects can provide power, such as buttons levers, pressure pads, or other devices.

Place a lever in your world, add a power connection to the door, and remove all standard kode in the door brain. The door will open when the lever is powered on, and will close when the lever powers off.

Pressure pads
Create a pressure pad (you could use a cube sunk into the ground, a thin primitive, or Ancient stone landmark). Add this kode to the brain of your pressure pad, and link to your door with a power connector. Couple this with a timer in the door brain if you want the player to run for the door before it closes.

WHEN [bump] DO [power on]
…WHEN [Else] DO [power off]

Add a timer to the power on on the door and you can have a door that is open for a fixed amount of time.

WHEN [started to][power on]
…WHEN [countdown timer][5] DO [power off]

Kill enemies to unlock
You may have a locked room situation with enemies you need to defeat before the door opens.

Add this to your enemy brains

WHEN [once] DO [global][objset:room1enemy][incremented by][me]
WHEN[started to][is dead] DO [global][objset:room1enemy][decremented by][me]

Add this to the door brain

WHEN [detect][player] DO
…WHEN [not][has power]
…/…[interacted] DO

…/…/…WHEN [global][objset:room1enemy][=][0] DO [boolvar:door unlocked][=][true]
…/…/…/WHEN [boolvar:door unlocked][=][true] DO [power on]

…/…/…/…WHEN [Else] DO [switch page][2]
…WHEN [Else] DO [power off]


Comments are closed.

Website Powered by

Up ↑

%d bloggers like this: