Skip to content

Add reset functionality to examples #487

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

Merged
merged 9 commits into from
Jun 2, 2022
Original file line number Diff line number Diff line change
Expand Up @@ -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)
"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
10 changes: 8 additions & 2 deletions course/lesson-14-multiplying/visuals/Graph.gd
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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:
Expand Down Expand Up @@ -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()
Expand Down
10 changes: 9 additions & 1 deletion course/lesson-15-modulo/visuals/TrafficLights.gd
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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"]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
Expand All @@ -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"]
Expand Down
4 changes: 4 additions & 0 deletions course/lesson-5-your-first-function/ExampleJumpingTurtle.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down
4 changes: 4 additions & 0 deletions course/lesson-5-your-first-function/ExampleTurtleSquare.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ var size := 40.0

onready var _turtle: DrawingTurtle = $DrawingTurtle


func run():
_turtle.reset()
_turtle.position = Vector2.ZERO
Expand All @@ -20,3 +21,7 @@ func run():

var rect: Rect2 = _turtle.get_rect()
_turtle.position = - rect.size / 2.0


func reset():
_turtle.reset()
Original file line number Diff line number Diff line change
Expand Up @@ -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\")
Expand All @@ -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"]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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\")
Expand All @@ -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"]
Expand Down
3 changes: 2 additions & 1 deletion game_demos/DrawingTurtle.gd
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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()

Expand Down
4 changes: 4 additions & 0 deletions ui/components/OutputConsole.gd
Original file line number Diff line number Diff line change
Expand Up @@ -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()