clean up monkeys
This commit is contained in:
@@ -8,9 +8,7 @@ extends Node2D
|
||||
func catch(p_coconut: Node2D):
|
||||
p_coconut.hide()
|
||||
coconut.text = p_coconut.text
|
||||
animation_player.play("catch")
|
||||
await animation_player.animation_finished
|
||||
animation_player.play("idle")
|
||||
await play("catch")
|
||||
|
||||
|
||||
func _on_animation_player_animation_finished(anim_name: StringName) -> void:
|
||||
@@ -23,28 +21,7 @@ func _on_animation_player_animation_finished(anim_name: StringName) -> void:
|
||||
animation_player.play("idle")
|
||||
|
||||
|
||||
func start_right() -> void:
|
||||
animation_player.play("start_right")
|
||||
await animation_player.animation_finished
|
||||
|
||||
|
||||
func finish_right() -> void:
|
||||
animation_player.play("finish_right")
|
||||
func play(animation: String) -> void:
|
||||
animation_player.play(animation)
|
||||
await animation_player.animation_finished
|
||||
animation_player.play("idle")
|
||||
|
||||
|
||||
func start_wrong() -> void:
|
||||
animation_player.play("start_wrong")
|
||||
await animation_player.animation_finished
|
||||
|
||||
|
||||
func finish_wrong() -> void:
|
||||
animation_player.play("finish_wrong")
|
||||
await animation_player.animation_finished
|
||||
animation_player.play("idle")
|
||||
|
||||
|
||||
func read() -> void:
|
||||
animation_player.play("read")
|
||||
await animation_player.animation_finished
|
||||
|
||||
@@ -45,6 +45,12 @@ func _on_button_pressed() -> void:
|
||||
pressed.emit()
|
||||
|
||||
|
||||
func play(animation: String) -> void:
|
||||
animation_player.play(animation)
|
||||
await animation_player.animation_finished
|
||||
animation_player.play("idle")
|
||||
|
||||
|
||||
func talk() -> void:
|
||||
animation_player.play("talk")
|
||||
await animation_player.animation_finished
|
||||
@@ -53,27 +59,9 @@ func talk() -> void:
|
||||
animation_player.play("idle")
|
||||
|
||||
|
||||
func grab() -> void:
|
||||
animation_player.play("grab")
|
||||
await animation_player.animation_finished
|
||||
animation_player.play("idle")
|
||||
|
||||
|
||||
func start_throw() -> void:
|
||||
animation_player.play("start_throw")
|
||||
await animation_player.animation_finished
|
||||
|
||||
|
||||
func finish_throw() -> void:
|
||||
animation_player.play("finish_throw")
|
||||
await animation_player.animation_finished
|
||||
animation_player.play("idle")
|
||||
|
||||
|
||||
func hit(p_coconut: Node2D) -> void:
|
||||
p_coconut.hide()
|
||||
animation_player.play("hit")
|
||||
await animation_player.animation_finished
|
||||
await play("hit")
|
||||
animation_player.play("stunned")
|
||||
stunned = true
|
||||
|
||||
|
||||
@@ -11,10 +11,23 @@ const difficulty_settings: = {
|
||||
4 : {"distractors_count": 5},
|
||||
}
|
||||
|
||||
const audio_streams: = [
|
||||
preload("res://assets/minigames/monkeys/audio/monkey_sendcoco.mp3"),
|
||||
preload("res://assets/minigames/monkeys/audio/monkey_sendcoco_right.mp3"),
|
||||
preload("res://assets/minigames/monkeys/audio/monkey_sendcoco_wrong.mp3"),
|
||||
]
|
||||
|
||||
enum Audio {
|
||||
SendToKing,
|
||||
SendToPlanck,
|
||||
SendToMonkey,
|
||||
}
|
||||
|
||||
@export var difficulty: = 1
|
||||
@export var lesson_nb: = 4
|
||||
@export var throw_to_king_duration: = 1.2
|
||||
@export var throw_to_monkey_duration: = 0.4
|
||||
@export var throw_to_planck_duration: = 0.8
|
||||
|
||||
@onready var monkeys_node: = $GameRoot/Monkeys
|
||||
@onready var possible_positions_parent: = $GameRoot/PalmTreeMonkeys
|
||||
@@ -63,18 +76,24 @@ func _on_current_progression_changed() -> void:
|
||||
await _set_current_letter(0)
|
||||
|
||||
|
||||
func _all_monkeys_say_word(word: String) -> void:
|
||||
if audio_player.playing:
|
||||
await audio_player.finished
|
||||
var coroutine: = Coroutine.new()
|
||||
for monkey in monkeys:
|
||||
coroutine.add_future(monkey.talk)
|
||||
audio_player.stream = Database.get_audio_stream_for_word(word)
|
||||
audio_player.play()
|
||||
if audio_player.playing:
|
||||
coroutine.add_future(audio_player.finished)
|
||||
await coroutine.join_all()
|
||||
await set_current_progression(current_progression + 1)
|
||||
|
||||
|
||||
func _set_current_letter(p_current_letter: int) -> void:
|
||||
_current_letter = p_current_letter
|
||||
if _current_letter >= stimuli[current_progression].GPs.size():
|
||||
var coroutine: = Coroutine.new()
|
||||
for monkey in monkeys:
|
||||
coroutine.add_future(monkey.talk)
|
||||
audio_player.stream = Database.get_audio_stream_for_word(stimuli[current_progression].Word)
|
||||
audio_player.play()
|
||||
if audio_player.playing:
|
||||
coroutine.add_future(audio_player.finished)
|
||||
await coroutine.join()
|
||||
await set_current_progression(current_progression + 1)
|
||||
await _all_monkeys_say_word(stimuli[current_progression].Word)
|
||||
return
|
||||
|
||||
var ind_good: = randi_range(0, monkeys.size() - 1)
|
||||
@@ -120,14 +139,16 @@ func say_word_and_grab_coconuts() -> void:
|
||||
if current_progression >= stimuli.size():
|
||||
return
|
||||
|
||||
if audio_player.playing:
|
||||
await audio_player.finished
|
||||
var coroutine: = Coroutine.new()
|
||||
audio_player.stream = Database.get_audio_stream_for_word(stimuli[current_progression].Word)
|
||||
audio_player.play()
|
||||
if audio_player.playing:
|
||||
coroutine.add_future(audio_player.finished)
|
||||
for monkey in monkeys:
|
||||
coroutine.add_future(monkey.grab)
|
||||
await coroutine.join()
|
||||
coroutine.add_future(monkey.play.bind("grab"))
|
||||
await coroutine.join_all()
|
||||
|
||||
|
||||
func _monkeys_drop_data(at_position: Vector2, data) -> void:
|
||||
@@ -143,10 +164,13 @@ func _on_coconut_drag_end(vector: Vector2, monkey: Monkey) -> void:
|
||||
monkey_throw_to_king(monkey)
|
||||
|
||||
|
||||
func monkey_throw_to_king(monkey: Monkey) -> void:
|
||||
lock()
|
||||
await monkey.start_throw()
|
||||
monkey.finish_throw()
|
||||
func _get_coconut_from_monkey_to_king(monkey: Monkey) -> Node2D:
|
||||
await monkey.play("start_throw")
|
||||
monkey.play("finish_throw")
|
||||
|
||||
audio_player.stream = audio_streams[Audio.SendToKing]
|
||||
audio_player.play()
|
||||
|
||||
var coconut: = monkey.coconut.duplicate()
|
||||
game_root.add_child(coconut)
|
||||
coconut.text = monkey.coconut.text
|
||||
@@ -162,36 +186,64 @@ func monkey_throw_to_king(monkey: Monkey) -> void:
|
||||
tween.tween_property(coconut, "global_position:y", king.catch_position.global_position.y, throw_to_king_duration / 2).set_trans(Tween.TRANS_QUAD).set_ease(Tween.EASE_IN)
|
||||
await tween.finished
|
||||
await king.catch(coconut)
|
||||
|
||||
return coconut
|
||||
|
||||
|
||||
# All monkeys talk but the sound is from a specific monkey, given as parameter
|
||||
func _king_reads_and_monkeys_talk(monkey: Monkey) -> void:
|
||||
var coroutine: = Coroutine.new()
|
||||
coroutine.add_future(king.read)
|
||||
coroutine.add_future(king.play.bind("read"))
|
||||
coroutine.add_future(monkey_talk.bind(monkey))
|
||||
await coroutine.join()
|
||||
await coroutine.join_all()
|
||||
|
||||
|
||||
func _on_right_coconut(coconut: Node2D) -> void:
|
||||
await king.play("start_right")
|
||||
|
||||
audio_player.stream = audio_streams[Audio.SendToPlanck]
|
||||
audio_player.play()
|
||||
|
||||
king.play("finish_right")
|
||||
var tween: = create_tween()
|
||||
coconut.show()
|
||||
coconut.global_transform = king.coconut.global_transform
|
||||
tween.tween_property(coconut, "global_position:y", text_plank.global_position.y, throw_to_planck_duration).set_trans(Tween.TRANS_LINEAR)
|
||||
await tween.finished
|
||||
coconut.queue_free()
|
||||
word_label.text = ""
|
||||
for i in _current_letter + 1:
|
||||
word_label.text += stimuli[current_progression].GPs[i].Grapheme
|
||||
word_label.text += "_".repeat(stimuli[current_progression].Word.length() - word_label.text.length())
|
||||
await _set_current_letter(_current_letter + 1)
|
||||
await say_word_and_grab_coconuts()
|
||||
|
||||
|
||||
func _on_wrong_coconut(coconut: Node2D, monkey: Monkey) -> void:
|
||||
await king.play("start_wrong")
|
||||
|
||||
audio_player.stream = audio_streams[Audio.SendToMonkey]
|
||||
audio_player.play()
|
||||
|
||||
king.play("finish_wrong")
|
||||
coconut.show()
|
||||
coconut.global_transform = king.coconut.global_transform
|
||||
var tween: = create_tween()
|
||||
tween.tween_property(coconut, "global_position", monkey.hit_position.global_position, throw_to_monkey_duration).set_trans(Tween.TRANS_LINEAR)
|
||||
await tween.finished
|
||||
await monkey.hit(coconut)
|
||||
coconut.queue_free()
|
||||
|
||||
|
||||
func monkey_throw_to_king(monkey: Monkey) -> void:
|
||||
lock()
|
||||
var coconut: = await _get_coconut_from_monkey_to_king(monkey)
|
||||
|
||||
await _king_reads_and_monkeys_talk(monkey)
|
||||
|
||||
if monkey.stimulus == stimuli[current_progression].GPs[_current_letter]:
|
||||
await king.start_right()
|
||||
king.finish_right()
|
||||
tween = create_tween()
|
||||
coconut.show()
|
||||
coconut.global_transform = king.coconut.global_transform
|
||||
tween.tween_property(coconut, "global_position:y", text_plank.global_position.y, throw_to_monkey_duration).set_trans(Tween.TRANS_LINEAR)
|
||||
await tween.finished
|
||||
coconut.queue_free()
|
||||
word_label.text = ""
|
||||
for i in _current_letter + 1:
|
||||
word_label.text += stimuli[current_progression].GPs[i].Grapheme
|
||||
word_label.text += "_".repeat(stimuli[current_progression].Word.length() - word_label.text.length())
|
||||
await _set_current_letter(_current_letter + 1)
|
||||
await say_word_and_grab_coconuts()
|
||||
await _on_right_coconut(coconut)
|
||||
else:
|
||||
await king.start_wrong()
|
||||
king.finish_wrong()
|
||||
coconut.show()
|
||||
coconut.global_transform = king.coconut.global_transform
|
||||
tween = create_tween()
|
||||
tween.tween_property(coconut, "global_position", monkey.hit_position.global_position, throw_to_monkey_duration).set_trans(Tween.TRANS_LINEAR)
|
||||
await tween.finished
|
||||
await monkey.hit(coconut)
|
||||
await _on_wrong_coconut(coconut, monkey)
|
||||
lock(false)
|
||||
|
||||
|
||||
@@ -213,4 +265,4 @@ func monkey_talk(monkey: Monkey) -> void:
|
||||
audio_player.play()
|
||||
if audio_player.playing:
|
||||
coroutine.add_future(audio_player.finished)
|
||||
await coroutine.join()
|
||||
await coroutine.join_all()
|
||||
|
||||
@@ -21,7 +21,8 @@ script = ExtResource("2_12lw5")
|
||||
difficulty = 0
|
||||
lesson_nb = 10
|
||||
throw_to_king_duration = 1.2
|
||||
throw_to_monkey_duration = 0.7
|
||||
throw_to_monkey_duration = 0.8
|
||||
throw_to_planck_duration = 0.9
|
||||
max_number_of_lives = 5
|
||||
max_progression = 1
|
||||
help_kalulu_speech = ExtResource("3_hhwrg")
|
||||
|
||||
@@ -179,7 +179,7 @@ func _parakeets_to_front(exceptions: Array[Parakeet] = []) -> void:
|
||||
continue
|
||||
|
||||
coroutine.add_future(_turn.bind(parakeet, false))
|
||||
await coroutine.join()
|
||||
await coroutine.join_all()
|
||||
|
||||
|
||||
func _present_parakeets() -> void:
|
||||
@@ -187,7 +187,7 @@ func _present_parakeets() -> void:
|
||||
var coroutine: = Coroutine.new()
|
||||
for parakeet in parakeets:
|
||||
coroutine.add_future(_turn.bind(parakeet, true))
|
||||
await coroutine.join()
|
||||
await coroutine.join_all()
|
||||
state = State.Idle
|
||||
|
||||
|
||||
@@ -203,7 +203,7 @@ func _make_selected_sad() -> void:
|
||||
var coroutine: = Coroutine.new()
|
||||
for parakeet in selected:
|
||||
coroutine.add_future(parakeet.sad)
|
||||
await coroutine.join()
|
||||
await coroutine.join_all()
|
||||
|
||||
|
||||
func _make_selected_coo() -> void:
|
||||
@@ -221,7 +221,7 @@ func _fly_to(targets: Array[Vector2]) -> void:
|
||||
coroutine.add_future(audio_player.finished)
|
||||
coroutine.add_future(selected[0].fly_to.bind(targets[0], fly_duration))
|
||||
coroutine.add_future(selected[1].fly_to.bind(targets[1], fly_duration))
|
||||
await coroutine.join()
|
||||
await coroutine.join_all()
|
||||
|
||||
|
||||
func _turn(parakeet: Parakeet, to_back: bool) -> void:
|
||||
@@ -241,6 +241,6 @@ func _flying_arrival(to: Array[Vector2]) -> void:
|
||||
coroutine.add_future(audio_player.finished)
|
||||
for i in parakeets.size():
|
||||
coroutine.add_future(parakeets[i].fly_to.bind(to[i], fly_duration))
|
||||
await coroutine.join()
|
||||
await coroutine.join_all()
|
||||
for parakeet in parakeets:
|
||||
parakeet.idle()
|
||||
|
||||
@@ -15,9 +15,7 @@ script = ExtResource("2_x6xn5")
|
||||
difficulty = 4
|
||||
lesson_nb = 4
|
||||
fly_duration = 3.0
|
||||
minigame_name = null
|
||||
max_number_of_lives = 5
|
||||
max_progression = null
|
||||
help_kalulu_speech = ExtResource("3_ofxb4")
|
||||
win_kalulu_speech = ExtResource("4_01e28")
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@ var is_completed: = false
|
||||
|
||||
# For join functionality
|
||||
signal _join()
|
||||
var _futures_count: = -1
|
||||
var _ended_count: = -1
|
||||
|
||||
var return_value
|
||||
|
||||
@@ -28,25 +28,31 @@ func resume() -> void:
|
||||
func add_future(param) -> void:
|
||||
assert(param is Callable or param is Signal, "Can only wait on Signal or Callable")
|
||||
# init
|
||||
if _futures_count < 0:
|
||||
_futures_count = 0
|
||||
if _ended_count < 0:
|
||||
_ended_count = 0
|
||||
return_value = []
|
||||
|
||||
var index: int = return_value.size()
|
||||
return_value.append(null)
|
||||
_futures_count += 1
|
||||
if param is Callable:
|
||||
return_value[index] = await param.call()
|
||||
else:
|
||||
await param
|
||||
_futures_count -= 1
|
||||
if _futures_count == 0:
|
||||
_ended_count += 1
|
||||
if _ended_count == return_value.size():
|
||||
_join.emit()
|
||||
|
||||
|
||||
func join() -> Array:
|
||||
if _futures_count <= 0:
|
||||
func join_all() -> Array:
|
||||
if _ended_count == return_value.size():
|
||||
return return_value
|
||||
await _join
|
||||
return return_value
|
||||
|
||||
|
||||
|
||||
func join_either() -> Array:
|
||||
if _ended_count > 0:
|
||||
return return_value
|
||||
_ended_count = return_value.size() - 1
|
||||
await _join
|
||||
return return_value
|
||||
|
||||
Reference in New Issue
Block a user