Added Level. Removed params from _init()

This commit is contained in:
2024-09-09 02:15:39 +03:00
parent f4758551cb
commit e7cbf0a6a1
11 changed files with 78 additions and 49 deletions
+15 -18
View File
@@ -1,11 +1,13 @@
class_name Door
extends StaticBody2D
enum DoorType {BOTTOM_DOOR, TOP_DOOR}
@export var door_type: DoorType
@export var type: DoorType
enum DoorState {OPENED, CLOSED, OPENING, CLOSING}
@export var door_state: DoorState
@export var state: DoorState
var ANIMATIONS_BY_TYPE : Dictionary = {
@@ -25,50 +27,45 @@ signal opened()
signal closed()
func _init(type: DoorType = DoorType.BOTTOM_DOOR, state: DoorState = DoorState.OPENED) -> void:
door_type = type
door_state = state
func _ready() -> void:
play_animation()
func play_animation() -> void:
var animation : String = "%s_%s" % [
ANIMATIONS_BY_TYPE[door_type],
ANIMATIONS_BY_STATE[door_state]
ANIMATIONS_BY_TYPE[type],
ANIMATIONS_BY_STATE[state]
]
$AnimatedSprite2D.play(animation)
func open() -> void:
if door_state != DoorState.CLOSED:
print("Door in state '%s' can't be opened" % DoorState.find_key(door_state))
if state != DoorState.CLOSED:
print("Door in state '%s' can't be opened" % DoorState.find_key(state))
return
door_state = DoorState.OPENING
state = DoorState.OPENING
play_animation()
func close():
if door_state != DoorState.OPENED:
print("Door in state '%s' can't be closed" % DoorState.find_key(door_state))
if state != DoorState.OPENED:
print("Door in state '%s' can't be closed" % DoorState.find_key(state))
return
door_state = DoorState.CLOSING
state = DoorState.CLOSING
play_animation()
func _on_animated_sprite_2d_animation_finished() -> void:
match door_state:
match state:
DoorState.CLOSING:
door_state = DoorState.CLOSED
state = DoorState.CLOSED
$CollisionShape2D.disabled = false
play_animation()
DoorState.OPENING:
door_state = DoorState.OPENED
state = DoorState.OPENED
$CollisionShape2D.disabled = true
play_animation()
DoorState.CLOSED: