diff --git a/course/lesson-10-the-game-loop/visuals/ExampleRotatingSprite.tscn b/course/lesson-10-the-game-loop/visuals/ExampleRotatingSprite.tscn index e8593714..1ddd1210 100644 --- a/course/lesson-10-the-game-loop/visuals/ExampleRotatingSprite.tscn +++ b/course/lesson-10-the-game-loop/visuals/ExampleRotatingSprite.tscn @@ -13,10 +13,12 @@ func _ready(): func run(): set_process(true) + func reset(): set_process(false) rotation = 0 + func _process(delta : float) -> void: rotate(0.05) " diff --git a/course/lesson-11-time-delta/visuals/ExampleRotatingWithDelta.tscn b/course/lesson-11-time-delta/visuals/ExampleRotatingWithDelta.tscn index d89b16a5..050a9280 100644 --- a/course/lesson-11-time-delta/visuals/ExampleRotatingWithDelta.tscn +++ b/course/lesson-11-time-delta/visuals/ExampleRotatingWithDelta.tscn @@ -9,14 +9,16 @@ script/source = "extends Node2D func _ready() -> void: set_process(false) - + func _process(delta: float) -> void: rotate(3.0 * delta) + func reset(): set_process(false) - + rotation = 0 + func run(): set_process(true) diff --git a/course/lesson-14-multiplying/visuals/Graph.gd b/course/lesson-14-multiplying/visuals/Graph.gd index dd33bb59..981f8fae 100644 --- a/course/lesson-14-multiplying/visuals/Graph.gd +++ b/course/lesson-14-multiplying/visuals/Graph.gd @@ -52,6 +52,11 @@ func run() -> void: _line.start_draw_animation() +func reset() -> void: + _line.reset() + _last_point = Vector2(0, 0) + + func _process(_delta: float) -> void: if Engine.editor_hint: return @@ -75,7 +80,8 @@ func _draw() -> void: for i in range(graph_size.y / axis_increments): draw_circle(-Vector2(0, axis_increments + i * axis_increments) + draw_offset, 4, Color.white) - draw_circle(_last_point, 4, Color.white) + if _last_point != Vector2(0, 0): + draw_circle(_last_point, 4, Color.white) class Polygon: @@ -135,7 +141,7 @@ class Polygon: _tween.start() func stop_animation() -> void: - _tween.stop_all() + _tween.remove_all() func is_drawing() -> bool: return _tween.is_active() diff --git a/course/lesson-15-modulo/visuals/TrafficLights.gd b/course/lesson-15-modulo/visuals/TrafficLights.gd index 3fc74cb2..9a911439 100644 --- a/course/lesson-15-modulo/visuals/TrafficLights.gd +++ b/course/lesson-15-modulo/visuals/TrafficLights.gd @@ -1,7 +1,8 @@ extends Node2D -var light_index := -1 +var initial_light_index := 0 +var light_index := initial_light_index - 1 onready var _tween := $Tween onready var _index_label := $Index @@ -27,6 +28,13 @@ func run() -> void: _index_label.text = str(light_index) +func reset() -> void: + light_index = initial_light_index + turn_on_light(initial_light_index) + + _index_label.text = str(light_index) + + func turn_on_light(light_index) -> void: for light in _lights: diff --git a/course/lesson-22-functions-return-values/visuals/ExampleRoundingHealth.tscn b/course/lesson-22-functions-return-values/visuals/ExampleRoundingHealth.tscn index b2b8ed5c..03b9acb3 100644 --- a/course/lesson-22-functions-return-values/visuals/ExampleRoundingHealth.tscn +++ b/course/lesson-22-functions-return-values/visuals/ExampleRoundingHealth.tscn @@ -7,14 +7,17 @@ script/source = " tool extends RunnableCodeExample + func _ready(): - create_slider_for(\"health\", 0.0, 100.0, 0.1) + _scene_instance.health_slider = create_slider_for(\"health\", 0.0, 100.0, 0.1) " [sub_resource type="GDScript" id=3] script/source = "extends PanelContainer -var health := 100.0 setget set_health +var initial_health := 100.0 +var health := initial_health setget set_health +var health_slider: HSlider onready var label := $Label as Label @@ -24,6 +27,11 @@ func set_health(new_value: float): if not label: yield(self, \"ready\") label.text = \"Health: %s\" % round(health) + + +func reset() -> void: + self.health = initial_health + health_slider.value = initial_health " [node name="Example" type="PanelContainer"] diff --git a/course/lesson-25-creating-dictionaries/visuals/ExampleAddValue.tscn b/course/lesson-25-creating-dictionaries/visuals/ExampleAddValue.tscn index 04c6f1ff..352e1955 100644 --- a/course/lesson-25-creating-dictionaries/visuals/ExampleAddValue.tscn +++ b/course/lesson-25-creating-dictionaries/visuals/ExampleAddValue.tscn @@ -6,9 +6,12 @@ [sub_resource type="GDScript" id=1] script/source = "extends DictInventory +var initial_healing_heart_amount := 3 + + func _ready() -> void: inventory = { - \"healing heart\": 3, + \"healing heart\": initial_healing_heart_amount, \"gems\": 5, \"sword\": 1, } @@ -18,6 +21,11 @@ func _ready() -> void: func run(): add_item(\"healing heart\") update_display() + + +func reset(): + inventory[\"healing heart\"] = initial_healing_heart_amount + update_display() " [node name="Panel" type="PanelContainer"] diff --git a/course/lesson-5-your-first-function/ExampleJumpingTurtle.tscn b/course/lesson-5-your-first-function/ExampleJumpingTurtle.tscn index 028f00e0..c0bea4ea 100644 --- a/course/lesson-5-your-first-function/ExampleJumpingTurtle.tscn +++ b/course/lesson-5-your-first-function/ExampleJumpingTurtle.tscn @@ -18,6 +18,10 @@ func run(): drawing_turtle.jump(-100, 50) drawing_turtle.move_forward(100) drawing_turtle.play_draw_animation() + + +func reset(): + drawing_turtle.reset() " [node name="ExampleJumpingTurtle" type="PanelContainer"] diff --git a/course/lesson-5-your-first-function/ExampleTurtleMoveAndRotate.tscn b/course/lesson-5-your-first-function/ExampleTurtleMoveAndRotate.tscn index 0ccbf744..da2e02b4 100644 --- a/course/lesson-5-your-first-function/ExampleTurtleMoveAndRotate.tscn +++ b/course/lesson-5-your-first-function/ExampleTurtleMoveAndRotate.tscn @@ -5,14 +5,19 @@ [sub_resource type="GDScript" id=1] script/source = "extends Node2D +onready var drawing_turtle = $DrawingTurtle as DrawingTurtle + + func run(): - var drawing_turtle = $DrawingTurtle as DrawingTurtle drawing_turtle.reset() drawing_turtle.position.x = -100 drawing_turtle.move_forward(200) drawing_turtle.turn_right(90) drawing_turtle.play_draw_animation() - + + +func reset(): + drawing_turtle.reset() " [node name="ExampleTurtleMoveAndRotate" type="Node2D"] diff --git a/course/lesson-5-your-first-function/ExampleTurtleSquare.tscn b/course/lesson-5-your-first-function/ExampleTurtleSquare.tscn index 9fe83f87..ec21ff01 100644 --- a/course/lesson-5-your-first-function/ExampleTurtleSquare.tscn +++ b/course/lesson-5-your-first-function/ExampleTurtleSquare.tscn @@ -19,6 +19,10 @@ func run(): _turtle.move_forward(200) _turtle.turn_right(90) _turtle.play_draw_animation() + + +func reset(): + _turtle.reset() " [node name="ExampleTurtleSquare" type="Node2D"] diff --git a/course/lesson-6-multiple-function-parameters/visuals/DemoDrawingSquares.gd b/course/lesson-6-multiple-function-parameters/visuals/DemoDrawingSquares.gd index d969ca9d..77620355 100644 --- a/course/lesson-6-multiple-function-parameters/visuals/DemoDrawingSquares.gd +++ b/course/lesson-6-multiple-function-parameters/visuals/DemoDrawingSquares.gd @@ -4,6 +4,7 @@ var size := 40.0 onready var _turtle: DrawingTurtle = $DrawingTurtle + func run(): _turtle.reset() _turtle.position = Vector2.ZERO @@ -20,3 +21,7 @@ func run(): var rect: Rect2 = _turtle.get_rect() _turtle.position = - rect.size / 2.0 + + +func reset(): + _turtle.reset() diff --git a/course/lesson-9-adding-and-subtracting/visuals/ExampleDamage.tscn b/course/lesson-9-adding-and-subtracting/visuals/ExampleDamage.tscn index 24f3417b..cf82256e 100644 --- a/course/lesson-9-adding-and-subtracting/visuals/ExampleDamage.tscn +++ b/course/lesson-9-adding-and-subtracting/visuals/ExampleDamage.tscn @@ -7,7 +7,8 @@ [sub_resource type="GDScript" id=2] script/source = "extends Node2D -var health := 75 +var initial_health := 75 +var health := initial_health onready var _animation_tree := find_node(\"AnimationTree\") onready var _health_bar := find_node(\"CustomHealthBar\") @@ -22,6 +23,11 @@ func run() -> void: health -= 25 _health_bar.set_health(health) _animation_tree.travel(\"damage\") + + +func reset() -> void: + _health_bar.set_health(initial_health) + health = initial_health " [node name="ExampleDamage" type="PanelContainer"] diff --git a/course/lesson-9-adding-and-subtracting/visuals/ExampleHeal.tscn b/course/lesson-9-adding-and-subtracting/visuals/ExampleHeal.tscn index f199ee12..ab11e274 100644 --- a/course/lesson-9-adding-and-subtracting/visuals/ExampleHeal.tscn +++ b/course/lesson-9-adding-and-subtracting/visuals/ExampleHeal.tscn @@ -7,7 +7,8 @@ [sub_resource type="GDScript" id=2] script/source = "extends Node2D -var health := 75 +var initial_health := 75 +var health := initial_health onready var _animation_tree := find_node(\"AnimationTree\") onready var _health_bar := find_node(\"CustomHealthBar\") @@ -22,6 +23,11 @@ func run() -> void: health += 25 _health_bar.set_health(health) _animation_tree.travel(\"heal\") + + +func reset() -> void: + _health_bar.set_health(initial_health) + health = initial_health " [node name="ExampleHeal" type="PanelContainer"] diff --git a/game_demos/DrawingTurtle.gd b/game_demos/DrawingTurtle.gd index 77073e20..6c4139cd 100644 --- a/game_demos/DrawingTurtle.gd +++ b/game_demos/DrawingTurtle.gd @@ -92,6 +92,7 @@ func jump(x: float, y: float) -> void: func reset() -> void: _command_stack.clear() stop_animation() + _animate_jump(0) rotation_degrees = 0.0 turn_degrees = 0.0 @@ -112,7 +113,7 @@ func get_polygons() -> Array: func stop_animation() -> void: - _tween.stop_all() + _tween.remove_all() for line in _canvas.get_children(): line.stop() diff --git a/ui/components/OutputConsole.gd b/ui/components/OutputConsole.gd index 98412c6e..6ae8aa4c 100644 --- a/ui/components/OutputConsole.gd +++ b/ui/components/OutputConsole.gd @@ -126,3 +126,7 @@ func _on_explain_requested(error_code: int, error_message: String) -> void: func _on_resized() -> void: _error_popup.set_margins_preset(Control.PRESET_WIDE) + + +func reset(): + clear_messages()