Added basic elevator system
This commit is contained in:
@ -6,34 +6,43 @@ var opened = false
|
||||
export var locked = false
|
||||
export var security_level = 0
|
||||
var player_level = -1
|
||||
var color_node : Node2D
|
||||
|
||||
|
||||
|
||||
func lock():
|
||||
locked = true
|
||||
$Top/Color.modulate = Color.red
|
||||
if color_node:
|
||||
color_node.modulate = Color.red
|
||||
|
||||
func unlock():
|
||||
locked = false
|
||||
set_color()
|
||||
|
||||
func set_color():
|
||||
match(security_level):
|
||||
0:
|
||||
$Top/Color.modulate = Color.green
|
||||
1:
|
||||
$Top/Color.modulate = Color.blue
|
||||
2:
|
||||
$Top/Color.modulate = Color.yellow
|
||||
3:
|
||||
$Top/Color.modulate = Color.orange
|
||||
4:
|
||||
$Top/Color.modulate = Color.red
|
||||
5:
|
||||
$Top/Color.modulate = Color.purple
|
||||
if color_node:
|
||||
match(security_level):
|
||||
0:
|
||||
color_node.modulate = Color.green
|
||||
1:
|
||||
color_node.modulate = Color.blue
|
||||
2:
|
||||
color_node.modulate = Color.yellow
|
||||
3:
|
||||
color_node.modulate = Color.orange
|
||||
4:
|
||||
color_node.modulate = Color.red
|
||||
5:
|
||||
color_node.modulate = Color.purple
|
||||
|
||||
# Called when the node enters the scene tree for the first time.
|
||||
func _ready():
|
||||
connect("body_entered", self, "_on_body_enter")
|
||||
connect("body_exited", self, "_on_body_exit")
|
||||
if $Top/Color:
|
||||
color_node = $Top/Color
|
||||
elif $Color:
|
||||
color_node = $Color
|
||||
if locked:
|
||||
lock()
|
||||
else:
|
||||
@ -60,6 +69,7 @@ func close():
|
||||
if opened:
|
||||
$AnimationPlayer.play("Close")
|
||||
$AudioStreamPlayer2D.play()
|
||||
|
||||
$StaticBody2D.collision_layer = 1
|
||||
$StaticBody2D.collision_mask = 1
|
||||
opened = false
|
||||
|
62
client/Scripts/Entities/Elevator.gd
Normal file
62
client/Scripts/Entities/Elevator.gd
Normal file
@ -0,0 +1,62 @@
|
||||
extends Node2D
|
||||
|
||||
signal elevator_stopped
|
||||
|
||||
export(Array, Vector2) var relative_positions = [Vector2(0,0)]
|
||||
export(Array, String) var labels = ["Default"]
|
||||
export(Array, NodePath) var doors = []
|
||||
export var current_pos : int = 0
|
||||
|
||||
var moving : bool = false
|
||||
|
||||
var gui
|
||||
var motion
|
||||
var intial_pos : Vector2
|
||||
export var elevator_speed = 25
|
||||
|
||||
func _ready():
|
||||
motion = Vector2.ZERO
|
||||
intial_pos = global_position
|
||||
|
||||
func _on_interact():
|
||||
if not moving:
|
||||
if not gui:
|
||||
gui = get_node("/root/World/GUI")
|
||||
gui.open_elevator_menu(self)
|
||||
|
||||
func _on_choice(index):
|
||||
start_moving(index)
|
||||
gui.close_elevator_menu()
|
||||
|
||||
func start_moving(index):
|
||||
if current_pos != index:
|
||||
moving = true
|
||||
current_pos = index
|
||||
|
||||
# Close all doors while in transit
|
||||
for door_path in doors:
|
||||
var door = get_node(door_path)
|
||||
door.close()
|
||||
door.lock()
|
||||
return true
|
||||
return false
|
||||
|
||||
func stop_moving():
|
||||
emit_signal("elevator_stopped")
|
||||
moving = false
|
||||
# Alert doors of updated elevator state
|
||||
for door_path in doors:
|
||||
get_node(door_path).on_elevator_stop(current_pos)
|
||||
|
||||
func _physics_process(delta):
|
||||
if moving:
|
||||
# Move towards elevator stop
|
||||
var target_pos = intial_pos + relative_positions[current_pos]
|
||||
var angle = get_angle_to(target_pos)
|
||||
var velocity = Vector2(cos(angle),sin(angle))
|
||||
global_position += velocity * elevator_speed * delta
|
||||
|
||||
# Stop when elevator is at destination
|
||||
if global_position.distance_to(target_pos) < 0.25:
|
||||
global_position = target_pos
|
||||
stop_moving()
|
20
client/Scripts/Entities/ElevatorButton.gd
Normal file
20
client/Scripts/Entities/ElevatorButton.gd
Normal file
@ -0,0 +1,20 @@
|
||||
extends "res://Scripts/Component/Interactable.gd"
|
||||
|
||||
export(NodePath) var elevator
|
||||
export var call_to_index : int = 0
|
||||
|
||||
var elevator_node
|
||||
|
||||
func _ready():
|
||||
elevator_node = get_node(elevator)
|
||||
connect("interacted", self, "_on_interact")
|
||||
$AnimationPlayer.play("Done")
|
||||
|
||||
func _on_interact():
|
||||
if elevator_node.start_moving(call_to_index):
|
||||
elevator_node.connect("elevator_stopped", self, "_on_finish")
|
||||
$AnimationPlayer.play("Waiting")
|
||||
|
||||
func _on_finish():
|
||||
elevator_node.disconnect("elevator_stopped", self, "_on_finish")
|
||||
$AnimationPlayer.play("Done")
|
10
client/Scripts/Entities/ElevatorDoor.gd
Normal file
10
client/Scripts/Entities/ElevatorDoor.gd
Normal file
@ -0,0 +1,10 @@
|
||||
extends "res://Scripts/Entities/Door.gd"
|
||||
|
||||
export var level_index : int = 0
|
||||
|
||||
func on_elevator_stop(index):
|
||||
if index == level_index:
|
||||
unlock()
|
||||
open()
|
||||
else:
|
||||
lock()
|
@ -139,17 +139,17 @@ func user_input():
|
||||
# Interactions
|
||||
if Input.is_action_just_pressed("interact") and len(interactables) > 0 and not gui.is_in_dialog():
|
||||
interact()
|
||||
|
||||
# Move down platforms
|
||||
if is_on_floor() and Input.is_action_just_pressed("ui_up") and Input.is_action_pressed("ui_down"):
|
||||
var test_pos = Vector2(position.x,position.y+6)
|
||||
if not test_move(Transform2D(0,test_pos), Vector2(0,1)):
|
||||
position.y = position.y + 2
|
||||
return
|
||||
|
||||
|
||||
# Jumping
|
||||
if(test_move(transform, Vector2(0,1)) and Input.is_action_just_pressed("ui_up")):
|
||||
jumped = true
|
||||
if Input.is_action_just_pressed("ui_up"):
|
||||
if Input.is_action_pressed("ui_down"):
|
||||
if is_on_floor():
|
||||
var test_pos = Vector2(position.x,position.y+6)
|
||||
if not test_move(Transform2D(0,test_pos), Vector2(0,1)):
|
||||
position.y = position.y + 2
|
||||
return
|
||||
elif(test_move(transform, Vector2(0,1))):
|
||||
jumped = true
|
||||
|
||||
# Move left and right <- & ->
|
||||
# - - - - - - - - - - - - - - -
|
||||
|
@ -1,7 +1,9 @@
|
||||
extends Sprite
|
||||
|
||||
export var shadows : bool = false
|
||||
export var energy : float = 1.1
|
||||
|
||||
func _ready():
|
||||
$Light2D.show()
|
||||
$Light2D.shadow_enabled = shadows
|
||||
$Light2D.energy = energy
|
||||
|
Reference in New Issue
Block a user