From 41852297247f1ae389ff9fb18b7f7aa7f0b24b4b Mon Sep 17 00:00:00 2001 From: Ashir Rashid Date: Mon, 4 Apr 2022 00:27:32 +0500 Subject: [PATCH 1/9] feat: add reset functionality to lesson 5 --- .../ExampleJumpingTurtle.tscn | 4 ++++ .../ExampleTurtleMoveAndRotate.tscn | 9 +++++++-- .../ExampleTurtleSquare.tscn | 4 ++++ .../visuals/DemoDrawingSquares.gd | 5 +++++ game_demos/DrawingTurtle.gd | 1 + 5 files changed, 21 insertions(+), 2 deletions(-) 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/game_demos/DrawingTurtle.gd b/game_demos/DrawingTurtle.gd index 77073e20..eff16348 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 From eb717e2e4c70da6958c9cc433f2f42318a845d13 Mon Sep 17 00:00:00 2001 From: Ashir Rashid Date: Mon, 4 Apr 2022 21:55:11 +0500 Subject: [PATCH 2/9] fix: stopped tween in lesson5(DrawingTurtle in ExampleDrawAnySquare.tscn) caused issues when the tween was run again To Replicate the Bug: Navigate in Lesson 5 to the example in which the turtle draws a square of variable(set by a "Size" slider) length. Click the button labelled "draw_square()". While the animation is running, change the "Size" slider to a new number and click the button labelled "Reset". Click the "draw_square()" button again and let the animation complete. You should be able to spot the bug in the form of the turtle making unexpected and unwanted movements. --- game_demos/DrawingTurtle.gd | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/game_demos/DrawingTurtle.gd b/game_demos/DrawingTurtle.gd index eff16348..6c4139cd 100644 --- a/game_demos/DrawingTurtle.gd +++ b/game_demos/DrawingTurtle.gd @@ -113,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() From 8bedfcea16dad820237c8787f20284b266eb9a77 Mon Sep 17 00:00:00 2001 From: Ashir Rashid Date: Tue, 5 Apr 2022 22:19:44 +0500 Subject: [PATCH 3/9] feat: add reset function to OutputConsole.gd --- ui/components/OutputConsole.gd | 4 ++++ 1 file changed, 4 insertions(+) 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() From 36688d6aba36c09c10e90c9df39ae596fbc6d695 Mon Sep 17 00:00:00 2001 From: Ashir Rashid Date: Tue, 5 Apr 2022 22:52:45 +0500 Subject: [PATCH 4/9] feat: add reset function to lesson9 robot damage and heal examples --- .../visuals/ExampleDamage.tscn | 8 +++++++- .../visuals/ExampleHeal.tscn | 8 +++++++- 2 files changed, 14 insertions(+), 2 deletions(-) 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"] From 2b7ae1db6afa10c762774c0ecc0ed0dc447f4e16 Mon Sep 17 00:00:00 2001 From: Ashir Rashid Date: Tue, 5 Apr 2022 23:25:19 +0500 Subject: [PATCH 5/9] feat: add reset function to lesson10 and lesson11 rotation examples --- .../visuals/ExampleRotatingSprite.tscn | 2 ++ .../visuals/ExampleRotatingWithDelta.tscn | 6 ++++-- 2 files changed, 6 insertions(+), 2 deletions(-) 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) From 2a04bff735572a1d1ec1a295332be57e9fcd6f05 Mon Sep 17 00:00:00 2001 From: Ashir Rashid Date: Tue, 5 Apr 2022 23:39:41 +0500 Subject: [PATCH 6/9] feat: add reset function to lesson14 graphs --- course/lesson-14-multiplying/visuals/Graph.gd | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) 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() From 08c3459027d681e94cfd5ec7a48a1baae76c9c33 Mon Sep 17 00:00:00 2001 From: Ashir Rashid Date: Wed, 6 Apr 2022 12:50:35 +0500 Subject: [PATCH 7/9] feat: reset function for lesson15 traffic light examples --- course/lesson-15-modulo/visuals/TrafficLights.gd | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) 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: From 04cf22b20dd6d14f90b79f97acbd9c0f104f1e26 Mon Sep 17 00:00:00 2001 From: Ashir Rashid Date: Wed, 6 Apr 2022 13:48:23 +0500 Subject: [PATCH 8/9] feat: add reset function to lesson25 inventory example --- .../visuals/ExampleAddValue.tscn | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) 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"] From 8594bdf769731a8d4dfdbc624e930c1b6f01b3b6 Mon Sep 17 00:00:00 2001 From: Ashir Rashid Date: Thu, 7 Apr 2022 23:31:10 +0500 Subject: [PATCH 9/9] feat: add reset function to lesson22 health slider example --- .../visuals/ExampleRoundingHealth.tscn | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) 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"]