keys and doors working
This commit is contained in:
47
scripts/key_door.gd
Normal file
47
scripts/key_door.gd
Normal file
@@ -0,0 +1,47 @@
|
||||
extends Node3D
|
||||
|
||||
@onready var level_control = get_tree().current_scene
|
||||
|
||||
@export var anim_player : Node
|
||||
@export var door_open_start : bool = false
|
||||
@export_enum("Silver", "Gold", "Special") var key_type_required: int
|
||||
@export var special_key_name : String
|
||||
|
||||
var door_open : bool
|
||||
|
||||
|
||||
# Called when the node enters the scene tree for the first time.
|
||||
func _ready() -> void:
|
||||
door_open = door_open_start
|
||||
|
||||
if door_open:
|
||||
open()
|
||||
else:
|
||||
close()
|
||||
|
||||
func open():
|
||||
door_open = true
|
||||
anim_player.play("open")
|
||||
|
||||
func close():
|
||||
door_open = false
|
||||
anim_player.play("close")
|
||||
|
||||
func interact():
|
||||
if !door_open:
|
||||
print("checking keys..." + str(level_control.keys))
|
||||
|
||||
var exit = false
|
||||
|
||||
for i in level_control.keys:
|
||||
if !exit:
|
||||
if i[0] == key_type_required:
|
||||
if key_type_required == 2:
|
||||
if i[1] == special_key_name:
|
||||
open()
|
||||
level_control.keys.erase(i)
|
||||
exit = true
|
||||
else:
|
||||
open()
|
||||
level_control.keys.erase(i)
|
||||
exit = true
|
||||
@@ -4,16 +4,36 @@ extends RigidBody3D
|
||||
@export var special_key_name : String
|
||||
@export var collision_shape : Node
|
||||
|
||||
@onready var level_control = get_tree().current_scene
|
||||
@onready var player = get_tree().current_scene.player
|
||||
|
||||
var pickupable = true
|
||||
var pick_up = false
|
||||
var rand_amt
|
||||
var player_follow
|
||||
|
||||
|
||||
# Called when the node enters the scene tree for the first time.
|
||||
func _ready() -> void:
|
||||
|
||||
add_to_group("pickup")
|
||||
|
||||
|
||||
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
||||
func _process(delta: float) -> void:
|
||||
pass
|
||||
func _physics_process(delta: float) -> void:
|
||||
if player_follow != null:
|
||||
if !pick_up:
|
||||
angular_velocity = lerp(angular_velocity, Vector3(0,0,0), delta)
|
||||
position = lerp(position, player.item_holder.global_position, 25 * delta)
|
||||
|
||||
if abs(position - player.item_holder.global_position) < Vector3(.5,.5,.5):
|
||||
await get_tree().create_timer(1).timeout
|
||||
position = lerp(position, player.camera.global_position, .01 * delta)
|
||||
await get_tree().create_timer(.01).timeout
|
||||
picked_up()
|
||||
|
||||
func picked_up():
|
||||
pass
|
||||
var key_attributes = [key_type, special_key_name]
|
||||
level_control.keys.append(key_attributes)
|
||||
print(level_control.keys)
|
||||
queue_free()
|
||||
|
||||
@@ -159,6 +159,7 @@ func _physics_process(delta):
|
||||
air_dash -= 1
|
||||
print("AIR DASH " +str(air_dash))
|
||||
|
||||
#walking
|
||||
if is_on_floor() and !is_climbing:
|
||||
if direction:
|
||||
velocity.x = lerp(velocity.x, direction.x * speed, delta * WALK_TRANSITION_SPEED)
|
||||
@@ -166,6 +167,7 @@ func _physics_process(delta):
|
||||
else:
|
||||
velocity.x = lerp(velocity.x, direction.x * speed, delta * 6.5) + (direction.x * DASH_SPEED)
|
||||
velocity.z = lerp(velocity.z, direction.z * speed, delta * 6.5) + (direction.z * DASH_SPEED)
|
||||
#ladder movement
|
||||
elif is_climbing:
|
||||
gravity = 0.0
|
||||
if direction:
|
||||
@@ -174,9 +176,10 @@ func _physics_process(delta):
|
||||
else:
|
||||
velocity.y = lerp(velocity.y, -direction.z * speed, delta * 6.5)
|
||||
velocity.x = lerp(velocity.x, direction.x * speed, delta * 6.5)
|
||||
#movement in air
|
||||
else:
|
||||
velocity.x = lerp(velocity.x, direction.x * speed, delta * 6.5)
|
||||
velocity.z = lerp(velocity.z, direction.z * speed, delta * 6.5)
|
||||
velocity.x = lerp(velocity.x, direction.x * speed, delta * 3)
|
||||
velocity.z = lerp(velocity.z, direction.z * speed, delta * 3)
|
||||
|
||||
# Head bob
|
||||
t_bob += delta * velocity.length() * float(is_on_floor())
|
||||
|
||||
Reference in New Issue
Block a user