retrace/Things/Door/Door.gd

55 lines
1.2 KiB
GDScript3
Raw Normal View History

2019-11-18 16:15:20 +01:00
extends KinematicBody
2019-11-18 16:39:26 +01:00
# export variables
export(NodePath) var outline_path
2019-11-18 18:16:46 +01:00
export(bool) var card_door
2019-11-18 18:25:57 +01:00
export(int) var door_lvl
2019-11-18 16:39:26 +01:00
# const
const OPENING_SPEED = 50
# private members
var _startingRotY
var _isMoving = false
var _isOpening = false
var _degrees = 0
2019-11-18 16:15:20 +01:00
# Called when the node enters the scene tree for the first time.
func _ready():
2019-11-18 16:39:26 +01:00
_startingRotY = global_transform.basis.get_euler().y
2019-11-18 16:15:20 +01:00
# Called every frame. 'delta' is the elapsed time since the previous frame.
2019-11-18 16:39:26 +01:00
func _process(delta):
2019-11-18 18:16:46 +01:00
if _isMoving:
door_move(delta)
# called by player to interact with this scene
func do_interact(var player):
if card_door:
2019-11-18 18:25:57 +01:00
if player.keycard_lvl >= door_lvl:
2019-11-18 18:16:46 +01:00
_isMoving = true
_isOpening = !_isOpening
else:
print("keycard level too low")
2019-11-18 18:25:57 +01:00
elif player.key_chain.has(door_lvl) or door_lvl == 0:
2019-11-18 16:39:26 +01:00
_isMoving = true
_isOpening = !_isOpening
2019-11-18 18:16:46 +01:00
else:
print("you don't have the right key")
# opens or closes the door
func door_move(delta):
2019-11-18 16:39:26 +01:00
if _isOpening:
if _degrees < 100:
_degrees += OPENING_SPEED * delta
else:
_degrees = 100
_isMoving = false
else:
if _degrees > 0:
_degrees -= OPENING_SPEED * delta
else:
_degrees = 0
_isMoving = false
rotate_y(_degrees * PI/180 - global_transform.basis.get_euler().y + _startingRotY)