diff --git a/scripts/cauldron_bar.gd b/scripts/cauldron_bar.gd index c98cde3..8727a92 100644 --- a/scripts/cauldron_bar.gd +++ b/scripts/cauldron_bar.gd @@ -9,9 +9,12 @@ var slots: Array[TextureRect] = [] var colors: Array[AtlasTexture] = [] var burning_colors: Array[AtlasTexture] = [] var slot_states = [0, 0, 0] - +var progres_index = 0 +var is_brewing +@onready var witch = get_parent() # Called when the node enters the scene tree for the first time. func _ready() -> void: + print(witch) base.atlas = preload("res://assets/Cauldron's Brew/Equiptment.png") base.region = Rect2(96, 96, 96, 96) yellow.atlas = preload("res://assets/Cauldron's Brew/Cauldron and Powder.png") @@ -55,10 +58,36 @@ func enrich_burning_colors(): burning.region = Rect2(color.region.position.x, color.region.position.y + 96, 96, 96) burning_colors.append(burning) -func progres_bar(fruit, progress): - +func progres_bar(fruit): + if is_brewing: + return if fruit is Apple: - change_texture(progress,3) + change_texture(progres_index,2) if fruit is Grape: - change_texture(progress, 4) + change_texture(progres_index, 4) + progres_index += 1 + if progres_index == 3: + brew(slot_states) + progres_index = 0 pass + +func brew(fruits): + is_brewing = true + var unique = get_unique_fruits() + await ignite_cauldrons() + if unique.has(2) and unique.size() == 1: + witch.shoot_fireballs() + elif unique.has(4) and unique.size() == 1: + witch.shoot_shuriken() + elif unique.has(2) and unique.has(4) and unique.size() == 2: + witch.shoot_fireballs() + witch.shoot_shuriken() + reset_texture() + is_brewing = false + +func get_unique_fruits() -> Array: + var unique = [] + for fruit in slot_states: + if fruit != null and not fruit in unique: + unique.append(fruit) + return unique diff --git a/scripts/witch.gd b/scripts/witch.gd index d8ea78a..ff45d48 100644 --- a/scripts/witch.gd +++ b/scripts/witch.gd @@ -1,12 +1,12 @@ extends CharacterBody2D var camera -var bar_progress = 0 var is_casting = false var fireball = preload("res://scenes/fireball.tscn") var shuriken = preload("res://scenes/shuriken.tscn") func _ready() -> void: + $CauldronBar.witch = self camera = get_node("/root/Game/Camera2D") func _physics_process(delta: float) -> void: @@ -16,16 +16,8 @@ func _physics_process(delta: float) -> void: func _on_collect(DropsBase): if is_casting: return - $CauldronBar.progres_bar(DropsBase, bar_progress) - bar_progress += 1 - if bar_progress == 3: - bar_progress = 0 - is_casting = true - await $CauldronBar.ignite_cauldrons() - shoot_shuriken() - camera.shake(0.3,0.8) - $CauldronBar.reset_texture() - is_casting = false + $CauldronBar.progres_bar(DropsBase) + func shoot_fireballs(): var enemies = get_tree().get_nodes_in_group("enemies") @@ -34,6 +26,7 @@ func shoot_fireballs(): fb.global_position = global_position get_parent().add_child(fb) fb.launch(enemy.global_position) + camera.shake(0.3,0.8) func shoot_shuriken(): var sh = shuriken.instantiate()