129 lines
3.9 KiB
GDScript
129 lines
3.9 KiB
GDScript
extends HBoxContainer
|
|
|
|
var base = AtlasTexture.new()
|
|
var yellow = AtlasTexture.new()
|
|
var orange = AtlasTexture.new()
|
|
var red = AtlasTexture.new()
|
|
var purple = AtlasTexture.new()
|
|
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
|
|
var brew_explosion = true
|
|
@onready var witch = get_parent()
|
|
var explosion_scene = preload("res://scenes/explosion.tscn")
|
|
var _ignite_sfx = preload("res://assets/music&sfx/sfx/data_pion-sfx9-fwoosh-324525.mp3")
|
|
var _ignite_player: AudioStreamPlayer
|
|
var _slot_shake_tweens: Array = []
|
|
|
|
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")
|
|
yellow.region = Rect2(96, 96, 96, 96)
|
|
orange.atlas = preload("res://assets/Cauldron's Brew/Cauldron and Powder.png")
|
|
orange.region = Rect2(192, 96, 96, 96)
|
|
red.atlas = preload("res://assets/Cauldron's Brew/Cauldron and Powder.png")
|
|
red.region = Rect2(288, 96, 96, 96)
|
|
purple.atlas = preload("res://assets/Cauldron's Brew/Cauldron and Powder.png")
|
|
purple.region = Rect2(480, 96, 96, 96)
|
|
slots = [$Empty1, $Empty2, $Empty3]
|
|
colors = [base, yellow, red, orange, purple]
|
|
enrich_burning_colors()
|
|
_ignite_player = AudioStreamPlayer.new()
|
|
_ignite_player.stream = _ignite_sfx
|
|
_ignite_player.volume_db = -15
|
|
add_child(_ignite_player)
|
|
|
|
|
|
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
|
func _process(delta: float) -> void:
|
|
pass
|
|
|
|
func change_texture(slot_index: int, color_index: int):
|
|
slots[slot_index].texture = colors[color_index]
|
|
slot_states[slot_index] = color_index
|
|
pass
|
|
|
|
func reset_texture():
|
|
for t in _slot_shake_tweens:
|
|
if t:
|
|
t.kill()
|
|
_slot_shake_tweens.clear()
|
|
for i in slots.size():
|
|
slots[i].texture = colors[0]
|
|
slots[i].rotation = 0.0
|
|
slot_states = [0, 0, 0]
|
|
|
|
func ignite_cauldrons():
|
|
for i in slots.size():
|
|
slots[i].texture = burning_colors[slot_states[i]]
|
|
_ignite_player.pitch_scale = randf_range(0.8, 1.2)
|
|
_ignite_player.play()
|
|
_slot_shake_tweens.append(_make_slot_shake(slots[i]))
|
|
await get_tree().create_timer(0.4).timeout
|
|
if brew_explosion:
|
|
var boom = explosion_scene.instantiate()
|
|
get_parent().add_child(boom)
|
|
boom.scale = Vector2(3,3)
|
|
boom.global_position = witch.global_position
|
|
|
|
pass
|
|
|
|
func enrich_burning_colors():
|
|
for color in colors:
|
|
var burning = AtlasTexture.new()
|
|
burning.atlas = color.atlas
|
|
burning.region = Rect2(color.region.position.x, color.region.position.y + 96, 96, 96)
|
|
burning_colors.append(burning)
|
|
|
|
func progres_bar(fruit):
|
|
if is_brewing:
|
|
return
|
|
if fruit is Apple:
|
|
change_texture(progres_index, 2)
|
|
if fruit is Grape:
|
|
change_texture(progres_index, 4)
|
|
_pop_slot(progres_index)
|
|
progres_index += 1
|
|
if progres_index == 3:
|
|
brew(slot_states)
|
|
progres_index = 0
|
|
pass
|
|
|
|
func _pop_slot(slot_index: int) -> void:
|
|
var slot = slots[slot_index]
|
|
slot.pivot_offset = slot.size / 2
|
|
slot.scale = Vector2(1.35, 1.35)
|
|
var t = create_tween()
|
|
t.tween_property(slot, "scale", Vector2(1.0, 1.0), 0.18).set_trans(Tween.TRANS_BACK).set_ease(Tween.EASE_OUT)
|
|
|
|
func _make_slot_shake(slot: TextureRect) -> Tween:
|
|
slot.pivot_offset = slot.size / 2
|
|
var t = create_tween().set_loops()
|
|
t.tween_property(slot, "rotation", 0.015, 0.05)
|
|
t.tween_property(slot, "rotation", -0.015, 0.05)
|
|
t.tween_property(slot, "rotation", 0.0, 0.05)
|
|
return t
|
|
|
|
func brew(fruits):
|
|
is_brewing = true
|
|
await ignite_cauldrons()
|
|
match SpellLibrary.identify(fruits):
|
|
SpellLibrary.SHURIKEN: witch.shoot_shuriken()
|
|
SpellLibrary.FIREBALL: witch.shoot_fireballs()
|
|
SpellLibrary.FIRE_SWIRL: witch.shoot_fire_swirl()
|
|
SpellLibrary.TORNADO: witch.shoot_tornado()
|
|
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
|