Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

improvement: have a single Robot scene for visuals and practices #276

Merged
merged 16 commits into from
Feb 6, 2022

Conversation

cogwoz
Copy link
Contributor

@cogwoz cogwoz commented Feb 6, 2022

This PR replaces each visual that uses the robot sprites with a dedicated robot scene which is easier to maintain and add to.

fixes #249
fixes #260

Previously, there were several different versions of the robot because many of the lessons were created in parallel.

There are currently 6 animations, some placeholder:

  • idle (default)
  • jump
  • heal
  • damage
  • level
  • saying_hi

The robot uses an AnimationTree to control its animations.

image

To play an animation, use the following. The robot will automatically go back to its "idle" animation.

onready var _animation_tree := find_node("AnimationTree")

func _ready():
	_animation_tree.travel("jump")

The AnimationTree has a helper script to allow the above which makes moving to each animation easier.

## RobotAnimationTree.gd
extends AnimationTree

signal animation_finished

onready var _state_machine = self["parameters/playback"]
onready var _animation_player = get_node(anim_player) as AnimationPlayer

func _ready() -> void:
	_animation_player.connect("animation_finished", self, "_on_animation_finished")

func travel(animation_name: String) -> void:
	_state_machine.travel(animation_name)

func _on_animation_finished() -> void:
	emit_signal("animation_finished")

In Godot, currently AnimationPlayers stop emitting signals when controlled by an AnimationTree, so each animation emits the animation_finished signal via the method track which feeds up to the AnimationTree.

image

This allows us to wait on animations before continuing in practices.

## IncreaseMaxHealth.gd
# ...
func _run():
	for i in range(2):
		level_up()
		_animation_tree.travel("level")
		yield(_animation_tree, "animation_finished")
	Events.emit_signal("practice_run_completed")

I tested all of the visuals and practices, so everything should just seemlessly work.

@cogwoz cogwoz requested a review from NathanLovato February 6, 2022 19:17
@NathanLovato
Copy link
Contributor

I quickly went through the scenes and everything seems to be working well. I'll have a tester go through all lessons again soon too. Thanks for your work!

@NathanLovato NathanLovato merged commit cc6e145 into main Feb 6, 2022
@NathanLovato NathanLovato deleted the robot-scene branch February 6, 2022 21:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ExampleRotateSprite.tscn in Lesson 3 doesn't show Have one robot scene we can use throughout the course
2 participants