GMTK-2024/gmtk_2024/scripts/PressurePlate.gd

39 lines
1.1 KiB
GDScript3
Raw Normal View History

2024-08-19 01:29:43 +02:00
extends StaticBody2D
2024-08-19 03:35:03 +02:00
@export var laser_path: NodePath = "../Laser"
2024-08-19 01:29:43 +02:00
@export var required_scale: Vector2 = Vector2(1.0, 1.0)
@export var player_required_scale: Vector2 = Vector2(2.0, 2.0)
@onready var animation = $AnimationPlayer
var laser: Node2D = null
var is_activated = false
func _ready():
laser = get_node(laser_path)
func _on_body_entered(body: Node):
print("Wird erkannt")
2024-08-19 03:15:07 +02:00
print(body)
print(body.scale)
if (body is AnimatableBody2D and body.scale >= required_scale) or (body is CharacterBody2D and body.scale >= player_required_scale):
2024-08-19 01:29:43 +02:00
animation.play("Disable")
activate_plate()
func _on_body_exited(body: Node):
2024-08-19 03:15:07 +02:00
if (body is AnimatableBody2D and body.scale >= required_scale) or (body is CharacterBody2D and body.scale >= player_required_scale):
2024-08-19 01:29:43 +02:00
animation.play("Enable")
deactivate_plate()
func activate_plate():
print("wird aktiviert")
if not is_activated:
is_activated = true
2024-08-19 18:33:47 +02:00
if laser and weakref(laser).get_ref():
2024-08-19 03:15:07 +02:00
laser.queue_free()
# TODO: fix error when called again
2024-08-19 01:29:43 +02:00
func deactivate_plate():
if is_activated:
is_activated = false