Door Tutorial by LadyLexUK

Have something important that other people might find usefull? Well, drop it here and help others!
User avatar
LucidStew
Level 3
Level 3
Posts: 176

Door Tutorial by LadyLexUK

Post#1 » Mon Aug 15, 2016 7:49 am

moved over from projectspark.com forums

Key:

... Indented child line
.../... Twice indented child line
boolvar: User defined boolean variable
numvar: User defined number variable
textvar: User defined text variable
objvar: User defined object variable
objset: User defined object set
IWP: In world picker
[]: tile

Tutorials about doors

1. Placing a door in your world.
Standard door Kode
Alternative 1: Open and close with interact
Alternative 2: Open door only
Alternative 3: Door opens automatically
Alternative 4: Door opens and closes automatically
Alternative 5: Interact to open, automatic close


2. Locked doors
a)Keys
Standard locked door assembly
Alternative locked door Kode
Locked door with visible key

b)Levers
c)Timed
d)Pressure pads
e)Coins/Collected objects
f)Kill enemies to unlock



1 - Placing a door in your world

If you are building your own walls using terrain, you will need to leave a gap for the door. The door will not remove the terrain behind it, and it is possible to have a door opening onto a solid wall. Doors placed on house assemblies will always open onto a solid wall.

Direction of door opening
Doors in the prop gallery generally come complete with hinges and surround. They open in one direction only. To change whether a door opens outwards or inwards you need to rotate the prop. It is not possible for the door to always open away from the player, so in one direction the door will hit and push the player out of the way. Unless it is important for the door to close behind the player, have the door open away from the player and just leave the door open. Remove any Kode that powers off the door.

The standard 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]

Alternative 1 :Open or close the door by interacting with it
WHEN [not][has power] DO
...WHEN [Interacted] DO [power on]
WHEN [has power]
...WHEN [countdown timer][1][in frames]
.../…WHEN[interacted] DO [power off]

You need the countdown so that the interaction does not turn the power on and off at the same time.

Alternative 2: Open door only. Door stays open.
WHEN [not][has power] DO
...WHEN [Interacted] DO [power on]

Alternative 3: Door opens automatically
WHEN [detect][player] DO [power on]

Alternative 4: Door opens and closes automatically
WHEN [detect][player] DO [power on]
...WHEN [Else] DO [power off]

Advantages to this rather than powering the door shut with a timer, is the player will always be out of the way and will not be hit in the face or back with the door.

Alternative 5: Interact to open, automatic close (recommended alternative to standard door Kode)
WHEN [detect][player] DO
...WHEN [not][has power]
…/...[interacted] DO [power on]
…[Else] DO [power off]

2 -Locked doors

a - Keys
The standard pack comes with a locked door assembly. Its 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]

and the keys 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]

This will open the door immediately the player is within detection zone of the door and has a key. It will not remove the key from the inventory upon opening the door. The door remains open.

Alternative 1
Door
WHEN [detect][player] DO
...WHEN [not][has power]
.../...[interacted] DO
.../.../...WHEN [it][inventory][contains][door key] DO [boolvar:door unlocked][=][true]
.../.../.../...WHEN DO [destroy][door key]
.../.../...WHEN [boolvar:door unlocked][=][true] DO [power on]
.../.../.../...WHEN [Else] DO [switch page][2]
…WHEN [Else] DO [power off]

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

*see Display messages with a timer tutorial

This will display a message if the door is locked. Will open door if the player interacts and has a key or has already unlocked the door. Will destroy the key from the inventory.Will close when the player is out of the detection zone.

Showing a turning key to open a door

Put a key into your world and place it against the door so it looks like it is in the lock. (Do this on the side of the door the player will be standing when the door is unlocked. Using attach, attach the key to the door. Make the key invisible using Edit/properties/appearance.

In door brain:
Add this line after destroy Door key (same level)

WHEN DO [IWP:key in the door][visible][=][true]

In the key brain

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



b -Levers
Doors open when they are powered on. 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.

c -Timed
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] DO [switch page] [2]

Page 2
WHEN [countdown timer][5] DO [power off]
...WHEN DO [switch page][1]

d - Pressure pads
Create a pressure pad with a cube sunk into the ground, a thin primitive, 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]

e - 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]




f - 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]
End of line.

Return to “Tutorials and guides”

Who is online

Users browsing this forum: No registered users and 1 guest

cron