65 lines
1.4 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
2020-01-25 19:07:51 +01:00
export(bool) var invert_open
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
2019-12-14 21:05:09 +01:00
var outline: MeshInstance
2019-11-18 16:39:26 +01:00
# const
const OPENING_SPEED = 50
# private members
2019-12-14 21:05:09 +01:00
var _startingRotY : float
2019-11-18 16:39:26 +01:00
var _isMoving = false
var _isOpening = false
var _degrees = 0
2020-01-25 19:07:51 +01:00
var _opening_dir = 1
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-12-14 21:05:09 +01:00
outline = get_node("DoorMesh/Outline") as MeshInstance
2020-01-25 19:07:51 +01:00
if invert_open:
_opening_dir = -1
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:
2019-12-14 21:05:09 +01:00
_door_move(delta)
2019-11-18 18:16:46 +01:00
# 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")
2019-12-14 21:05:09 +01:00
2019-11-18 18:16:46 +01:00
# opens or closes the door
2019-12-14 21:05:09 +01:00
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
2019-12-14 21:05:09 +01:00
2020-01-25 19:07:51 +01:00
rotate_y(_degrees * _opening_dir * PI/180 - global_transform.basis.get_euler().y + _startingRotY)