From e88cb24581b51b334753e244bceae289a0f14d49 Mon Sep 17 00:00:00 2001 From: johnnygossdev Date: Fri, 24 Dec 2021 18:23:08 +0000 Subject: [PATCH 01/21] content: add draft lesson 10 --- .../content-5AJTESv5.tres | 10 +++++ .../content-DizKUdOC.tres | 16 ++++++++ .../content-QiGjB7tK.tres | 10 +++++ .../content-RHJMQ2XN.tres | 12 ++++++ .../content-TRhZN4rS.tres | 12 ++++++ .../content-ZPxY8VUD.tres | 10 +++++ .../content-otxF5HUx.tres | 10 +++++ .../content-pPwQDwfy.tres | 14 +++++++ .../content-qdYOexRj.tres | 10 +++++ .../content-tT6n1Txl.tres | 12 ++++++ .../content-wQMqAYVj.tres | 10 +++++ course/lesson-10-the-game-loop/lesson.tres | 20 ++++++++++ lesson-10.md | 39 +++++++++++++++++++ 13 files changed, 185 insertions(+) create mode 100644 course/lesson-10-the-game-loop/content-5AJTESv5.tres create mode 100644 course/lesson-10-the-game-loop/content-DizKUdOC.tres create mode 100644 course/lesson-10-the-game-loop/content-QiGjB7tK.tres create mode 100644 course/lesson-10-the-game-loop/content-RHJMQ2XN.tres create mode 100644 course/lesson-10-the-game-loop/content-TRhZN4rS.tres create mode 100644 course/lesson-10-the-game-loop/content-ZPxY8VUD.tres create mode 100644 course/lesson-10-the-game-loop/content-otxF5HUx.tres create mode 100644 course/lesson-10-the-game-loop/content-pPwQDwfy.tres create mode 100644 course/lesson-10-the-game-loop/content-qdYOexRj.tres create mode 100644 course/lesson-10-the-game-loop/content-tT6n1Txl.tres create mode 100644 course/lesson-10-the-game-loop/content-wQMqAYVj.tres create mode 100644 course/lesson-10-the-game-loop/lesson.tres create mode 100644 lesson-10.md diff --git a/course/lesson-10-the-game-loop/content-5AJTESv5.tres b/course/lesson-10-the-game-loop/content-5AJTESv5.tres new file mode 100644 index 000000000..41d0b87af --- /dev/null +++ b/course/lesson-10-the-game-loop/content-5AJTESv5.tres @@ -0,0 +1,10 @@ +[gd_resource type="Resource" load_steps=2 format=2] + +[ext_resource path="res://resources/ContentBlock.gd" type="Script" id=1] + +[resource] +script = ExtResource( 1 ) +text = "[example of sprite rotating animation]" +visual_element_path = "" +reverse_blocks = false +type = 0 diff --git a/course/lesson-10-the-game-loop/content-DizKUdOC.tres b/course/lesson-10-the-game-loop/content-DizKUdOC.tres new file mode 100644 index 000000000..b52f2fd4b --- /dev/null +++ b/course/lesson-10-the-game-loop/content-DizKUdOC.tres @@ -0,0 +1,16 @@ +[gd_resource type="Resource" load_steps=2 format=2] + +[ext_resource path="res://resources/ContentBlock.gd" type="Script" id=1] + +[resource] +script = ExtResource( 1 ) +text = "As we've seen, Godot has functions that do certain actions. For example, the [code]show()[/code] and [code]hide()[/code] functions change the visibility of things. + +We can also create our own functions to make custom effects like adding or removing health to a character. + +Godot also has special functions we can customise or add to. + +Take the [code]_process()[/code] function." +visual_element_path = "" +reverse_blocks = false +type = 0 diff --git a/course/lesson-10-the-game-loop/content-QiGjB7tK.tres b/course/lesson-10-the-game-loop/content-QiGjB7tK.tres new file mode 100644 index 000000000..ae81ed57a --- /dev/null +++ b/course/lesson-10-the-game-loop/content-QiGjB7tK.tres @@ -0,0 +1,10 @@ +[gd_resource type="Resource" load_steps=2 format=2] + +[ext_resource path="res://resources/ContentBlock.gd" type="Script" id=1] + +[resource] +script = ExtResource( 1 ) +text = "[PROCESS FUNCTION]" +visual_element_path = "" +reverse_blocks = false +type = 0 diff --git a/course/lesson-10-the-game-loop/content-RHJMQ2XN.tres b/course/lesson-10-the-game-loop/content-RHJMQ2XN.tres new file mode 100644 index 000000000..d9979b662 --- /dev/null +++ b/course/lesson-10-the-game-loop/content-RHJMQ2XN.tres @@ -0,0 +1,12 @@ +[gd_resource type="Resource" load_steps=2 format=2] + +[ext_resource path="res://resources/ContentBlock.gd" type="Script" id=1] + +[resource] +script = ExtResource( 1 ) +text = "The [code]_process()[/code] function gets its name because it does calculations or continuous actions. + +It's like a factory that [bold]processes[/bold] food; the food is always moving along a conveyer belt." +visual_element_path = "" +reverse_blocks = false +type = 0 diff --git a/course/lesson-10-the-game-loop/content-TRhZN4rS.tres b/course/lesson-10-the-game-loop/content-TRhZN4rS.tres new file mode 100644 index 000000000..277473073 --- /dev/null +++ b/course/lesson-10-the-game-loop/content-TRhZN4rS.tres @@ -0,0 +1,12 @@ +[gd_resource type="Resource" load_steps=2 format=2] + +[ext_resource path="res://resources/ContentBlock.gd" type="Script" id=1] + +[resource] +script = ExtResource( 1 ) +text = "[font=res://ui/theme/fonts/font_title.tres]Why is [code]_process()[/code] useful?[/font] + +It's perhaps better to see the process function in action. Take the following example." +visual_element_path = "" +reverse_blocks = false +type = 0 diff --git a/course/lesson-10-the-game-loop/content-ZPxY8VUD.tres b/course/lesson-10-the-game-loop/content-ZPxY8VUD.tres new file mode 100644 index 000000000..d2606c3b7 --- /dev/null +++ b/course/lesson-10-the-game-loop/content-ZPxY8VUD.tres @@ -0,0 +1,10 @@ +[gd_resource type="Resource" load_steps=2 format=2] + +[ext_resource path="res://resources/ContentBlock.gd" type="Script" id=1] + +[resource] +script = ExtResource( 1 ) +text = "Other game engines might use different names for this like [code]_update()[/code]." +visual_element_path = "" +reverse_blocks = false +type = 2 diff --git a/course/lesson-10-the-game-loop/content-otxF5HUx.tres b/course/lesson-10-the-game-loop/content-otxF5HUx.tres new file mode 100644 index 000000000..5c0a83831 --- /dev/null +++ b/course/lesson-10-the-game-loop/content-otxF5HUx.tres @@ -0,0 +1,10 @@ +[gd_resource type="Resource" load_steps=2 format=2] + +[ext_resource path="res://resources/ContentBlock.gd" type="Script" id=1] + +[resource] +script = ExtResource( 1 ) +text = "It's similar in Godot, but this function can run [bold]hundreds of times a second[/bold]." +visual_element_path = "" +reverse_blocks = false +type = 0 diff --git a/course/lesson-10-the-game-loop/content-pPwQDwfy.tres b/course/lesson-10-the-game-loop/content-pPwQDwfy.tres new file mode 100644 index 000000000..f6050c9ab --- /dev/null +++ b/course/lesson-10-the-game-loop/content-pPwQDwfy.tres @@ -0,0 +1,14 @@ +[gd_resource type="Resource" load_steps=2 format=2] + +[ext_resource path="res://resources/ContentBlock.gd" type="Script" id=1] + +[resource] +script = ExtResource( 1 ) +text = "The [code]_process()[/code] function won't do anything until we add something to it. + +You might notice the underscore in front of the function name. This means the function is built-in to Godot and we can add to it. + +Using an underscore in this way is common in lots of languages to show developers they can add to the function." +visual_element_path = "" +reverse_blocks = false +type = 0 diff --git a/course/lesson-10-the-game-loop/content-qdYOexRj.tres b/course/lesson-10-the-game-loop/content-qdYOexRj.tres new file mode 100644 index 000000000..66941cd62 --- /dev/null +++ b/course/lesson-10-the-game-loop/content-qdYOexRj.tres @@ -0,0 +1,10 @@ +[gd_resource type="Resource" load_steps=2 format=2] + +[ext_resource path="res://resources/ContentBlock.gd" type="Script" id=1] + +[resource] +script = ExtResource( 1 ) +text = "[example \"process\" functions in other languages]" +visual_element_path = "" +reverse_blocks = false +type = 0 diff --git a/course/lesson-10-the-game-loop/content-tT6n1Txl.tres b/course/lesson-10-the-game-loop/content-tT6n1Txl.tres new file mode 100644 index 000000000..5099e1228 --- /dev/null +++ b/course/lesson-10-the-game-loop/content-tT6n1Txl.tres @@ -0,0 +1,12 @@ +[gd_resource type="Resource" load_steps=2 format=2] + +[ext_resource path="res://resources/ContentBlock.gd" type="Script" id=1] + +[resource] +script = ExtResource( 1 ) +text = "We've added to the character's [code]_process[/code] function so that it continuously rotate. + +In the practice, you'll learn how to use the process function to rotate a character yourself." +visual_element_path = "" +reverse_blocks = false +type = 0 diff --git a/course/lesson-10-the-game-loop/content-wQMqAYVj.tres b/course/lesson-10-the-game-loop/content-wQMqAYVj.tres new file mode 100644 index 000000000..6e2e51e2c --- /dev/null +++ b/course/lesson-10-the-game-loop/content-wQMqAYVj.tres @@ -0,0 +1,10 @@ +[gd_resource type="Resource" load_steps=2 format=2] + +[ext_resource path="res://resources/ContentBlock.gd" type="Script" id=1] + +[resource] +script = ExtResource( 1 ) +text = "[Conveyer belt animation]" +visual_element_path = "" +reverse_blocks = false +type = 0 diff --git a/course/lesson-10-the-game-loop/lesson.tres b/course/lesson-10-the-game-loop/lesson.tres new file mode 100644 index 000000000..07c03cdb7 --- /dev/null +++ b/course/lesson-10-the-game-loop/lesson.tres @@ -0,0 +1,20 @@ +[gd_resource type="Resource" load_steps=13 format=2] + +[ext_resource path="res://resources/Lesson.gd" type="Script" id=1] +[ext_resource path="res://course/lesson-10-the-game-loop/content-wQMqAYVj.tres" type="Resource" id=2] +[ext_resource path="res://course/lesson-10-the-game-loop/content-pPwQDwfy.tres" type="Resource" id=3] +[ext_resource path="res://course/lesson-10-the-game-loop/content-TRhZN4rS.tres" type="Resource" id=4] +[ext_resource path="res://course/lesson-10-the-game-loop/content-RHJMQ2XN.tres" type="Resource" id=5] +[ext_resource path="res://course/lesson-10-the-game-loop/content-5AJTESv5.tres" type="Resource" id=6] +[ext_resource path="res://course/lesson-10-the-game-loop/content-otxF5HUx.tres" type="Resource" id=7] +[ext_resource path="res://course/lesson-10-the-game-loop/content-ZPxY8VUD.tres" type="Resource" id=8] +[ext_resource path="res://course/lesson-10-the-game-loop/content-DizKUdOC.tres" type="Resource" id=9] +[ext_resource path="res://course/lesson-10-the-game-loop/content-tT6n1Txl.tres" type="Resource" id=10] +[ext_resource path="res://course/lesson-10-the-game-loop/content-qdYOexRj.tres" type="Resource" id=11] +[ext_resource path="res://course/lesson-10-the-game-loop/content-QiGjB7tK.tres" type="Resource" id=12] + +[resource] +script = ExtResource( 1 ) +title = "The Game Loop" +content_blocks = [ ExtResource( 9 ), ExtResource( 12 ), ExtResource( 5 ), ExtResource( 2 ), ExtResource( 7 ), ExtResource( 8 ), ExtResource( 3 ), ExtResource( 11 ), ExtResource( 4 ), ExtResource( 6 ), ExtResource( 10 ) ] +practices = [ ] diff --git a/lesson-10.md b/lesson-10.md new file mode 100644 index 000000000..f70e15c58 --- /dev/null +++ b/lesson-10.md @@ -0,0 +1,39 @@ +As we've seen, Godot has functions that do certain actions. For example, the `show()` and `hide()` functions change the visibility of things. + +We can also create our own functions to make custom effects like adding or removing health to a character. + +Godot also has special functions we can customise or add to. + +Take the `_process()` function. + +- Show process() code example + +The `_process()` function gets its name because it does calculations or continuous actions. + +It's like a factory that **processes** food; the food is always moving along a conveyer belt. + +- Animation of a conveyer belt + +It's similar in Godot, but this function can run **hundreds of times a second**. + +- Note: Other game engines might use different names for this like update. + +Godot runs this function on its own; we don't have to keep telling Godot to run it. + +The `_process()` function won't do anything until we add something to it. + +You might notice the underscore in front of the function name. This means the function is built-in to Godot and we can add to it. + +Using an underscore in this way is common in lots of languages to show developers they can add to the function. + +- example "process" functions in other languages + +But how and why is the process useful? + +It's perhaps better to see the process function in action. Take the following example. + +- Example of a sprite rotating all of the time continuously. + +We've added to the character's process function so that it continuously rotate. + +In the practice, you'll learn how to use the process function to rotate continuously yourself. \ No newline at end of file From 5a035176c848cd0f1bf41b18023a8eb1e6642b14 Mon Sep 17 00:00:00 2001 From: johnnygossdev Date: Fri, 24 Dec 2021 19:28:55 +0000 Subject: [PATCH 02/21] content: add visuals and quizes --- .../content-5AJTESv5.tres | 4 ++-- .../content-QiGjB7tK.tres | 4 ++-- .../content-RHJMQ2XN.tres | 2 +- .../content-TRhZN4rS.tres | 4 +++- .../content-ZPxY8VUD.tres | 2 +- .../content-bTxYej47.tres | 10 ++++++++ .../content-otxF5HUx.tres | 2 +- .../content-pPwQDwfy.tres | 2 +- .../content-tT6n1Txl.tres | 4 ++-- .../content-wQMqAYVj.tres | 2 +- course/lesson-10-the-game-loop/lesson.tres | 8 ++++--- .../quiz-BnVHARbB.tres | 16 +++++++++++++ .../quiz-MqE82V6j.tres | 16 +++++++++++++ .../visuals/DemoRotatingSprite.gd | 13 +++++++++++ .../visuals/DemoRotatingSprite.tscn | 23 +++++++++++++++++++ .../visuals/ExampleProcessFunction.tscn | 22 ++++++++++++++++++ .../visuals/ExampleRotatingSprite.tscn | 21 +++++++++++++++++ ...ateSprite.tscn => DemoRotatingSprite.tscn} | 0 18 files changed, 140 insertions(+), 15 deletions(-) create mode 100644 course/lesson-10-the-game-loop/content-bTxYej47.tres create mode 100644 course/lesson-10-the-game-loop/quiz-BnVHARbB.tres create mode 100644 course/lesson-10-the-game-loop/quiz-MqE82V6j.tres create mode 100644 course/lesson-10-the-game-loop/visuals/DemoRotatingSprite.gd create mode 100644 course/lesson-10-the-game-loop/visuals/DemoRotatingSprite.tscn create mode 100644 course/lesson-10-the-game-loop/visuals/ExampleProcessFunction.tscn create mode 100644 course/lesson-10-the-game-loop/visuals/ExampleRotatingSprite.tscn rename course/lesson-3-standing-on-shoulders-of-giants/{ExampleRotateSprite.tscn => DemoRotatingSprite.tscn} (100%) diff --git a/course/lesson-10-the-game-loop/content-5AJTESv5.tres b/course/lesson-10-the-game-loop/content-5AJTESv5.tres index 41d0b87af..4d7c9a5ef 100644 --- a/course/lesson-10-the-game-loop/content-5AJTESv5.tres +++ b/course/lesson-10-the-game-loop/content-5AJTESv5.tres @@ -4,7 +4,7 @@ [resource] script = ExtResource( 1 ) -text = "[example of sprite rotating animation]" -visual_element_path = "" +text = "" +visual_element_path = "visuals/ExampleRotatingSprite.tscn" reverse_blocks = false type = 0 diff --git a/course/lesson-10-the-game-loop/content-QiGjB7tK.tres b/course/lesson-10-the-game-loop/content-QiGjB7tK.tres index ae81ed57a..4881cf546 100644 --- a/course/lesson-10-the-game-loop/content-QiGjB7tK.tres +++ b/course/lesson-10-the-game-loop/content-QiGjB7tK.tres @@ -4,7 +4,7 @@ [resource] script = ExtResource( 1 ) -text = "[PROCESS FUNCTION]" -visual_element_path = "" +text = "" +visual_element_path = "res://course/lesson-10-the-game-loop/visuals/ExampleProcessFunction.tscn" reverse_blocks = false type = 0 diff --git a/course/lesson-10-the-game-loop/content-RHJMQ2XN.tres b/course/lesson-10-the-game-loop/content-RHJMQ2XN.tres index d9979b662..b79c5f79c 100644 --- a/course/lesson-10-the-game-loop/content-RHJMQ2XN.tres +++ b/course/lesson-10-the-game-loop/content-RHJMQ2XN.tres @@ -6,7 +6,7 @@ script = ExtResource( 1 ) text = "The [code]_process()[/code] function gets its name because it does calculations or continuous actions. -It's like a factory that [bold]processes[/bold] food; the food is always moving along a conveyer belt." +It's like a factory that [b]processes[/b] food; the food is always moving along a conveyer belt." visual_element_path = "" reverse_blocks = false type = 0 diff --git a/course/lesson-10-the-game-loop/content-TRhZN4rS.tres b/course/lesson-10-the-game-loop/content-TRhZN4rS.tres index 277473073..bd304973d 100644 --- a/course/lesson-10-the-game-loop/content-TRhZN4rS.tres +++ b/course/lesson-10-the-game-loop/content-TRhZN4rS.tres @@ -6,7 +6,9 @@ script = ExtResource( 1 ) text = "[font=res://ui/theme/fonts/font_title.tres]Why is [code]_process()[/code] useful?[/font] -It's perhaps better to see the process function in action. Take the following example." +It's perhaps better to see the [code]_process[/code] function in action. + +Take the following example." visual_element_path = "" reverse_blocks = false type = 0 diff --git a/course/lesson-10-the-game-loop/content-ZPxY8VUD.tres b/course/lesson-10-the-game-loop/content-ZPxY8VUD.tres index d2606c3b7..23f7a459d 100644 --- a/course/lesson-10-the-game-loop/content-ZPxY8VUD.tres +++ b/course/lesson-10-the-game-loop/content-ZPxY8VUD.tres @@ -4,7 +4,7 @@ [resource] script = ExtResource( 1 ) -text = "Other game engines might use different names for this like [code]_update()[/code]." +text = "Other game engines might use different names like [code]_update()[/code]." visual_element_path = "" reverse_blocks = false type = 2 diff --git a/course/lesson-10-the-game-loop/content-bTxYej47.tres b/course/lesson-10-the-game-loop/content-bTxYej47.tres new file mode 100644 index 000000000..298c5bb36 --- /dev/null +++ b/course/lesson-10-the-game-loop/content-bTxYej47.tres @@ -0,0 +1,10 @@ +[gd_resource type="Resource" load_steps=2 format=2] + +[ext_resource path="res://resources/ContentBlock.gd" type="Script" id=1] + +[resource] +script = ExtResource( 1 ) +text = "In the practice, you'll learn how to use the process function to rotate a character yourself." +visual_element_path = "" +reverse_blocks = false +type = 0 diff --git a/course/lesson-10-the-game-loop/content-otxF5HUx.tres b/course/lesson-10-the-game-loop/content-otxF5HUx.tres index 5c0a83831..d7bc2d2d2 100644 --- a/course/lesson-10-the-game-loop/content-otxF5HUx.tres +++ b/course/lesson-10-the-game-loop/content-otxF5HUx.tres @@ -4,7 +4,7 @@ [resource] script = ExtResource( 1 ) -text = "It's similar in Godot, but this function can run [bold]hundreds of times a second[/bold]." +text = "It's similar in Godot, but this function can run [b]hundreds of times a second[/b]." visual_element_path = "" reverse_blocks = false type = 0 diff --git a/course/lesson-10-the-game-loop/content-pPwQDwfy.tres b/course/lesson-10-the-game-loop/content-pPwQDwfy.tres index f6050c9ab..081bbd312 100644 --- a/course/lesson-10-the-game-loop/content-pPwQDwfy.tres +++ b/course/lesson-10-the-game-loop/content-pPwQDwfy.tres @@ -6,7 +6,7 @@ script = ExtResource( 1 ) text = "The [code]_process()[/code] function won't do anything until we add something to it. -You might notice the underscore in front of the function name. This means the function is built-in to Godot and we can add to it. +You might notice the underscore [code]_[/code] in front of the function name. This means the function is built into Godot. Because it's already there, we can add to it. Using an underscore in this way is common in lots of languages to show developers they can add to the function." visual_element_path = "" diff --git a/course/lesson-10-the-game-loop/content-tT6n1Txl.tres b/course/lesson-10-the-game-loop/content-tT6n1Txl.tres index 5099e1228..4c1b5f3bf 100644 --- a/course/lesson-10-the-game-loop/content-tT6n1Txl.tres +++ b/course/lesson-10-the-game-loop/content-tT6n1Txl.tres @@ -4,9 +4,9 @@ [resource] script = ExtResource( 1 ) -text = "We've added to the character's [code]_process[/code] function so that it continuously rotate. +text = "We've added to the character's [code]_process[/code] function so that it continuously rotates. -In the practice, you'll learn how to use the process function to rotate a character yourself." +Godot is rotating the character by [code]0.05[/code] radians [b]many[/b] times a second." visual_element_path = "" reverse_blocks = false type = 0 diff --git a/course/lesson-10-the-game-loop/content-wQMqAYVj.tres b/course/lesson-10-the-game-loop/content-wQMqAYVj.tres index 6e2e51e2c..332215c00 100644 --- a/course/lesson-10-the-game-loop/content-wQMqAYVj.tres +++ b/course/lesson-10-the-game-loop/content-wQMqAYVj.tres @@ -4,7 +4,7 @@ [resource] script = ExtResource( 1 ) -text = "[Conveyer belt animation]" +text = "[Conveyer belt animation?]" visual_element_path = "" reverse_blocks = false type = 0 diff --git a/course/lesson-10-the-game-loop/lesson.tres b/course/lesson-10-the-game-loop/lesson.tres index 07c03cdb7..a85c3e332 100644 --- a/course/lesson-10-the-game-loop/lesson.tres +++ b/course/lesson-10-the-game-loop/lesson.tres @@ -1,4 +1,4 @@ -[gd_resource type="Resource" load_steps=13 format=2] +[gd_resource type="Resource" load_steps=15 format=2] [ext_resource path="res://resources/Lesson.gd" type="Script" id=1] [ext_resource path="res://course/lesson-10-the-game-loop/content-wQMqAYVj.tres" type="Resource" id=2] @@ -10,11 +10,13 @@ [ext_resource path="res://course/lesson-10-the-game-loop/content-ZPxY8VUD.tres" type="Resource" id=8] [ext_resource path="res://course/lesson-10-the-game-loop/content-DizKUdOC.tres" type="Resource" id=9] [ext_resource path="res://course/lesson-10-the-game-loop/content-tT6n1Txl.tres" type="Resource" id=10] -[ext_resource path="res://course/lesson-10-the-game-loop/content-qdYOexRj.tres" type="Resource" id=11] +[ext_resource path="res://course/lesson-10-the-game-loop/quiz-MqE82V6j.tres" type="Resource" id=11] [ext_resource path="res://course/lesson-10-the-game-loop/content-QiGjB7tK.tres" type="Resource" id=12] +[ext_resource path="res://course/lesson-10-the-game-loop/quiz-BnVHARbB.tres" type="Resource" id=13] +[ext_resource path="res://course/lesson-10-the-game-loop/content-bTxYej47.tres" type="Resource" id=14] [resource] script = ExtResource( 1 ) title = "The Game Loop" -content_blocks = [ ExtResource( 9 ), ExtResource( 12 ), ExtResource( 5 ), ExtResource( 2 ), ExtResource( 7 ), ExtResource( 8 ), ExtResource( 3 ), ExtResource( 11 ), ExtResource( 4 ), ExtResource( 6 ), ExtResource( 10 ) ] +content_blocks = [ ExtResource( 9 ), ExtResource( 12 ), ExtResource( 5 ), ExtResource( 2 ), ExtResource( 7 ), ExtResource( 13 ), ExtResource( 3 ), ExtResource( 8 ), ExtResource( 4 ), ExtResource( 6 ), ExtResource( 10 ), ExtResource( 11 ), ExtResource( 14 ) ] practices = [ ] diff --git a/course/lesson-10-the-game-loop/quiz-BnVHARbB.tres b/course/lesson-10-the-game-loop/quiz-BnVHARbB.tres new file mode 100644 index 000000000..74763069e --- /dev/null +++ b/course/lesson-10-the-game-loop/quiz-BnVHARbB.tres @@ -0,0 +1,16 @@ +[gd_resource type="Resource" load_steps=2 format=2] + +[ext_resource path="res://resources/QuizChoice.gd" type="Script" id=1] + +[resource] +script = ExtResource( 1 ) +question = "How many parameters does this function take?" +content_bbcode = "" +hint = "" +explanation_bbcode = "The [code]_process()[/code] function takes one parameter: [code]delta[/code]. + +We'll look at what [code]delta[/code] is in the next lesson, as well as how to use it." +answer_options = [ "1", "2" ] +valid_answers = [ "1" ] +is_multiple_choice = false +do_shuffle_answers = true diff --git a/course/lesson-10-the-game-loop/quiz-MqE82V6j.tres b/course/lesson-10-the-game-loop/quiz-MqE82V6j.tres new file mode 100644 index 000000000..cd7e65124 --- /dev/null +++ b/course/lesson-10-the-game-loop/quiz-MqE82V6j.tres @@ -0,0 +1,16 @@ +[gd_resource type="Resource" load_steps=2 format=2] + +[ext_resource path="res://resources/QuizChoice.gd" type="Script" id=1] + +[resource] +script = ExtResource( 1 ) +question = "How often does the [code]_process[/code] function run?" +content_bbcode = "" +hint = "" +explanation_bbcode = "How many times [code]_process()[/code] runs depends on how fast your computer is. + +Godot will try and run it as many times as it can so any movement or animations are smooth." +answer_options = [ "Once a second.", "Multiple times a second." ] +valid_answers = [ "Multiple times a second." ] +is_multiple_choice = false +do_shuffle_answers = true diff --git a/course/lesson-10-the-game-loop/visuals/DemoRotatingSprite.gd b/course/lesson-10-the-game-loop/visuals/DemoRotatingSprite.gd new file mode 100644 index 000000000..7a9722f2e --- /dev/null +++ b/course/lesson-10-the-game-loop/visuals/DemoRotatingSprite.gd @@ -0,0 +1,13 @@ +extends Node2D + + +func _ready(): + set_process(false) + + +func run(): + set_process(true) + + +func _process(delta : float) -> void: + rotate(0.05) diff --git a/course/lesson-10-the-game-loop/visuals/DemoRotatingSprite.tscn b/course/lesson-10-the-game-loop/visuals/DemoRotatingSprite.tscn new file mode 100644 index 000000000..bf04d748f --- /dev/null +++ b/course/lesson-10-the-game-loop/visuals/DemoRotatingSprite.tscn @@ -0,0 +1,23 @@ +[gd_scene load_steps=4 format=2] + +[ext_resource path="res://course/lesson-10-the-game-loop/visuals/DemoRotatingSprite.gd" type="Script" id=1] +[ext_resource path="res://course/lesson-1-what-code-is-like/first_practice/godot_bottom.png" type="Texture" id=2] +[ext_resource path="res://course/lesson-1-what-code-is-like/first_practice/hand_ice.png" type="Texture" id=3] + +[node name="DemoRotateSprite" type="Node2D"] +script = ExtResource( 1 ) + +[node name="GodotBottom" type="Sprite" parent="."] +position = Vector2( 0, -17 ) +texture = ExtResource( 2 ) + +[node name="HandIce" type="Sprite" parent="."] +position = Vector2( 66, 14 ) +rotation = 0.36894 +texture = ExtResource( 3 ) + +[node name="HandIce2" type="Sprite" parent="."] +position = Vector2( -65, 19 ) +rotation = -0.483649 +texture = ExtResource( 3 ) +flip_h = true diff --git a/course/lesson-10-the-game-loop/visuals/ExampleProcessFunction.tscn b/course/lesson-10-the-game-loop/visuals/ExampleProcessFunction.tscn new file mode 100644 index 000000000..a6566dcc9 --- /dev/null +++ b/course/lesson-10-the-game-loop/visuals/ExampleProcessFunction.tscn @@ -0,0 +1,22 @@ +[gd_scene load_steps=2 format=2] + +[ext_resource path="res://course/common/GDScriptCodeExample.tscn" type="PackedScene" id=1] + +[node name="ExampleProcessFunctionBody" type="PanelContainer"] +margin_right = 288.0 +margin_bottom = 178.0 +rect_min_size = Vector2( 320, 200 ) +__meta__ = { +"_edit_use_anchors_": false +} + +[node name="GDScriptCodeExample" parent="." instance=ExtResource( 1 )] +anchor_right = 0.0 +anchor_bottom = 0.0 +margin_left = 7.0 +margin_top = 7.0 +margin_right = 327.0 +margin_bottom = 207.0 +rect_min_size = Vector2( 320, 200 ) +text = "func _process(delta): + rotate(0.05)" diff --git a/course/lesson-10-the-game-loop/visuals/ExampleRotatingSprite.tscn b/course/lesson-10-the-game-loop/visuals/ExampleRotatingSprite.tscn new file mode 100644 index 000000000..d796bf07b --- /dev/null +++ b/course/lesson-10-the-game-loop/visuals/ExampleRotatingSprite.tscn @@ -0,0 +1,21 @@ +[gd_scene load_steps=3 format=2] + +[ext_resource path="res://ui/components/RunnableCodeExample.tscn" type="PackedScene" id=1] +[ext_resource path="res://course/lesson-10-the-game-loop/visuals/DemoRotatingSprite.tscn" type="PackedScene" id=2] + +[node name="ExampleRotatingSprite" type="PanelContainer"] +margin_right = 1047.0 +margin_bottom = 298.0 +size_flags_horizontal = 3 +__meta__ = { +"_edit_use_anchors_": false +} + +[node name="RunnableCodeExample" parent="." instance=ExtResource( 1 )] +margin_left = 7.0 +margin_top = 7.0 +margin_right = 1040.0 +margin_bottom = 291.0 +scene = ExtResource( 2 ) +gdscript_code = "func _process(delta): + rotate(0.05)" diff --git a/course/lesson-3-standing-on-shoulders-of-giants/ExampleRotateSprite.tscn b/course/lesson-3-standing-on-shoulders-of-giants/DemoRotatingSprite.tscn similarity index 100% rename from course/lesson-3-standing-on-shoulders-of-giants/ExampleRotateSprite.tscn rename to course/lesson-3-standing-on-shoulders-of-giants/DemoRotatingSprite.tscn From fbb3f95b986f3503f1b40ea5ee4849a004e9e943 Mon Sep 17 00:00:00 2001 From: johnnygossdev Date: Mon, 27 Dec 2021 09:49:21 +0000 Subject: [PATCH 03/21] improvement: wording --- course/lesson-10-the-game-loop/content-tT6n1Txl.tres | 2 +- course/lesson-10-the-game-loop/quiz-MqE82V6j.tres | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/course/lesson-10-the-game-loop/content-tT6n1Txl.tres b/course/lesson-10-the-game-loop/content-tT6n1Txl.tres index 4c1b5f3bf..8f0fd4600 100644 --- a/course/lesson-10-the-game-loop/content-tT6n1Txl.tres +++ b/course/lesson-10-the-game-loop/content-tT6n1Txl.tres @@ -4,7 +4,7 @@ [resource] script = ExtResource( 1 ) -text = "We've added to the character's [code]_process[/code] function so that it continuously rotates. +text = "We've added to the character's [code]_process()[/code] function so that it continuously rotates. Godot is rotating the character by [code]0.05[/code] radians [b]many[/b] times a second." visual_element_path = "" diff --git a/course/lesson-10-the-game-loop/quiz-MqE82V6j.tres b/course/lesson-10-the-game-loop/quiz-MqE82V6j.tres index cd7e65124..161e2b521 100644 --- a/course/lesson-10-the-game-loop/quiz-MqE82V6j.tres +++ b/course/lesson-10-the-game-loop/quiz-MqE82V6j.tres @@ -4,12 +4,12 @@ [resource] script = ExtResource( 1 ) -question = "How often does the [code]_process[/code] function run?" +question = "How often does the _process() function run?" content_bbcode = "" hint = "" -explanation_bbcode = "How many times [code]_process()[/code] runs depends on how fast your computer is. +explanation_bbcode = "The faster your computer, the more times [code]_process()[/code] will run. -Godot will try and run it as many times as it can so any movement or animations are smooth." +Godot will try and run [code]_process()[/code] as many times as it can. This makes sure any movement or animations look smooth and fluid." answer_options = [ "Once a second.", "Multiple times a second." ] valid_answers = [ "Multiple times a second." ] is_multiple_choice = false From 51c94be471bd059feaf2b2531a5cda001163fd20 Mon Sep 17 00:00:00 2001 From: johnnygossdev Date: Mon, 27 Dec 2021 09:53:20 +0000 Subject: [PATCH 04/21] improvement: typos --- course/lesson-10-the-game-loop/content-TRhZN4rS.tres | 2 +- course/lesson-10-the-game-loop/quiz-MqE82V6j.tres | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/course/lesson-10-the-game-loop/content-TRhZN4rS.tres b/course/lesson-10-the-game-loop/content-TRhZN4rS.tres index bd304973d..4037d7e08 100644 --- a/course/lesson-10-the-game-loop/content-TRhZN4rS.tres +++ b/course/lesson-10-the-game-loop/content-TRhZN4rS.tres @@ -6,7 +6,7 @@ script = ExtResource( 1 ) text = "[font=res://ui/theme/fonts/font_title.tres]Why is [code]_process()[/code] useful?[/font] -It's perhaps better to see the [code]_process[/code] function in action. +It's perhaps better to see the [code]_process()[/code] function in action. Take the following example." visual_element_path = "" diff --git a/course/lesson-10-the-game-loop/quiz-MqE82V6j.tres b/course/lesson-10-the-game-loop/quiz-MqE82V6j.tres index 161e2b521..fb6c0f57a 100644 --- a/course/lesson-10-the-game-loop/quiz-MqE82V6j.tres +++ b/course/lesson-10-the-game-loop/quiz-MqE82V6j.tres @@ -9,7 +9,7 @@ content_bbcode = "" hint = "" explanation_bbcode = "The faster your computer, the more times [code]_process()[/code] will run. -Godot will try and run [code]_process()[/code] as many times as it can. This makes sure any movement or animations look smooth and fluid." +Godot will try and run [code]_process()[/code] as quickly as it can. This makes sure any movement or animations look smooth and fluid." answer_options = [ "Once a second.", "Multiple times a second." ] valid_answers = [ "Multiple times a second." ] is_multiple_choice = false From 6af070778b27248ce83e9304e48febcb9deb842a Mon Sep 17 00:00:00 2001 From: johnnygossdev Date: Mon, 27 Dec 2021 10:25:51 +0000 Subject: [PATCH 05/21] content: add lesson 10 practice 1 draft --- .../lesson-10-the-game-loop/TestsRotating.gd | 11 +++++++++ .../content-bTxYej47.tres | 2 +- course/lesson-10-the-game-loop/lesson.tres | 5 ++-- .../practice-tKRHJMQ2.tres | 15 ++++++++++++ .../rotate-and-move/RotateAndMoveSprite.gd | 15 ++++++++++++ .../scene/RotateAndMoveSprite.tscn.tres | 9 ++++++++ .../scripts/RotateAndMoveSprite.gd.tres | 22 ++++++++++++++++++ ...teAndMoveSprite.move_and_rotate.slice.tres | 20 ++++++++++++++++ .../rotate-and-move/RotateAndMoveSprite.tscn | 23 +++++++++++++++++++ ...ngSprite.tscn => ExampleRotateSprite.tscn} | 2 +- 10 files changed, 120 insertions(+), 4 deletions(-) create mode 100644 course/lesson-10-the-game-loop/TestsRotating.gd create mode 100644 course/lesson-10-the-game-loop/practice-tKRHJMQ2.tres create mode 100644 course/lesson-10-the-game-loop/rotate-and-move/RotateAndMoveSprite.gd create mode 100644 course/lesson-10-the-game-loop/rotate-and-move/RotateAndMoveSprite.live-editor/scene/RotateAndMoveSprite.tscn.tres create mode 100644 course/lesson-10-the-game-loop/rotate-and-move/RotateAndMoveSprite.live-editor/scripts/RotateAndMoveSprite.gd.tres create mode 100644 course/lesson-10-the-game-loop/rotate-and-move/RotateAndMoveSprite.live-editor/slices/RotateAndMoveSprite.move_and_rotate.slice.tres create mode 100644 course/lesson-10-the-game-loop/rotate-and-move/RotateAndMoveSprite.tscn rename course/lesson-3-standing-on-shoulders-of-giants/{DemoRotatingSprite.tscn => ExampleRotateSprite.tscn} (99%) diff --git a/course/lesson-10-the-game-loop/TestsRotating.gd b/course/lesson-10-the-game-loop/TestsRotating.gd new file mode 100644 index 000000000..17a91a940 --- /dev/null +++ b/course/lesson-10-the-game-loop/TestsRotating.gd @@ -0,0 +1,11 @@ +extends PracticeTester + +const TOLERANCE := 0.05 + +func test_character_is_rotating() -> String: + var node_2d = _scene_root_viewport.get_child(0) + if node_2d.rotation < -TOLERANCE: + return "The robot is turned counter-clockwise! Did you turn it less than 0.5 radians?" + elif node_2d.rotation > TOLERANCE: + return "The robot is turned too far clockwise! Did you turn it more than 0.5 radians?" + return "" diff --git a/course/lesson-10-the-game-loop/content-bTxYej47.tres b/course/lesson-10-the-game-loop/content-bTxYej47.tres index 298c5bb36..ccd8e1a76 100644 --- a/course/lesson-10-the-game-loop/content-bTxYej47.tres +++ b/course/lesson-10-the-game-loop/content-bTxYej47.tres @@ -4,7 +4,7 @@ [resource] script = ExtResource( 1 ) -text = "In the practice, you'll learn how to use the process function to rotate a character yourself." +text = "In the practice, you'll learn how to use the process function to rotate and move a character yourself." visual_element_path = "" reverse_blocks = false type = 0 diff --git a/course/lesson-10-the-game-loop/lesson.tres b/course/lesson-10-the-game-loop/lesson.tres index a85c3e332..b96eca2b9 100644 --- a/course/lesson-10-the-game-loop/lesson.tres +++ b/course/lesson-10-the-game-loop/lesson.tres @@ -1,4 +1,4 @@ -[gd_resource type="Resource" load_steps=15 format=2] +[gd_resource type="Resource" load_steps=16 format=2] [ext_resource path="res://resources/Lesson.gd" type="Script" id=1] [ext_resource path="res://course/lesson-10-the-game-loop/content-wQMqAYVj.tres" type="Resource" id=2] @@ -14,9 +14,10 @@ [ext_resource path="res://course/lesson-10-the-game-loop/content-QiGjB7tK.tres" type="Resource" id=12] [ext_resource path="res://course/lesson-10-the-game-loop/quiz-BnVHARbB.tres" type="Resource" id=13] [ext_resource path="res://course/lesson-10-the-game-loop/content-bTxYej47.tres" type="Resource" id=14] +[ext_resource path="res://course/lesson-10-the-game-loop/practice-tKRHJMQ2.tres" type="Resource" id=15] [resource] script = ExtResource( 1 ) title = "The Game Loop" content_blocks = [ ExtResource( 9 ), ExtResource( 12 ), ExtResource( 5 ), ExtResource( 2 ), ExtResource( 7 ), ExtResource( 13 ), ExtResource( 3 ), ExtResource( 8 ), ExtResource( 4 ), ExtResource( 6 ), ExtResource( 10 ), ExtResource( 11 ), ExtResource( 14 ) ] -practices = [ ] +practices = [ ExtResource( 15 ) ] diff --git a/course/lesson-10-the-game-loop/practice-tKRHJMQ2.tres b/course/lesson-10-the-game-loop/practice-tKRHJMQ2.tres new file mode 100644 index 000000000..a96cd6ca3 --- /dev/null +++ b/course/lesson-10-the-game-loop/practice-tKRHJMQ2.tres @@ -0,0 +1,15 @@ +[gd_resource type="Resource" load_steps=3 format=2] + +[ext_resource path="res://resources/Practice.gd" type="Script" id=1] +[ext_resource path="res://course/Documentation.tres" type="Resource" id=2] + +[resource] +script = ExtResource( 1 ) +title = "Continuous Rotation" +goal = "" +starting_code = "" +hints = PoolStringArray( ) +validator_script_path = "res://course/lesson-10-the-game-loop/TestsRotating.gd" +script_slice_path = "res://course/lesson-10-the-game-loop/rotate-and-move/RotateAndMoveSprite.live-editor/slices/RotateAndMoveSprite.move_and_rotate.slice.tres" +documentation_references = PoolStringArray( ) +documentation_resource = ExtResource( 2 ) diff --git a/course/lesson-10-the-game-loop/rotate-and-move/RotateAndMoveSprite.gd b/course/lesson-10-the-game-loop/rotate-and-move/RotateAndMoveSprite.gd new file mode 100644 index 000000000..791533b8a --- /dev/null +++ b/course/lesson-10-the-game-loop/rotate-and-move/RotateAndMoveSprite.gd @@ -0,0 +1,15 @@ +extends WrappingNode2D + + +func _ready() -> void: + _sprites = [$GodotBottom, $HandIce, $HandIce2] + _bounds = calculate_bounding_rect(_sprites) + set_process(false) + +# EXPORT move_and_rotate +func _process(delta): + rotate(0.05) +# /EXPORT move_and_rotate + +func _run(): + set_process(true) diff --git a/course/lesson-10-the-game-loop/rotate-and-move/RotateAndMoveSprite.live-editor/scene/RotateAndMoveSprite.tscn.tres b/course/lesson-10-the-game-loop/rotate-and-move/RotateAndMoveSprite.live-editor/scene/RotateAndMoveSprite.tscn.tres new file mode 100644 index 000000000..af1883b69 --- /dev/null +++ b/course/lesson-10-the-game-loop/rotate-and-move/RotateAndMoveSprite.live-editor/scene/RotateAndMoveSprite.tscn.tres @@ -0,0 +1,9 @@ +[gd_resource type="Resource" load_steps=3 format=2] + +[ext_resource path="res://course/lesson-10-the-game-loop/rotate-and-move/RotateAndMoveSprite.tscn" type="PackedScene" id=1] +[ext_resource path="res://addons/gdscript-slice-exporter/collections/SceneProperties.gd" type="Script" id=2] + +[resource] +script = ExtResource( 2 ) +scene = ExtResource( 1 ) +viewport_size = Vector2( 1920, 1080 ) diff --git a/course/lesson-10-the-game-loop/rotate-and-move/RotateAndMoveSprite.live-editor/scripts/RotateAndMoveSprite.gd.tres b/course/lesson-10-the-game-loop/rotate-and-move/RotateAndMoveSprite.live-editor/scripts/RotateAndMoveSprite.gd.tres new file mode 100644 index 000000000..239dc2fbc --- /dev/null +++ b/course/lesson-10-the-game-loop/rotate-and-move/RotateAndMoveSprite.live-editor/scripts/RotateAndMoveSprite.gd.tres @@ -0,0 +1,22 @@ +[gd_resource type="Resource" load_steps=3 format=2] + +[ext_resource path="res://course/lesson-10-the-game-loop/rotate-and-move/RotateAndMoveSprite.gd" type="Script" id=1] +[ext_resource path="res://addons/gdscript-slice-exporter/collections/ScriptProperties.gd" type="Script" id=2] + +[resource] +script = ExtResource( 2 ) +nodes_paths = [ NodePath("") ] +script_file = ExtResource( 1 ) +original_script = "extends WrappingNode2D + + +func _ready() -> void: + _sprites = [$GodotBottom, $HandIce, $HandIce2] + _bounds = calculate_bounding_rect(_sprites) + +# EXPORT move_and_rotate +func _process(delta): + rotate(0.05) + move_local_y(1) +# /EXPORT move_and_rotate +" diff --git a/course/lesson-10-the-game-loop/rotate-and-move/RotateAndMoveSprite.live-editor/slices/RotateAndMoveSprite.move_and_rotate.slice.tres b/course/lesson-10-the-game-loop/rotate-and-move/RotateAndMoveSprite.live-editor/slices/RotateAndMoveSprite.move_and_rotate.slice.tres new file mode 100644 index 000000000..970190c33 --- /dev/null +++ b/course/lesson-10-the-game-loop/rotate-and-move/RotateAndMoveSprite.live-editor/slices/RotateAndMoveSprite.move_and_rotate.slice.tres @@ -0,0 +1,20 @@ +[gd_resource type="Resource" load_steps=4 format=2] + +[ext_resource path="res://course/lesson-10-the-game-loop/rotate-and-move/RotateAndMoveSprite.live-editor/scene/RotateAndMoveSprite.tscn.tres" type="Resource" id=1] +[ext_resource path="res://course/lesson-10-the-game-loop/rotate-and-move/RotateAndMoveSprite.live-editor/scripts/RotateAndMoveSprite.gd.tres" type="Resource" id=2] +[ext_resource path="res://addons/gdscript-slice-exporter/collections/SliceProperties.gd" type="Script" id=3] + +[resource] +script = ExtResource( 3 ) +scene_properties = ExtResource( 1 ) +script_properties = ExtResource( 2 ) +leading_spaces = 0 +keyword = "EXPORT" +closing = false +name = "move_and_rotate" +is_full_file = false +start = 7 +end = 11 +lines_before = [ "extends WrappingNode2D", "", "", "func _ready() -> void:", " _sprites = [$GodotBottom, $HandIce, $HandIce2]", " _bounds = calculate_bounding_rect(_sprites)", "" ] +lines_after = [ "" ] +lines_editable = [ "func _process(delta):", " rotate(0.05)", " move_local_y(1)" ] diff --git a/course/lesson-10-the-game-loop/rotate-and-move/RotateAndMoveSprite.tscn b/course/lesson-10-the-game-loop/rotate-and-move/RotateAndMoveSprite.tscn new file mode 100644 index 000000000..e269e6292 --- /dev/null +++ b/course/lesson-10-the-game-loop/rotate-and-move/RotateAndMoveSprite.tscn @@ -0,0 +1,23 @@ +[gd_scene load_steps=4 format=2] + +[ext_resource path="res://course/lesson-1-what-code-is-like/first_practice/godot_bottom.png" type="Texture" id=1] +[ext_resource path="res://course/lesson-1-what-code-is-like/first_practice/hand_ice.png" type="Texture" id=2] +[ext_resource path="res://course/lesson-10-the-game-loop/rotate-and-move/RotateAndMoveSprite.gd" type="Script" id=3] + +[node name="RotateAndMoveSprite" type="Node2D"] +script = ExtResource( 3 ) + +[node name="GodotBottom" type="Sprite" parent="."] +position = Vector2( 0, -17 ) +texture = ExtResource( 1 ) + +[node name="HandIce" type="Sprite" parent="."] +position = Vector2( 66, 14 ) +rotation = 0.36894 +texture = ExtResource( 2 ) + +[node name="HandIce2" type="Sprite" parent="."] +position = Vector2( -65, 19 ) +rotation = -0.483649 +texture = ExtResource( 2 ) +flip_h = true diff --git a/course/lesson-3-standing-on-shoulders-of-giants/DemoRotatingSprite.tscn b/course/lesson-3-standing-on-shoulders-of-giants/ExampleRotateSprite.tscn similarity index 99% rename from course/lesson-3-standing-on-shoulders-of-giants/DemoRotatingSprite.tscn rename to course/lesson-3-standing-on-shoulders-of-giants/ExampleRotateSprite.tscn index 2cf6dd198..6636dc186 100644 --- a/course/lesson-3-standing-on-shoulders-of-giants/DemoRotatingSprite.tscn +++ b/course/lesson-3-standing-on-shoulders-of-giants/ExampleRotateSprite.tscn @@ -24,7 +24,7 @@ __meta__ = { "_edit_use_anchors_": false } -[node name="RunnableCodeExample" parent="." instance=ExtResource( 1 )] +[node name="RunnableCodeExample" parent="." instance=ExtResource( 2 )] margin_left = 7.0 margin_top = 7.0 margin_right = 1040.0 From 513de4234828a483a57965a9b95bcae4f26cb8c6 Mon Sep 17 00:00:00 2001 From: johnnygossdev Date: Mon, 27 Dec 2021 13:31:08 +0000 Subject: [PATCH 06/21] content: add lesson 11 draft --- .../content-1TxlTtcy.tres | 14 +++++++++++ .../content-DGt6fUqb.tres | 20 +++++++++++++++ .../content-DwfyqdYO.tres | 10 ++++++++ .../content-ESv5tT6n.tres | 10 ++++++++ .../content-En91c9ll.tres | 10 ++++++++ .../content-N4rS5AJT.tres | 22 ++++++++++++++++ .../content-TLtZixQO.tres | 18 +++++++++++++ .../content-cSrGQgrV.tres | 10 ++++++++ .../content-exRjTRhZ.tres | 10 ++++++++ .../content-f8B67UJ8.tres | 10 ++++++++ .../content-hcIb5BnV.tres | 10 ++++++++ .../content-qE82V6jG.tres | 12 +++++++++ .../content-vGm22rtQ.tres | 10 ++++++++ course/lesson-11-time-delta/lesson.tres | 25 +++++++++++++++++++ .../lesson-11-time-delta/quiz-HARbBWNb.tres | 17 +++++++++++++ .../lesson-11-time-delta/quiz-PRw9clsF.tres | 14 +++++++++++ .../lesson-11-time-delta/quiz-TxYej47M.tres | 14 +++++++++++ 17 files changed, 236 insertions(+) create mode 100644 course/lesson-11-time-delta/content-1TxlTtcy.tres create mode 100644 course/lesson-11-time-delta/content-DGt6fUqb.tres create mode 100644 course/lesson-11-time-delta/content-DwfyqdYO.tres create mode 100644 course/lesson-11-time-delta/content-ESv5tT6n.tres create mode 100644 course/lesson-11-time-delta/content-En91c9ll.tres create mode 100644 course/lesson-11-time-delta/content-N4rS5AJT.tres create mode 100644 course/lesson-11-time-delta/content-TLtZixQO.tres create mode 100644 course/lesson-11-time-delta/content-cSrGQgrV.tres create mode 100644 course/lesson-11-time-delta/content-exRjTRhZ.tres create mode 100644 course/lesson-11-time-delta/content-f8B67UJ8.tres create mode 100644 course/lesson-11-time-delta/content-hcIb5BnV.tres create mode 100644 course/lesson-11-time-delta/content-qE82V6jG.tres create mode 100644 course/lesson-11-time-delta/content-vGm22rtQ.tres create mode 100644 course/lesson-11-time-delta/lesson.tres create mode 100644 course/lesson-11-time-delta/quiz-HARbBWNb.tres create mode 100644 course/lesson-11-time-delta/quiz-PRw9clsF.tres create mode 100644 course/lesson-11-time-delta/quiz-TxYej47M.tres diff --git a/course/lesson-11-time-delta/content-1TxlTtcy.tres b/course/lesson-11-time-delta/content-1TxlTtcy.tres new file mode 100644 index 000000000..a7788db95 --- /dev/null +++ b/course/lesson-11-time-delta/content-1TxlTtcy.tres @@ -0,0 +1,14 @@ +[gd_resource type="Resource" load_steps=2 format=2] + +[ext_resource path="res://resources/ContentBlock.gd" type="Script" id=1] + +[resource] +script = ExtResource( 1 ) +text = "You may have heard of frames-per-second or FPS. Games often run at 30 or 60 frames-per-second. + +This means that each second, everything in the game is updated 30 or 60 times. + +On powerful computers, it's possible to unlock the frame rate to get hundreds or thousands of frames-per-second." +visual_element_path = "" +reverse_blocks = false +type = 2 diff --git a/course/lesson-11-time-delta/content-DGt6fUqb.tres b/course/lesson-11-time-delta/content-DGt6fUqb.tres new file mode 100644 index 000000000..2f240ce37 --- /dev/null +++ b/course/lesson-11-time-delta/content-DGt6fUqb.tres @@ -0,0 +1,20 @@ +[gd_resource type="Resource" load_steps=2 format=2] + +[ext_resource path="res://resources/ContentBlock.gd" type="Script" id=1] + +[resource] +script = ExtResource( 1 ) +text = "In mathematics, delta is often used to describe a very small change in something. + +We know that Godot runs all the [code]_process()[/code] functions as fast as it can. + +The parameter [code]delta[/code] is how fast in seconds Godot took to complete the previous frame. + +Because lots of different things happen at different times in games, Godot might take longer to complete one frame. + +For example, the player might fire lots of bullets at once, and now Godot has all of these bullets to process! + +This means that [code]delta[/code] also varies." +visual_element_path = "" +reverse_blocks = false +type = 0 diff --git a/course/lesson-11-time-delta/content-DwfyqdYO.tres b/course/lesson-11-time-delta/content-DwfyqdYO.tres new file mode 100644 index 000000000..b10224a6e --- /dev/null +++ b/course/lesson-11-time-delta/content-DwfyqdYO.tres @@ -0,0 +1,10 @@ +[gd_resource type="Resource" load_steps=2 format=2] + +[ext_resource path="res://resources/ContentBlock.gd" type="Script" id=1] + +[resource] +script = ExtResource( 1 ) +text = "We've seen how we can use our character's [code]_process()[/code] function to make it move continuously." +visual_element_path = "" +reverse_blocks = false +type = 0 diff --git a/course/lesson-11-time-delta/content-ESv5tT6n.tres b/course/lesson-11-time-delta/content-ESv5tT6n.tres new file mode 100644 index 000000000..5b3d27ccc --- /dev/null +++ b/course/lesson-11-time-delta/content-ESv5tT6n.tres @@ -0,0 +1,10 @@ +[gd_resource type="Resource" load_steps=2 format=2] + +[ext_resource path="res://resources/ContentBlock.gd" type="Script" id=1] + +[resource] +script = ExtResource( 1 ) +text = "Flip book animation?" +visual_element_path = "" +reverse_blocks = false +type = 0 diff --git a/course/lesson-11-time-delta/content-En91c9ll.tres b/course/lesson-11-time-delta/content-En91c9ll.tres new file mode 100644 index 000000000..f82325f33 --- /dev/null +++ b/course/lesson-11-time-delta/content-En91c9ll.tres @@ -0,0 +1,10 @@ +[gd_resource type="Resource" load_steps=2 format=2] + +[ext_resource path="res://resources/ContentBlock.gd" type="Script" id=1] + +[resource] +script = ExtResource( 1 ) +text = "However, if we use [code]delta[/code] to compensate, we get a smoother animation." +visual_element_path = "" +reverse_blocks = false +type = 0 diff --git a/course/lesson-11-time-delta/content-N4rS5AJT.tres b/course/lesson-11-time-delta/content-N4rS5AJT.tres new file mode 100644 index 000000000..600bd3f42 --- /dev/null +++ b/course/lesson-11-time-delta/content-N4rS5AJT.tres @@ -0,0 +1,22 @@ +[gd_resource type="Resource" load_steps=2 format=2] + +[ext_resource path="res://resources/ContentBlock.gd" type="Script" id=1] + +[resource] +script = ExtResource( 1 ) +text = "But it's not just our character that has a [code]_process()[/code] function; almost everything in the game has a [code]_process()[/code] function! + +Godot runs each [code]_process()[/code] function as fast as it can. + +When Godot has run every [code]_process()[/code] function in the game, it has completed one game loop, or [b]frame[/b]. + +Godot then moves on to the next frame. + +And this can happen many, many times a second! + +This is how we get fluid motion in games. + +In many ways, each frame is like a page in a flip book." +visual_element_path = "" +reverse_blocks = false +type = 0 diff --git a/course/lesson-11-time-delta/content-TLtZixQO.tres b/course/lesson-11-time-delta/content-TLtZixQO.tres new file mode 100644 index 000000000..75be5d200 --- /dev/null +++ b/course/lesson-11-time-delta/content-TLtZixQO.tres @@ -0,0 +1,18 @@ +[gd_resource type="Resource" load_steps=2 format=2] + +[ext_resource path="res://resources/ContentBlock.gd" type="Script" id=1] + +[resource] +script = ExtResource( 1 ) +text = "Rather than jumping the full amount every frame, we rotate the character by part of the value based on the [code]delta[/code]. + +We increase the values because [code]delta[/code] is so small. + +By multiplying the 3 radians by [code]delta[/code], we rotate the character by 3 radians per second. + +We also move the character by 500 pixels per second. + +When we multiply time sensitive values like this, we make them [b]time-dependent[/b] rather than [b]frame-dependent[/b]." +visual_element_path = "" +reverse_blocks = false +type = 0 diff --git a/course/lesson-11-time-delta/content-cSrGQgrV.tres b/course/lesson-11-time-delta/content-cSrGQgrV.tres new file mode 100644 index 000000000..055075638 --- /dev/null +++ b/course/lesson-11-time-delta/content-cSrGQgrV.tres @@ -0,0 +1,10 @@ +[gd_resource type="Resource" load_steps=2 format=2] + +[ext_resource path="res://resources/ContentBlock.gd" type="Script" id=1] + +[resource] +script = ExtResource( 1 ) +text = "In the next practice, we'll use delta to make rotating time-dependant." +visual_element_path = "" +reverse_blocks = false +type = 0 diff --git a/course/lesson-11-time-delta/content-exRjTRhZ.tres b/course/lesson-11-time-delta/content-exRjTRhZ.tres new file mode 100644 index 000000000..a7c21f33e --- /dev/null +++ b/course/lesson-11-time-delta/content-exRjTRhZ.tres @@ -0,0 +1,10 @@ +[gd_resource type="Resource" load_steps=2 format=2] + +[ext_resource path="res://resources/ContentBlock.gd" type="Script" id=1] + +[resource] +script = ExtResource( 1 ) +text = "" +visual_element_path = "res://course/lesson-10-the-game-loop/visuals/ExampleRotatingSprite.tscn" +reverse_blocks = false +type = 0 diff --git a/course/lesson-11-time-delta/content-f8B67UJ8.tres b/course/lesson-11-time-delta/content-f8B67UJ8.tres new file mode 100644 index 000000000..e912e02b1 --- /dev/null +++ b/course/lesson-11-time-delta/content-f8B67UJ8.tres @@ -0,0 +1,10 @@ +[gd_resource type="Resource" load_steps=2 format=2] + +[ext_resource path="res://resources/ContentBlock.gd" type="Script" id=1] + +[resource] +script = ExtResource( 1 ) +text = "[visual]" +visual_element_path = "" +reverse_blocks = false +type = 0 diff --git a/course/lesson-11-time-delta/content-hcIb5BnV.tres b/course/lesson-11-time-delta/content-hcIb5BnV.tres new file mode 100644 index 000000000..3c394e619 --- /dev/null +++ b/course/lesson-11-time-delta/content-hcIb5BnV.tres @@ -0,0 +1,10 @@ +[gd_resource type="Resource" load_steps=2 format=2] + +[ext_resource path="res://resources/ContentBlock.gd" type="Script" id=1] + +[resource] +script = ExtResource( 1 ) +text = "Let's look at the [code]_process()[/code] function in more detail." +visual_element_path = "" +reverse_blocks = false +type = 0 diff --git a/course/lesson-11-time-delta/content-qE82V6jG.tres b/course/lesson-11-time-delta/content-qE82V6jG.tres new file mode 100644 index 000000000..acec25737 --- /dev/null +++ b/course/lesson-11-time-delta/content-qE82V6jG.tres @@ -0,0 +1,12 @@ +[gd_resource type="Resource" load_steps=2 format=2] + +[ext_resource path="res://resources/ContentBlock.gd" type="Script" id=1] + +[resource] +script = ExtResource( 1 ) +text = "What would happen if our computer slows down? + +Without delta, we'd get an irregular animation because the movement is dependent on frames." +visual_element_path = "" +reverse_blocks = false +type = 0 diff --git a/course/lesson-11-time-delta/content-vGm22rtQ.tres b/course/lesson-11-time-delta/content-vGm22rtQ.tres new file mode 100644 index 000000000..e912e02b1 --- /dev/null +++ b/course/lesson-11-time-delta/content-vGm22rtQ.tres @@ -0,0 +1,10 @@ +[gd_resource type="Resource" load_steps=2 format=2] + +[ext_resource path="res://resources/ContentBlock.gd" type="Script" id=1] + +[resource] +script = ExtResource( 1 ) +text = "[visual]" +visual_element_path = "" +reverse_blocks = false +type = 0 diff --git a/course/lesson-11-time-delta/lesson.tres b/course/lesson-11-time-delta/lesson.tres new file mode 100644 index 000000000..2896a2276 --- /dev/null +++ b/course/lesson-11-time-delta/lesson.tres @@ -0,0 +1,25 @@ +[gd_resource type="Resource" load_steps=18 format=2] + +[ext_resource path="res://resources/Lesson.gd" type="Script" id=1] +[ext_resource path="res://course/lesson-11-time-delta/quiz-HARbBWNb.tres" type="Resource" id=2] +[ext_resource path="res://course/lesson-11-time-delta/content-hcIb5BnV.tres" type="Resource" id=3] +[ext_resource path="res://course/lesson-11-time-delta/content-N4rS5AJT.tres" type="Resource" id=4] +[ext_resource path="res://course/lesson-11-time-delta/content-ESv5tT6n.tres" type="Resource" id=5] +[ext_resource path="res://course/lesson-11-time-delta/content-DwfyqdYO.tres" type="Resource" id=6] +[ext_resource path="res://course/lesson-11-time-delta/content-exRjTRhZ.tres" type="Resource" id=7] +[ext_resource path="res://course/lesson-11-time-delta/content-1TxlTtcy.tres" type="Resource" id=8] +[ext_resource path="res://course/lesson-11-time-delta/content-En91c9ll.tres" type="Resource" id=9] +[ext_resource path="res://course/lesson-11-time-delta/quiz-TxYej47M.tres" type="Resource" id=10] +[ext_resource path="res://course/lesson-11-time-delta/content-f8B67UJ8.tres" type="Resource" id=11] +[ext_resource path="res://course/lesson-11-time-delta/content-DGt6fUqb.tres" type="Resource" id=12] +[ext_resource path="res://course/lesson-11-time-delta/content-qE82V6jG.tres" type="Resource" id=13] +[ext_resource path="res://course/lesson-11-time-delta/content-TLtZixQO.tres" type="Resource" id=14] +[ext_resource path="res://course/lesson-11-time-delta/content-vGm22rtQ.tres" type="Resource" id=15] +[ext_resource path="res://course/lesson-11-time-delta/content-cSrGQgrV.tres" type="Resource" id=16] +[ext_resource path="res://course/lesson-11-time-delta/quiz-PRw9clsF.tres" type="Resource" id=17] + +[resource] +script = ExtResource( 1 ) +title = "Time Delta" +content_blocks = [ ExtResource( 6 ), ExtResource( 7 ), ExtResource( 4 ), ExtResource( 5 ), ExtResource( 8 ), ExtResource( 3 ), ExtResource( 2 ), ExtResource( 12 ), ExtResource( 10 ), ExtResource( 13 ), ExtResource( 15 ), ExtResource( 9 ), ExtResource( 11 ), ExtResource( 14 ), ExtResource( 17 ), ExtResource( 16 ) ] +practices = [ ] diff --git a/course/lesson-11-time-delta/quiz-HARbBWNb.tres b/course/lesson-11-time-delta/quiz-HARbBWNb.tres new file mode 100644 index 000000000..592c5d57b --- /dev/null +++ b/course/lesson-11-time-delta/quiz-HARbBWNb.tres @@ -0,0 +1,17 @@ +[gd_resource type="Resource" load_steps=2 format=2] + +[ext_resource path="res://resources/QuizChoice.gd" type="Script" id=1] + +[resource] +script = ExtResource( 1 ) +question = "What parameter does the _process() function take?" +content_bbcode = "[code] +func _process(delta): + rotate(0.05) +[/code]" +hint = "" +explanation_bbcode = "The [code]_process()[/code] function has one parameter named [code]delta[/code]." +answer_options = [ "rotate", "0.05", "delta" ] +valid_answers = [ "delta" ] +is_multiple_choice = false +do_shuffle_answers = true diff --git a/course/lesson-11-time-delta/quiz-PRw9clsF.tres b/course/lesson-11-time-delta/quiz-PRw9clsF.tres new file mode 100644 index 000000000..2f5f89d96 --- /dev/null +++ b/course/lesson-11-time-delta/quiz-PRw9clsF.tres @@ -0,0 +1,14 @@ +[gd_resource type="Resource" load_steps=2 format=2] + +[ext_resource path="res://resources/QuizChoice.gd" type="Script" id=1] + +[resource] +script = ExtResource( 1 ) +question = "What does this mean?" +content_bbcode = "[code] speed * time [/code]" +hint = "" +explanation_bbcode = "" +answer_options = [ "We're multiplying speed by time.", "We're dividing time by speed.", "We're adding speed to time.", "We're subtracting time from speed." ] +valid_answers = [ "We're multiplying speed by time." ] +is_multiple_choice = false +do_shuffle_answers = true diff --git a/course/lesson-11-time-delta/quiz-TxYej47M.tres b/course/lesson-11-time-delta/quiz-TxYej47M.tres new file mode 100644 index 000000000..042112c79 --- /dev/null +++ b/course/lesson-11-time-delta/quiz-TxYej47M.tres @@ -0,0 +1,14 @@ +[gd_resource type="Resource" load_steps=2 format=2] + +[ext_resource path="res://resources/QuizChoice.gd" type="Script" id=1] + +[resource] +script = ExtResource( 1 ) +question = "What do we know about delta?" +content_bbcode = "" +hint = "" +explanation_bbcode = "" +answer_options = [ "It's very small because frames happen many times a second.", "It varies from frame to frame because Godot needs to process more or less each frame.", "It's the time it takes Godot to complete the previous frame in seconds." ] +valid_answers = [ "It's very small because frames happen many times a second.", "It varies from frame to frame because Godot needs to process more or less each frame.", "It's the time it takes Godot to complete the previous frame in seconds." ] +is_multiple_choice = true +do_shuffle_answers = true From 551999b4af400042b6bd42f2342d84dd7003f71c Mon Sep 17 00:00:00 2001 From: johnnygossdev Date: Mon, 27 Dec 2021 16:40:19 +0000 Subject: [PATCH 07/21] content: add lesson 10 practice 1 --- .../lesson-10-the-game-loop/TestsRotating.gd | 11 ------ .../content-QiGjB7tK.tres | 2 +- course/lesson-10-the-game-loop/lesson.tres | 5 ++- .../practice-kGx0c7DD.tres | 15 ++++++++ .../practice-tKRHJMQ2.tres | 15 ++++---- .../quiz-BnVHARbB.tres | 4 ++- .../rotate-and-move/RotateAndMoveSprite.gd | 15 -------- .../scripts/RotateAndMoveSprite.gd.tres | 22 ------------ ...teAndMoveSprite.move_and_rotate.slice.tres | 20 ----------- .../rotate-and-move/RotateAndMoveSprite.tscn | 23 ------------- .../RotateAndMoveSprite.gd | 24 +++++++++++++ .../scene/RotateAndMoveSprite.tscn.tres | 9 +++++ .../scripts/RotateAndMoveSprite.gd.tres | 34 +++++++++++++++++++ .../scripts/RotatingSprite.gd.tres | 34 +++++++++++++++++++ ...teAndMoveSprite.move_and_rotate.slice.tres | 20 +++++++++++ .../RotatingSprite.move_and_rotate.slice.tres | 20 +++++++++++ .../RotateAndMoveSprite.tscn | 26 ++++++++++++++ .../TestsRotatingAndMoving.gd | 19 +++++++++++ .../rotating-sprite/RotatingSprite.gd | 22 ++++++++++++ .../scene/RotatingSprite.tscn.tres} | 2 +- .../scripts/RotatingSprite.gd.tres | 32 +++++++++++++++++ .../RotatingSprite.move_and_rotate.slice.tres | 20 +++++++++++ .../rotating-sprite/RotatingSprite.tscn | 26 ++++++++++++++ .../rotating-sprite/TestsRotating.gd | 13 +++++++ 24 files changed, 330 insertions(+), 103 deletions(-) delete mode 100644 course/lesson-10-the-game-loop/TestsRotating.gd create mode 100644 course/lesson-10-the-game-loop/practice-kGx0c7DD.tres delete mode 100644 course/lesson-10-the-game-loop/rotate-and-move/RotateAndMoveSprite.gd delete mode 100644 course/lesson-10-the-game-loop/rotate-and-move/RotateAndMoveSprite.live-editor/scripts/RotateAndMoveSprite.gd.tres delete mode 100644 course/lesson-10-the-game-loop/rotate-and-move/RotateAndMoveSprite.live-editor/slices/RotateAndMoveSprite.move_and_rotate.slice.tres delete mode 100644 course/lesson-10-the-game-loop/rotate-and-move/RotateAndMoveSprite.tscn create mode 100644 course/lesson-10-the-game-loop/rotating-and-moving/RotateAndMoveSprite.gd create mode 100644 course/lesson-10-the-game-loop/rotating-and-moving/RotateAndMoveSprite.live-editor/scene/RotateAndMoveSprite.tscn.tres create mode 100644 course/lesson-10-the-game-loop/rotating-and-moving/RotateAndMoveSprite.live-editor/scripts/RotateAndMoveSprite.gd.tres create mode 100644 course/lesson-10-the-game-loop/rotating-and-moving/RotateAndMoveSprite.live-editor/scripts/RotatingSprite.gd.tres create mode 100644 course/lesson-10-the-game-loop/rotating-and-moving/RotateAndMoveSprite.live-editor/slices/RotateAndMoveSprite.move_and_rotate.slice.tres create mode 100644 course/lesson-10-the-game-loop/rotating-and-moving/RotateAndMoveSprite.live-editor/slices/RotatingSprite.move_and_rotate.slice.tres create mode 100644 course/lesson-10-the-game-loop/rotating-and-moving/RotateAndMoveSprite.tscn create mode 100644 course/lesson-10-the-game-loop/rotating-and-moving/TestsRotatingAndMoving.gd create mode 100644 course/lesson-10-the-game-loop/rotating-sprite/RotatingSprite.gd rename course/lesson-10-the-game-loop/{rotate-and-move/RotateAndMoveSprite.live-editor/scene/RotateAndMoveSprite.tscn.tres => rotating-sprite/RotatingSprite.live-editor/scene/RotatingSprite.tscn.tres} (67%) create mode 100644 course/lesson-10-the-game-loop/rotating-sprite/RotatingSprite.live-editor/scripts/RotatingSprite.gd.tres create mode 100644 course/lesson-10-the-game-loop/rotating-sprite/RotatingSprite.live-editor/slices/RotatingSprite.move_and_rotate.slice.tres create mode 100644 course/lesson-10-the-game-loop/rotating-sprite/RotatingSprite.tscn create mode 100644 course/lesson-10-the-game-loop/rotating-sprite/TestsRotating.gd diff --git a/course/lesson-10-the-game-loop/TestsRotating.gd b/course/lesson-10-the-game-loop/TestsRotating.gd deleted file mode 100644 index 17a91a940..000000000 --- a/course/lesson-10-the-game-loop/TestsRotating.gd +++ /dev/null @@ -1,11 +0,0 @@ -extends PracticeTester - -const TOLERANCE := 0.05 - -func test_character_is_rotating() -> String: - var node_2d = _scene_root_viewport.get_child(0) - if node_2d.rotation < -TOLERANCE: - return "The robot is turned counter-clockwise! Did you turn it less than 0.5 radians?" - elif node_2d.rotation > TOLERANCE: - return "The robot is turned too far clockwise! Did you turn it more than 0.5 radians?" - return "" diff --git a/course/lesson-10-the-game-loop/content-QiGjB7tK.tres b/course/lesson-10-the-game-loop/content-QiGjB7tK.tres index 4881cf546..34762831f 100644 --- a/course/lesson-10-the-game-loop/content-QiGjB7tK.tres +++ b/course/lesson-10-the-game-loop/content-QiGjB7tK.tres @@ -5,6 +5,6 @@ [resource] script = ExtResource( 1 ) text = "" -visual_element_path = "res://course/lesson-10-the-game-loop/visuals/ExampleProcessFunction.tscn" +visual_element_path = "visuals/ExampleProcessFunction.tscn" reverse_blocks = false type = 0 diff --git a/course/lesson-10-the-game-loop/lesson.tres b/course/lesson-10-the-game-loop/lesson.tres index b96eca2b9..aed502ee0 100644 --- a/course/lesson-10-the-game-loop/lesson.tres +++ b/course/lesson-10-the-game-loop/lesson.tres @@ -1,7 +1,6 @@ -[gd_resource type="Resource" load_steps=16 format=2] +[gd_resource type="Resource" load_steps=15 format=2] [ext_resource path="res://resources/Lesson.gd" type="Script" id=1] -[ext_resource path="res://course/lesson-10-the-game-loop/content-wQMqAYVj.tres" type="Resource" id=2] [ext_resource path="res://course/lesson-10-the-game-loop/content-pPwQDwfy.tres" type="Resource" id=3] [ext_resource path="res://course/lesson-10-the-game-loop/content-TRhZN4rS.tres" type="Resource" id=4] [ext_resource path="res://course/lesson-10-the-game-loop/content-RHJMQ2XN.tres" type="Resource" id=5] @@ -19,5 +18,5 @@ [resource] script = ExtResource( 1 ) title = "The Game Loop" -content_blocks = [ ExtResource( 9 ), ExtResource( 12 ), ExtResource( 5 ), ExtResource( 2 ), ExtResource( 7 ), ExtResource( 13 ), ExtResource( 3 ), ExtResource( 8 ), ExtResource( 4 ), ExtResource( 6 ), ExtResource( 10 ), ExtResource( 11 ), ExtResource( 14 ) ] +content_blocks = [ ExtResource( 9 ), ExtResource( 12 ), ExtResource( 5 ), ExtResource( 7 ), ExtResource( 13 ), ExtResource( 3 ), ExtResource( 8 ), ExtResource( 4 ), ExtResource( 6 ), ExtResource( 10 ), ExtResource( 11 ), ExtResource( 14 ) ] practices = [ ExtResource( 15 ) ] diff --git a/course/lesson-10-the-game-loop/practice-kGx0c7DD.tres b/course/lesson-10-the-game-loop/practice-kGx0c7DD.tres new file mode 100644 index 000000000..42f8de377 --- /dev/null +++ b/course/lesson-10-the-game-loop/practice-kGx0c7DD.tres @@ -0,0 +1,15 @@ +[gd_resource type="Resource" load_steps=3 format=2] + +[ext_resource path="res://resources/Practice.gd" type="Script" id=1] +[ext_resource path="res://course/Documentation.tres" type="Resource" id=2] + +[resource] +script = ExtResource( 1 ) +title = "Rotating and Moving" +goal = "" +starting_code = "" +hints = PoolStringArray( ) +validator_script_path = "rotating-and-moving/TestsRotatingAndMoving.gd" +script_slice_path = "rotating-and-moving/RotateAndMoveSprite.live-editor/slices/RotatingSprite.move_and_rotate.slice.tres" +documentation_references = PoolStringArray( ) +documentation_resource = ExtResource( 2 ) diff --git a/course/lesson-10-the-game-loop/practice-tKRHJMQ2.tres b/course/lesson-10-the-game-loop/practice-tKRHJMQ2.tres index a96cd6ca3..f8681c6fe 100644 --- a/course/lesson-10-the-game-loop/practice-tKRHJMQ2.tres +++ b/course/lesson-10-the-game-loop/practice-tKRHJMQ2.tres @@ -5,11 +5,14 @@ [resource] script = ExtResource( 1 ) -title = "Continuous Rotation" -goal = "" -starting_code = "" -hints = PoolStringArray( ) -validator_script_path = "res://course/lesson-10-the-game-loop/TestsRotating.gd" -script_slice_path = "res://course/lesson-10-the-game-loop/rotate-and-move/RotateAndMoveSprite.live-editor/slices/RotateAndMoveSprite.move_and_rotate.slice.tres" +title = "Rotating a Character Continuously" +goal = "Make the robot rotate slowly by adding to the [code]_process()[/code] function. + +A rotation speed of about 0.05 each frame should do." +starting_code = "func _process(_delta): + pass" +hints = PoolStringArray( "Replace [code]pass[/code] with the [code]rotate()[/code] function." ) +validator_script_path = "res://course/lesson-10-the-game-loop/rotating-sprite/TestsRotating.gd" +script_slice_path = "res://course/lesson-10-the-game-loop/rotating-sprite/RotatingSprite.live-editor/slices/RotatingSprite.move_and_rotate.slice.tres" documentation_references = PoolStringArray( ) documentation_resource = ExtResource( 2 ) diff --git a/course/lesson-10-the-game-loop/quiz-BnVHARbB.tres b/course/lesson-10-the-game-loop/quiz-BnVHARbB.tres index 74763069e..4d38e15a2 100644 --- a/course/lesson-10-the-game-loop/quiz-BnVHARbB.tres +++ b/course/lesson-10-the-game-loop/quiz-BnVHARbB.tres @@ -5,7 +5,9 @@ [resource] script = ExtResource( 1 ) question = "How many parameters does this function take?" -content_bbcode = "" +content_bbcode = "[code] +func _process(delta): +[/code]" hint = "" explanation_bbcode = "The [code]_process()[/code] function takes one parameter: [code]delta[/code]. diff --git a/course/lesson-10-the-game-loop/rotate-and-move/RotateAndMoveSprite.gd b/course/lesson-10-the-game-loop/rotate-and-move/RotateAndMoveSprite.gd deleted file mode 100644 index 791533b8a..000000000 --- a/course/lesson-10-the-game-loop/rotate-and-move/RotateAndMoveSprite.gd +++ /dev/null @@ -1,15 +0,0 @@ -extends WrappingNode2D - - -func _ready() -> void: - _sprites = [$GodotBottom, $HandIce, $HandIce2] - _bounds = calculate_bounding_rect(_sprites) - set_process(false) - -# EXPORT move_and_rotate -func _process(delta): - rotate(0.05) -# /EXPORT move_and_rotate - -func _run(): - set_process(true) diff --git a/course/lesson-10-the-game-loop/rotate-and-move/RotateAndMoveSprite.live-editor/scripts/RotateAndMoveSprite.gd.tres b/course/lesson-10-the-game-loop/rotate-and-move/RotateAndMoveSprite.live-editor/scripts/RotateAndMoveSprite.gd.tres deleted file mode 100644 index 239dc2fbc..000000000 --- a/course/lesson-10-the-game-loop/rotate-and-move/RotateAndMoveSprite.live-editor/scripts/RotateAndMoveSprite.gd.tres +++ /dev/null @@ -1,22 +0,0 @@ -[gd_resource type="Resource" load_steps=3 format=2] - -[ext_resource path="res://course/lesson-10-the-game-loop/rotate-and-move/RotateAndMoveSprite.gd" type="Script" id=1] -[ext_resource path="res://addons/gdscript-slice-exporter/collections/ScriptProperties.gd" type="Script" id=2] - -[resource] -script = ExtResource( 2 ) -nodes_paths = [ NodePath("") ] -script_file = ExtResource( 1 ) -original_script = "extends WrappingNode2D - - -func _ready() -> void: - _sprites = [$GodotBottom, $HandIce, $HandIce2] - _bounds = calculate_bounding_rect(_sprites) - -# EXPORT move_and_rotate -func _process(delta): - rotate(0.05) - move_local_y(1) -# /EXPORT move_and_rotate -" diff --git a/course/lesson-10-the-game-loop/rotate-and-move/RotateAndMoveSprite.live-editor/slices/RotateAndMoveSprite.move_and_rotate.slice.tres b/course/lesson-10-the-game-loop/rotate-and-move/RotateAndMoveSprite.live-editor/slices/RotateAndMoveSprite.move_and_rotate.slice.tres deleted file mode 100644 index 970190c33..000000000 --- a/course/lesson-10-the-game-loop/rotate-and-move/RotateAndMoveSprite.live-editor/slices/RotateAndMoveSprite.move_and_rotate.slice.tres +++ /dev/null @@ -1,20 +0,0 @@ -[gd_resource type="Resource" load_steps=4 format=2] - -[ext_resource path="res://course/lesson-10-the-game-loop/rotate-and-move/RotateAndMoveSprite.live-editor/scene/RotateAndMoveSprite.tscn.tres" type="Resource" id=1] -[ext_resource path="res://course/lesson-10-the-game-loop/rotate-and-move/RotateAndMoveSprite.live-editor/scripts/RotateAndMoveSprite.gd.tres" type="Resource" id=2] -[ext_resource path="res://addons/gdscript-slice-exporter/collections/SliceProperties.gd" type="Script" id=3] - -[resource] -script = ExtResource( 3 ) -scene_properties = ExtResource( 1 ) -script_properties = ExtResource( 2 ) -leading_spaces = 0 -keyword = "EXPORT" -closing = false -name = "move_and_rotate" -is_full_file = false -start = 7 -end = 11 -lines_before = [ "extends WrappingNode2D", "", "", "func _ready() -> void:", " _sprites = [$GodotBottom, $HandIce, $HandIce2]", " _bounds = calculate_bounding_rect(_sprites)", "" ] -lines_after = [ "" ] -lines_editable = [ "func _process(delta):", " rotate(0.05)", " move_local_y(1)" ] diff --git a/course/lesson-10-the-game-loop/rotate-and-move/RotateAndMoveSprite.tscn b/course/lesson-10-the-game-loop/rotate-and-move/RotateAndMoveSprite.tscn deleted file mode 100644 index e269e6292..000000000 --- a/course/lesson-10-the-game-loop/rotate-and-move/RotateAndMoveSprite.tscn +++ /dev/null @@ -1,23 +0,0 @@ -[gd_scene load_steps=4 format=2] - -[ext_resource path="res://course/lesson-1-what-code-is-like/first_practice/godot_bottom.png" type="Texture" id=1] -[ext_resource path="res://course/lesson-1-what-code-is-like/first_practice/hand_ice.png" type="Texture" id=2] -[ext_resource path="res://course/lesson-10-the-game-loop/rotate-and-move/RotateAndMoveSprite.gd" type="Script" id=3] - -[node name="RotateAndMoveSprite" type="Node2D"] -script = ExtResource( 3 ) - -[node name="GodotBottom" type="Sprite" parent="."] -position = Vector2( 0, -17 ) -texture = ExtResource( 1 ) - -[node name="HandIce" type="Sprite" parent="."] -position = Vector2( 66, 14 ) -rotation = 0.36894 -texture = ExtResource( 2 ) - -[node name="HandIce2" type="Sprite" parent="."] -position = Vector2( -65, 19 ) -rotation = -0.483649 -texture = ExtResource( 2 ) -flip_h = true diff --git a/course/lesson-10-the-game-loop/rotating-and-moving/RotateAndMoveSprite.gd b/course/lesson-10-the-game-loop/rotating-and-moving/RotateAndMoveSprite.gd new file mode 100644 index 000000000..673ad6206 --- /dev/null +++ b/course/lesson-10-the-game-loop/rotating-and-moving/RotateAndMoveSprite.gd @@ -0,0 +1,24 @@ +extends Node2D + + +func _ready() -> void: + set_process(false) + + +# EXPORT move_and_rotate +func _process(_delta): + rotate(0.05) + move_local_x(5) +# /EXPORT move_and_rotate + + +func _run() -> void: + reset() + _process(0.0) + set_process(true) + + +func reset() -> void: + rotation = 0.0 + position = Vector2.ZERO + set_process(false) diff --git a/course/lesson-10-the-game-loop/rotating-and-moving/RotateAndMoveSprite.live-editor/scene/RotateAndMoveSprite.tscn.tres b/course/lesson-10-the-game-loop/rotating-and-moving/RotateAndMoveSprite.live-editor/scene/RotateAndMoveSprite.tscn.tres new file mode 100644 index 000000000..3362cbdac --- /dev/null +++ b/course/lesson-10-the-game-loop/rotating-and-moving/RotateAndMoveSprite.live-editor/scene/RotateAndMoveSprite.tscn.tres @@ -0,0 +1,9 @@ +[gd_resource type="Resource" load_steps=3 format=2] + +[ext_resource path="res://course/lesson-10-the-game-loop/rotating-and-moving/RotateAndMoveSprite.tscn" type="PackedScene" id=1] +[ext_resource path="res://addons/gdscript-slice-exporter/collections/SceneProperties.gd" type="Script" id=2] + +[resource] +script = ExtResource( 2 ) +scene = ExtResource( 1 ) +viewport_size = Vector2( 1920, 1080 ) diff --git a/course/lesson-10-the-game-loop/rotating-and-moving/RotateAndMoveSprite.live-editor/scripts/RotateAndMoveSprite.gd.tres b/course/lesson-10-the-game-loop/rotating-and-moving/RotateAndMoveSprite.live-editor/scripts/RotateAndMoveSprite.gd.tres new file mode 100644 index 000000000..a7aeafb31 --- /dev/null +++ b/course/lesson-10-the-game-loop/rotating-and-moving/RotateAndMoveSprite.live-editor/scripts/RotateAndMoveSprite.gd.tres @@ -0,0 +1,34 @@ +[gd_resource type="Resource" load_steps=3 format=2] + +[ext_resource path="res://course/lesson-10-the-game-loop/rotating-and-moving/RotateAndMoveSprite.gd" type="Script" id=1] +[ext_resource path="res://addons/gdscript-slice-exporter/collections/ScriptProperties.gd" type="Script" id=2] + +[resource] +script = ExtResource( 2 ) +nodes_paths = [ NodePath("RotateAndMoveSprite") ] +script_file = ExtResource( 1 ) +original_script = "extends Node2D + + +func _ready() -> void: + set_process(false) + + +# EXPORT move_and_rotate +func _process(_delta): + rotate(0.05) + move_local_x(5) +# /EXPORT move_and_rotate + + +func _run() -> void: + reset() + _process(0.0) + set_process(true) + + +func reset() -> void: + rotation = 0.0 + position = Vector2.ZERO + set_process(false) +" diff --git a/course/lesson-10-the-game-loop/rotating-and-moving/RotateAndMoveSprite.live-editor/scripts/RotatingSprite.gd.tres b/course/lesson-10-the-game-loop/rotating-and-moving/RotateAndMoveSprite.live-editor/scripts/RotatingSprite.gd.tres new file mode 100644 index 000000000..34a8c8053 --- /dev/null +++ b/course/lesson-10-the-game-loop/rotating-and-moving/RotateAndMoveSprite.live-editor/scripts/RotatingSprite.gd.tres @@ -0,0 +1,34 @@ +[gd_resource type="Resource" load_steps=3 format=2] + +[ext_resource path="res://course/lesson-10-the-game-loop/rotating-sprite/RotatingSprite.gd" type="Script" id=1] +[ext_resource path="res://addons/gdscript-slice-exporter/collections/ScriptProperties.gd" type="Script" id=2] + +[resource] +script = ExtResource( 2 ) +nodes_paths = [ NodePath("RotateAndMoveSprite") ] +script_file = ExtResource( 1 ) +original_script = "extends Node2D + + +func _ready() -> void: + set_process(false) + + +# EXPORT move_and_rotate +func _process(_delta): + rotate(0.05) + move_local_x(5) +# /EXPORT move_and_rotate + + +func _run() -> void: + reset() + _process(0.0) + set_process(true) + + +func reset() -> void: + rotation = 0.0 + position = Vector2.ZERO + set_process(false) +" diff --git a/course/lesson-10-the-game-loop/rotating-and-moving/RotateAndMoveSprite.live-editor/slices/RotateAndMoveSprite.move_and_rotate.slice.tres b/course/lesson-10-the-game-loop/rotating-and-moving/RotateAndMoveSprite.live-editor/slices/RotateAndMoveSprite.move_and_rotate.slice.tres new file mode 100644 index 000000000..a51ebb9aa --- /dev/null +++ b/course/lesson-10-the-game-loop/rotating-and-moving/RotateAndMoveSprite.live-editor/slices/RotateAndMoveSprite.move_and_rotate.slice.tres @@ -0,0 +1,20 @@ +[gd_resource type="Resource" load_steps=4 format=2] + +[ext_resource path="res://course/lesson-10-the-game-loop/rotating-and-moving/RotateAndMoveSprite.live-editor/scene/RotateAndMoveSprite.tscn.tres" type="Resource" id=1] +[ext_resource path="res://course/lesson-10-the-game-loop/rotating-and-moving/RotateAndMoveSprite.live-editor/scripts/RotateAndMoveSprite.gd.tres" type="Resource" id=2] +[ext_resource path="res://addons/gdscript-slice-exporter/collections/SliceProperties.gd" type="Script" id=3] + +[resource] +script = ExtResource( 3 ) +scene_properties = ExtResource( 1 ) +script_properties = ExtResource( 2 ) +leading_spaces = 0 +keyword = "EXPORT" +closing = false +name = "move_and_rotate" +is_full_file = false +start = 7 +end = 11 +lines_before = [ "extends Node2D", "", "", "func _ready() -> void:", " set_process(false)", "", "" ] +lines_after = [ "", "", "func _run() -> void:", " reset()", " _process(0.0)", " set_process(true)", "", "", "func reset() -> void:", " rotation = 0.0", " position = Vector2.ZERO", " set_process(false)", "" ] +lines_editable = [ "func _process(_delta):", " rotate(0.05)", " move_local_x(5)" ] diff --git a/course/lesson-10-the-game-loop/rotating-and-moving/RotateAndMoveSprite.live-editor/slices/RotatingSprite.move_and_rotate.slice.tres b/course/lesson-10-the-game-loop/rotating-and-moving/RotateAndMoveSprite.live-editor/slices/RotatingSprite.move_and_rotate.slice.tres new file mode 100644 index 000000000..f72f61569 --- /dev/null +++ b/course/lesson-10-the-game-loop/rotating-and-moving/RotateAndMoveSprite.live-editor/slices/RotatingSprite.move_and_rotate.slice.tres @@ -0,0 +1,20 @@ +[gd_resource type="Resource" load_steps=4 format=2] + +[ext_resource path="res://course/lesson-10-the-game-loop/rotating-and-moving/RotateAndMoveSprite.live-editor/scene/RotateAndMoveSprite.tscn.tres" type="Resource" id=1] +[ext_resource path="res://course/lesson-10-the-game-loop/rotating-and-moving/RotateAndMoveSprite.live-editor/scripts/RotatingSprite.gd.tres" type="Resource" id=2] +[ext_resource path="res://addons/gdscript-slice-exporter/collections/SliceProperties.gd" type="Script" id=3] + +[resource] +script = ExtResource( 3 ) +scene_properties = ExtResource( 1 ) +script_properties = ExtResource( 2 ) +leading_spaces = 0 +keyword = "EXPORT" +closing = false +name = "move_and_rotate" +is_full_file = false +start = 7 +end = 11 +lines_before = [ "extends Node2D", "", "", "func _ready() -> void:", " set_process(false)", "", "" ] +lines_after = [ "", "", "func _run() -> void:", " reset()", " _process(0.0)", " set_process(true)", "", "", "func reset() -> void:", " rotation = 0.0", " position = Vector2.ZERO", " set_process(false)", "" ] +lines_editable = [ "func _process(_delta):", " rotate(0.05)", " move_local_x(5)" ] diff --git a/course/lesson-10-the-game-loop/rotating-and-moving/RotateAndMoveSprite.tscn b/course/lesson-10-the-game-loop/rotating-and-moving/RotateAndMoveSprite.tscn new file mode 100644 index 000000000..36641db70 --- /dev/null +++ b/course/lesson-10-the-game-loop/rotating-and-moving/RotateAndMoveSprite.tscn @@ -0,0 +1,26 @@ +[gd_scene load_steps=4 format=2] + +[ext_resource path="res://course/lesson-10-the-game-loop/rotating-and-moving/RotateAndMoveSprite.gd" type="Script" id=1] +[ext_resource path="res://course/lesson-1-what-code-is-like/first_practice/hand_ice.png" type="Texture" id=2] +[ext_resource path="res://course/lesson-1-what-code-is-like/first_practice/godot_bottom.png" type="Texture" id=3] + +[node name="Position2D" type="Position2D"] + +[node name="RotateAndMoveSprite" type="Node2D" parent="."] +position = Vector2( 300, 300 ) +script = ExtResource( 1 ) + +[node name="GodotBottom" type="Sprite" parent="RotateAndMoveSprite"] +position = Vector2( 0, -17 ) +texture = ExtResource( 3 ) + +[node name="HandIce" type="Sprite" parent="RotateAndMoveSprite"] +position = Vector2( 66, 14 ) +rotation = 0.36894 +texture = ExtResource( 2 ) + +[node name="HandIce2" type="Sprite" parent="RotateAndMoveSprite"] +position = Vector2( -65, 19 ) +rotation = -0.483649 +texture = ExtResource( 2 ) +flip_h = true diff --git a/course/lesson-10-the-game-loop/rotating-and-moving/TestsRotatingAndMoving.gd b/course/lesson-10-the-game-loop/rotating-and-moving/TestsRotatingAndMoving.gd new file mode 100644 index 000000000..a9249a774 --- /dev/null +++ b/course/lesson-10-the-game-loop/rotating-and-moving/TestsRotatingAndMoving.gd @@ -0,0 +1,19 @@ +extends PracticeTester + + +func test_character_is_rotating_slowly() -> String: + var node_2d = _scene_root_viewport.get_child(0).get_child(0) + var node_rotation = node_2d.rotation + var node_position := node_2d.position as Vector2 + var test = node_position - Vector2(4.994, 0.25) + if node_rotation < 0.0: + return "The robot is turning in the wrong direction!" + elif node_rotation > 0.06: + return "The robot is turning too fast!" + elif not is_equal_approx(node_rotation, 0.05): + return "The robot's rotation speed isn't right." + + + elif not test.is_equal_approx(Vector2.ZERO): + return "false" + return "" diff --git a/course/lesson-10-the-game-loop/rotating-sprite/RotatingSprite.gd b/course/lesson-10-the-game-loop/rotating-sprite/RotatingSprite.gd new file mode 100644 index 000000000..60a2fcd6c --- /dev/null +++ b/course/lesson-10-the-game-loop/rotating-sprite/RotatingSprite.gd @@ -0,0 +1,22 @@ +extends Node2D + + +func _ready() -> void: + set_process(false) + + +# EXPORT move_and_rotate +func _process(_delta): + rotate(0.05) +# /EXPORT move_and_rotate + + +func _run() -> void: + reset() + _process(0.0) + set_process(true) + + +func reset() -> void: + rotation = 0.0 + set_process(false) diff --git a/course/lesson-10-the-game-loop/rotate-and-move/RotateAndMoveSprite.live-editor/scene/RotateAndMoveSprite.tscn.tres b/course/lesson-10-the-game-loop/rotating-sprite/RotatingSprite.live-editor/scene/RotatingSprite.tscn.tres similarity index 67% rename from course/lesson-10-the-game-loop/rotate-and-move/RotateAndMoveSprite.live-editor/scene/RotateAndMoveSprite.tscn.tres rename to course/lesson-10-the-game-loop/rotating-sprite/RotatingSprite.live-editor/scene/RotatingSprite.tscn.tres index af1883b69..26ffaf340 100644 --- a/course/lesson-10-the-game-loop/rotate-and-move/RotateAndMoveSprite.live-editor/scene/RotateAndMoveSprite.tscn.tres +++ b/course/lesson-10-the-game-loop/rotating-sprite/RotatingSprite.live-editor/scene/RotatingSprite.tscn.tres @@ -1,6 +1,6 @@ [gd_resource type="Resource" load_steps=3 format=2] -[ext_resource path="res://course/lesson-10-the-game-loop/rotate-and-move/RotateAndMoveSprite.tscn" type="PackedScene" id=1] +[ext_resource path="res://course/lesson-10-the-game-loop/rotating-sprite/RotatingSprite.tscn" type="PackedScene" id=1] [ext_resource path="res://addons/gdscript-slice-exporter/collections/SceneProperties.gd" type="Script" id=2] [resource] diff --git a/course/lesson-10-the-game-loop/rotating-sprite/RotatingSprite.live-editor/scripts/RotatingSprite.gd.tres b/course/lesson-10-the-game-loop/rotating-sprite/RotatingSprite.live-editor/scripts/RotatingSprite.gd.tres new file mode 100644 index 000000000..b676e9425 --- /dev/null +++ b/course/lesson-10-the-game-loop/rotating-sprite/RotatingSprite.live-editor/scripts/RotatingSprite.gd.tres @@ -0,0 +1,32 @@ +[gd_resource type="Resource" load_steps=3 format=2] + +[ext_resource path="res://course/lesson-10-the-game-loop/rotating-sprite/RotatingSprite.gd" type="Script" id=1] +[ext_resource path="res://addons/gdscript-slice-exporter/collections/ScriptProperties.gd" type="Script" id=2] + +[resource] +script = ExtResource( 2 ) +nodes_paths = [ NodePath("RotatingSprite") ] +script_file = ExtResource( 1 ) +original_script = "extends Node2D + + +func _ready() -> void: + set_process(false) + + +# EXPORT move_and_rotate +func _process(_delta): + rotate(0.05) +# /EXPORT move_and_rotate + + +func _run() -> void: + reset() + _process(0.0) + set_process(true) + + +func reset() -> void: + rotation = 0.0 + set_process(false) +" diff --git a/course/lesson-10-the-game-loop/rotating-sprite/RotatingSprite.live-editor/slices/RotatingSprite.move_and_rotate.slice.tres b/course/lesson-10-the-game-loop/rotating-sprite/RotatingSprite.live-editor/slices/RotatingSprite.move_and_rotate.slice.tres new file mode 100644 index 000000000..decc675e5 --- /dev/null +++ b/course/lesson-10-the-game-loop/rotating-sprite/RotatingSprite.live-editor/slices/RotatingSprite.move_and_rotate.slice.tres @@ -0,0 +1,20 @@ +[gd_resource type="Resource" load_steps=4 format=2] + +[ext_resource path="res://course/lesson-10-the-game-loop/rotating-sprite/RotatingSprite.live-editor/scene/RotatingSprite.tscn.tres" type="Resource" id=1] +[ext_resource path="res://course/lesson-10-the-game-loop/rotating-sprite/RotatingSprite.live-editor/scripts/RotatingSprite.gd.tres" type="Resource" id=2] +[ext_resource path="res://addons/gdscript-slice-exporter/collections/SliceProperties.gd" type="Script" id=3] + +[resource] +script = ExtResource( 3 ) +scene_properties = ExtResource( 1 ) +script_properties = ExtResource( 2 ) +leading_spaces = 0 +keyword = "EXPORT" +closing = false +name = "move_and_rotate" +is_full_file = false +start = 7 +end = 10 +lines_before = [ "extends Node2D", "", "", "func _ready() -> void:", " set_process(false)", "", "" ] +lines_after = [ "", "", "func _run() -> void:", " reset()", " _process(0.0)", " set_process(true)", "", "", "func reset() -> void:", " rotation = 0.0", " set_process(false)", "" ] +lines_editable = [ "func _process(_delta):", " rotate(0.05)" ] diff --git a/course/lesson-10-the-game-loop/rotating-sprite/RotatingSprite.tscn b/course/lesson-10-the-game-loop/rotating-sprite/RotatingSprite.tscn new file mode 100644 index 000000000..a808fa734 --- /dev/null +++ b/course/lesson-10-the-game-loop/rotating-sprite/RotatingSprite.tscn @@ -0,0 +1,26 @@ +[gd_scene load_steps=4 format=2] + +[ext_resource path="res://course/lesson-10-the-game-loop/rotating-sprite/RotatingSprite.gd" type="Script" id=1] +[ext_resource path="res://course/lesson-1-what-code-is-like/first_practice/hand_ice.png" type="Texture" id=2] +[ext_resource path="res://course/lesson-1-what-code-is-like/first_practice/godot_bottom.png" type="Texture" id=3] + +[node name="Position2D" type="Position2D"] + +[node name="RotatingSprite" type="Node2D" parent="."] +position = Vector2( 300, 300 ) +script = ExtResource( 1 ) + +[node name="GodotBottom" type="Sprite" parent="RotatingSprite"] +position = Vector2( 0, -17 ) +texture = ExtResource( 3 ) + +[node name="HandIce" type="Sprite" parent="RotatingSprite"] +position = Vector2( 66, 14 ) +rotation = 0.36894 +texture = ExtResource( 2 ) + +[node name="HandIce2" type="Sprite" parent="RotatingSprite"] +position = Vector2( -65, 19 ) +rotation = -0.483649 +texture = ExtResource( 2 ) +flip_h = true diff --git a/course/lesson-10-the-game-loop/rotating-sprite/TestsRotating.gd b/course/lesson-10-the-game-loop/rotating-sprite/TestsRotating.gd new file mode 100644 index 000000000..6e4544088 --- /dev/null +++ b/course/lesson-10-the-game-loop/rotating-sprite/TestsRotating.gd @@ -0,0 +1,13 @@ +extends PracticeTester + + +func test_character_is_rotating_slowly() -> String: + var node_2d = _scene_root_viewport.get_child(0).get_child(0) + var node_rotation = node_2d.rotation + if node_rotation < 0.0: + return "The robot is turning in the wrong direction!" + elif node_rotation > 0.06: + return "The robot is turning too fast!" + elif not is_equal_approx(node_rotation, 0.05): + return "The robot's rotation speed isn't right." + return "" From 4d7598fcfb581bf50cfdec1eb2b816c96fc12a4a Mon Sep 17 00:00:00 2001 From: johnnygossdev Date: Mon, 27 Dec 2021 16:50:36 +0000 Subject: [PATCH 08/21] improvement: tidy up lesson 11 --- course/lesson-11-time-delta/content-DGt6fUqb.tres | 4 ++-- course/lesson-11-time-delta/content-TLtZixQO.tres | 4 +--- course/lesson-11-time-delta/content-qE82V6jG.tres | 2 +- course/lesson-11-time-delta/lesson.tres | 5 ++--- course/lesson-11-time-delta/quiz-PRw9clsF.tres | 2 +- course/lesson-11-time-delta/quiz-TxYej47M.tres | 10 +++++++--- 6 files changed, 14 insertions(+), 13 deletions(-) diff --git a/course/lesson-11-time-delta/content-DGt6fUqb.tres b/course/lesson-11-time-delta/content-DGt6fUqb.tres index 2f240ce37..aac26a0fc 100644 --- a/course/lesson-11-time-delta/content-DGt6fUqb.tres +++ b/course/lesson-11-time-delta/content-DGt6fUqb.tres @@ -8,9 +8,9 @@ text = "In mathematics, delta is often used to describe a very small change in s We know that Godot runs all the [code]_process()[/code] functions as fast as it can. -The parameter [code]delta[/code] is how fast in seconds Godot took to complete the previous frame. +The parameter [code]delta[/code] is how fast in seconds Godot took to complete the [b]previous frame[/b]. -Because lots of different things happen at different times in games, Godot might take longer to complete one frame. +Because lots of different things happen at different times in games, Godot might take more or less time to complete one frame. For example, the player might fire lots of bullets at once, and now Godot has all of these bullets to process! diff --git a/course/lesson-11-time-delta/content-TLtZixQO.tres b/course/lesson-11-time-delta/content-TLtZixQO.tres index 75be5d200..90bb192f5 100644 --- a/course/lesson-11-time-delta/content-TLtZixQO.tres +++ b/course/lesson-11-time-delta/content-TLtZixQO.tres @@ -6,12 +6,10 @@ script = ExtResource( 1 ) text = "Rather than jumping the full amount every frame, we rotate the character by part of the value based on the [code]delta[/code]. -We increase the values because [code]delta[/code] is so small. +These values are bigger because [code]delta[/code] is so small. By multiplying the 3 radians by [code]delta[/code], we rotate the character by 3 radians per second. -We also move the character by 500 pixels per second. - When we multiply time sensitive values like this, we make them [b]time-dependent[/b] rather than [b]frame-dependent[/b]." visual_element_path = "" reverse_blocks = false diff --git a/course/lesson-11-time-delta/content-qE82V6jG.tres b/course/lesson-11-time-delta/content-qE82V6jG.tres index acec25737..55a798269 100644 --- a/course/lesson-11-time-delta/content-qE82V6jG.tres +++ b/course/lesson-11-time-delta/content-qE82V6jG.tres @@ -6,7 +6,7 @@ script = ExtResource( 1 ) text = "What would happen if our computer slows down? -Without delta, we'd get an irregular animation because the movement is dependent on frames." +Without [code]delta[/code], we'd get an irregular animation because the movement is dependent on frames." visual_element_path = "" reverse_blocks = false type = 0 diff --git a/course/lesson-11-time-delta/lesson.tres b/course/lesson-11-time-delta/lesson.tres index 2896a2276..9afa8eb62 100644 --- a/course/lesson-11-time-delta/lesson.tres +++ b/course/lesson-11-time-delta/lesson.tres @@ -1,10 +1,9 @@ -[gd_resource type="Resource" load_steps=18 format=2] +[gd_resource type="Resource" load_steps=17 format=2] [ext_resource path="res://resources/Lesson.gd" type="Script" id=1] [ext_resource path="res://course/lesson-11-time-delta/quiz-HARbBWNb.tres" type="Resource" id=2] [ext_resource path="res://course/lesson-11-time-delta/content-hcIb5BnV.tres" type="Resource" id=3] [ext_resource path="res://course/lesson-11-time-delta/content-N4rS5AJT.tres" type="Resource" id=4] -[ext_resource path="res://course/lesson-11-time-delta/content-ESv5tT6n.tres" type="Resource" id=5] [ext_resource path="res://course/lesson-11-time-delta/content-DwfyqdYO.tres" type="Resource" id=6] [ext_resource path="res://course/lesson-11-time-delta/content-exRjTRhZ.tres" type="Resource" id=7] [ext_resource path="res://course/lesson-11-time-delta/content-1TxlTtcy.tres" type="Resource" id=8] @@ -21,5 +20,5 @@ [resource] script = ExtResource( 1 ) title = "Time Delta" -content_blocks = [ ExtResource( 6 ), ExtResource( 7 ), ExtResource( 4 ), ExtResource( 5 ), ExtResource( 8 ), ExtResource( 3 ), ExtResource( 2 ), ExtResource( 12 ), ExtResource( 10 ), ExtResource( 13 ), ExtResource( 15 ), ExtResource( 9 ), ExtResource( 11 ), ExtResource( 14 ), ExtResource( 17 ), ExtResource( 16 ) ] +content_blocks = [ ExtResource( 6 ), ExtResource( 7 ), ExtResource( 4 ), ExtResource( 8 ), ExtResource( 3 ), ExtResource( 2 ), ExtResource( 12 ), ExtResource( 10 ), ExtResource( 13 ), ExtResource( 15 ), ExtResource( 9 ), ExtResource( 11 ), ExtResource( 14 ), ExtResource( 17 ), ExtResource( 16 ) ] practices = [ ] diff --git a/course/lesson-11-time-delta/quiz-PRw9clsF.tres b/course/lesson-11-time-delta/quiz-PRw9clsF.tres index 2f5f89d96..e8b90c762 100644 --- a/course/lesson-11-time-delta/quiz-PRw9clsF.tres +++ b/course/lesson-11-time-delta/quiz-PRw9clsF.tres @@ -7,7 +7,7 @@ script = ExtResource( 1 ) question = "What does this mean?" content_bbcode = "[code] speed * time [/code]" hint = "" -explanation_bbcode = "" +explanation_bbcode = "The [code]*[/code] symbol means we're multiplying [code]speed[/code] by [code]time[/code]." answer_options = [ "We're multiplying speed by time.", "We're dividing time by speed.", "We're adding speed to time.", "We're subtracting time from speed." ] valid_answers = [ "We're multiplying speed by time." ] is_multiple_choice = false diff --git a/course/lesson-11-time-delta/quiz-TxYej47M.tres b/course/lesson-11-time-delta/quiz-TxYej47M.tres index 042112c79..35b251112 100644 --- a/course/lesson-11-time-delta/quiz-TxYej47M.tres +++ b/course/lesson-11-time-delta/quiz-TxYej47M.tres @@ -7,8 +7,12 @@ script = ExtResource( 1 ) question = "What do we know about delta?" content_bbcode = "" hint = "" -explanation_bbcode = "" -answer_options = [ "It's very small because frames happen many times a second.", "It varies from frame to frame because Godot needs to process more or less each frame.", "It's the time it takes Godot to complete the previous frame in seconds." ] -valid_answers = [ "It's very small because frames happen many times a second.", "It varies from frame to frame because Godot needs to process more or less each frame.", "It's the time it takes Godot to complete the previous frame in seconds." ] +explanation_bbcode = "[code]delta[/code] is the time it takes Godot to complete the previous frame in seconds. + +It's very small because frames happen many times a second. + +It varies each frame because Godot needs to process more or less each frame." +answer_options = [ "It's very small because frames happen many times a second.", "It varies each frame.", "It's the time it takes Godot to complete the previous frame." ] +valid_answers = [ "It's very small because frames happen many times a second.", "It varies each frame.", "It's the time it takes Godot to complete the previous frame." ] is_multiple_choice = true do_shuffle_answers = true From 76aca5bd949736465c49e4559a75134f1b2016c8 Mon Sep 17 00:00:00 2001 From: johnnygossdev Date: Mon, 27 Dec 2021 17:38:27 +0000 Subject: [PATCH 09/21] content: add lesson 11 visuals --- .../content-f8B67UJ8.tres | 4 +-- .../content-qE82V6jG.tres | 2 +- .../content-vGm22rtQ.tres | 4 +-- .../visuals/DemoRotatingSpriteFrame.gd | 14 +++++++++ .../visuals/DemoRotatingSpriteFrame.tscn | 31 +++++++++++++++++++ .../visuals/DemoRotatingTime.gd | 14 +++++++++ .../visuals/DemoRotatingTime.tscn | 31 +++++++++++++++++++ .../visuals/ExampleRotatingSpriteFrame.tscn | 21 +++++++++++++ .../visuals/ExampleRotatingSpriteTime.tscn | 21 +++++++++++++ 9 files changed, 137 insertions(+), 5 deletions(-) create mode 100644 course/lesson-11-time-delta/visuals/DemoRotatingSpriteFrame.gd create mode 100644 course/lesson-11-time-delta/visuals/DemoRotatingSpriteFrame.tscn create mode 100644 course/lesson-11-time-delta/visuals/DemoRotatingTime.gd create mode 100644 course/lesson-11-time-delta/visuals/DemoRotatingTime.tscn create mode 100644 course/lesson-11-time-delta/visuals/ExampleRotatingSpriteFrame.tscn create mode 100644 course/lesson-11-time-delta/visuals/ExampleRotatingSpriteTime.tscn diff --git a/course/lesson-11-time-delta/content-f8B67UJ8.tres b/course/lesson-11-time-delta/content-f8B67UJ8.tres index e912e02b1..37c1ac1de 100644 --- a/course/lesson-11-time-delta/content-f8B67UJ8.tres +++ b/course/lesson-11-time-delta/content-f8B67UJ8.tres @@ -4,7 +4,7 @@ [resource] script = ExtResource( 1 ) -text = "[visual]" -visual_element_path = "" +text = "" +visual_element_path = "res://course/lesson-11-time-delta/visuals/ExampleRotatingSpriteTime.tscn" reverse_blocks = false type = 0 diff --git a/course/lesson-11-time-delta/content-qE82V6jG.tres b/course/lesson-11-time-delta/content-qE82V6jG.tres index 55a798269..0956405c3 100644 --- a/course/lesson-11-time-delta/content-qE82V6jG.tres +++ b/course/lesson-11-time-delta/content-qE82V6jG.tres @@ -4,7 +4,7 @@ [resource] script = ExtResource( 1 ) -text = "What would happen if our computer slows down? +text = "What would happen if our computer slows down or has irregular frame times? Without [code]delta[/code], we'd get an irregular animation because the movement is dependent on frames." visual_element_path = "" diff --git a/course/lesson-11-time-delta/content-vGm22rtQ.tres b/course/lesson-11-time-delta/content-vGm22rtQ.tres index e912e02b1..944104f40 100644 --- a/course/lesson-11-time-delta/content-vGm22rtQ.tres +++ b/course/lesson-11-time-delta/content-vGm22rtQ.tres @@ -4,7 +4,7 @@ [resource] script = ExtResource( 1 ) -text = "[visual]" -visual_element_path = "" +text = "" +visual_element_path = "res://course/lesson-11-time-delta/visuals/ExampleRotatingSpriteFrame.tscn" reverse_blocks = false type = 0 diff --git a/course/lesson-11-time-delta/visuals/DemoRotatingSpriteFrame.gd b/course/lesson-11-time-delta/visuals/DemoRotatingSpriteFrame.gd new file mode 100644 index 000000000..297a94880 --- /dev/null +++ b/course/lesson-11-time-delta/visuals/DemoRotatingSpriteFrame.gd @@ -0,0 +1,14 @@ +extends Node2D + +var _times := [0.1, 0.1, 0.2, 0.1, 0.2] +var _index := 0 + +onready var _timer := $Timer +onready var _sprite := $DemoRotateSprite + + +func _on_Timer_timeout(): + _sprite.rotate(0.2) + _timer.start(_times[_index]) + + _index = wrapi(_index + 1, 0, _times.size() - 1) diff --git a/course/lesson-11-time-delta/visuals/DemoRotatingSpriteFrame.tscn b/course/lesson-11-time-delta/visuals/DemoRotatingSpriteFrame.tscn new file mode 100644 index 000000000..d58707606 --- /dev/null +++ b/course/lesson-11-time-delta/visuals/DemoRotatingSpriteFrame.tscn @@ -0,0 +1,31 @@ +[gd_scene load_steps=4 format=2] + +[ext_resource path="res://course/lesson-11-time-delta/visuals/DemoRotatingSpriteFrame.gd" type="Script" id=1] +[ext_resource path="res://course/lesson-1-what-code-is-like/first_practice/godot_bottom.png" type="Texture" id=2] +[ext_resource path="res://course/lesson-1-what-code-is-like/first_practice/hand_ice.png" type="Texture" id=3] + +[node name="Node2D" type="Node2D"] +script = ExtResource( 1 ) + +[node name="DemoRotateSprite" type="Node2D" parent="."] + +[node name="GodotBottom" type="Sprite" parent="DemoRotateSprite"] +position = Vector2( 0, -17 ) +texture = ExtResource( 2 ) + +[node name="HandIce" type="Sprite" parent="DemoRotateSprite"] +position = Vector2( 66, 14 ) +rotation = 0.36894 +texture = ExtResource( 3 ) + +[node name="HandIce2" type="Sprite" parent="DemoRotateSprite"] +position = Vector2( -65, 19 ) +rotation = -0.483649 +texture = ExtResource( 3 ) +flip_h = true + +[node name="Timer" type="Timer" parent="."] +wait_time = 0.1 +autostart = true + +[connection signal="timeout" from="Timer" to="." method="_on_Timer_timeout"] diff --git a/course/lesson-11-time-delta/visuals/DemoRotatingTime.gd b/course/lesson-11-time-delta/visuals/DemoRotatingTime.gd new file mode 100644 index 000000000..191032198 --- /dev/null +++ b/course/lesson-11-time-delta/visuals/DemoRotatingTime.gd @@ -0,0 +1,14 @@ +extends Node2D + +var _times := [0.1, 0.1, 0.2, 0.1, 0.2] +var _index := 0 + +onready var _timer := $Timer +onready var _sprite := $DemoRotateSprite + + +func _on_Timer_timeout(): + _sprite.rotate(1 * _timer.wait_time) + _timer.start(_times[_index]) + + _index = wrapi(_index + 1, 0, _times.size() - 1) diff --git a/course/lesson-11-time-delta/visuals/DemoRotatingTime.tscn b/course/lesson-11-time-delta/visuals/DemoRotatingTime.tscn new file mode 100644 index 000000000..c8423664d --- /dev/null +++ b/course/lesson-11-time-delta/visuals/DemoRotatingTime.tscn @@ -0,0 +1,31 @@ +[gd_scene load_steps=4 format=2] + +[ext_resource path="res://course/lesson-11-time-delta/visuals/DemoRotatingTime.gd" type="Script" id=1] +[ext_resource path="res://course/lesson-1-what-code-is-like/first_practice/godot_bottom.png" type="Texture" id=2] +[ext_resource path="res://course/lesson-1-what-code-is-like/first_practice/hand_ice.png" type="Texture" id=3] + +[node name="Node2D" type="Node2D"] +script = ExtResource( 1 ) + +[node name="DemoRotateSprite" type="Node2D" parent="."] + +[node name="GodotBottom" type="Sprite" parent="DemoRotateSprite"] +position = Vector2( 0, -17 ) +texture = ExtResource( 2 ) + +[node name="HandIce" type="Sprite" parent="DemoRotateSprite"] +position = Vector2( 66, 14 ) +rotation = 0.36894 +texture = ExtResource( 3 ) + +[node name="HandIce2" type="Sprite" parent="DemoRotateSprite"] +position = Vector2( -65, 19 ) +rotation = -0.483649 +texture = ExtResource( 3 ) +flip_h = true + +[node name="Timer" type="Timer" parent="."] +wait_time = 0.1 +autostart = true + +[connection signal="timeout" from="Timer" to="." method="_on_Timer_timeout"] diff --git a/course/lesson-11-time-delta/visuals/ExampleRotatingSpriteFrame.tscn b/course/lesson-11-time-delta/visuals/ExampleRotatingSpriteFrame.tscn new file mode 100644 index 000000000..0a2ea0ff0 --- /dev/null +++ b/course/lesson-11-time-delta/visuals/ExampleRotatingSpriteFrame.tscn @@ -0,0 +1,21 @@ +[gd_scene load_steps=3 format=2] + +[ext_resource path="res://ui/components/RunnableCodeExample.tscn" type="PackedScene" id=1] +[ext_resource path="res://course/lesson-11-time-delta/visuals/DemoRotatingSpriteFrame.tscn" type="PackedScene" id=2] + +[node name="ExampleRotatingSpriteFrame" type="PanelContainer"] +margin_right = 1047.0 +margin_bottom = 298.0 +size_flags_horizontal = 3 +__meta__ = { +"_edit_use_anchors_": false +} + +[node name="RunnableCodeExample" parent="." instance=ExtResource( 1 )] +margin_left = 7.0 +margin_top = 7.0 +margin_right = 1040.0 +margin_bottom = 291.0 +scene = ExtResource( 2 ) +gdscript_code = "func _process(delta): + rotate(0.2)" diff --git a/course/lesson-11-time-delta/visuals/ExampleRotatingSpriteTime.tscn b/course/lesson-11-time-delta/visuals/ExampleRotatingSpriteTime.tscn new file mode 100644 index 000000000..04e9f1fea --- /dev/null +++ b/course/lesson-11-time-delta/visuals/ExampleRotatingSpriteTime.tscn @@ -0,0 +1,21 @@ +[gd_scene load_steps=3 format=2] + +[ext_resource path="res://ui/components/RunnableCodeExample.tscn" type="PackedScene" id=1] +[ext_resource path="res://course/lesson-11-time-delta/visuals/DemoRotatingTime.tscn" type="PackedScene" id=2] + +[node name="ExampleRotatingSpriteTime" type="PanelContainer"] +margin_right = 1047.0 +margin_bottom = 298.0 +size_flags_horizontal = 3 +__meta__ = { +"_edit_use_anchors_": false +} + +[node name="RunnableCodeExample" parent="." instance=ExtResource( 1 )] +margin_left = 7.0 +margin_top = 7.0 +margin_right = 1040.0 +margin_bottom = 291.0 +scene = ExtResource( 2 ) +gdscript_code = "func _process(delta): + rotate(1 * delta)" From 52fa6340105a9764d4632828ac43466dc81e1252 Mon Sep 17 00:00:00 2001 From: johnnygossdev Date: Mon, 27 Dec 2021 18:31:10 +0000 Subject: [PATCH 10/21] content: add practice 1 to lesson 11 --- .../content-TLtZixQO.tres | 4 ++- course/lesson-11-time-delta/lesson.tres | 5 +-- .../practice-UdOCQiGj.tres | 20 ++++++++++++ .../lesson-11-time-delta/quiz-PRw9clsF.tres | 8 ++--- .../RotatingSpriteDelta.gd | 22 +++++++++++++ .../scene/RotatingSpriteDelta.tscn.tres | 9 ++++++ .../scripts/RotatingSpriteDelta.gd.tres | 32 +++++++++++++++++++ ...tingSpriteDelta.move_and_rotate.slice.tres | 20 ++++++++++++ .../RotatingSpriteDelta.tscn | 26 +++++++++++++++ .../TestsRotatingDelta.gd | 18 +++++++++++ 10 files changed, 157 insertions(+), 7 deletions(-) create mode 100644 course/lesson-11-time-delta/practice-UdOCQiGj.tres create mode 100644 course/lesson-11-time-delta/rotating-using-delta/RotatingSpriteDelta.gd create mode 100644 course/lesson-11-time-delta/rotating-using-delta/RotatingSpriteDelta.live-editor/scene/RotatingSpriteDelta.tscn.tres create mode 100644 course/lesson-11-time-delta/rotating-using-delta/RotatingSpriteDelta.live-editor/scripts/RotatingSpriteDelta.gd.tres create mode 100644 course/lesson-11-time-delta/rotating-using-delta/RotatingSpriteDelta.live-editor/slices/RotatingSpriteDelta.move_and_rotate.slice.tres create mode 100644 course/lesson-11-time-delta/rotating-using-delta/RotatingSpriteDelta.tscn create mode 100644 course/lesson-11-time-delta/rotating-using-delta/TestsRotatingDelta.gd diff --git a/course/lesson-11-time-delta/content-TLtZixQO.tres b/course/lesson-11-time-delta/content-TLtZixQO.tres index 90bb192f5..e2ce65001 100644 --- a/course/lesson-11-time-delta/content-TLtZixQO.tres +++ b/course/lesson-11-time-delta/content-TLtZixQO.tres @@ -8,7 +8,9 @@ text = "Rather than jumping the full amount every frame, we rotate the character These values are bigger because [code]delta[/code] is so small. -By multiplying the 3 radians by [code]delta[/code], we rotate the character by 3 radians per second. +By multiplying 1 radians by [code]delta[/code], we rotate the character by 1 radian per second. + +We've slowed the above down to see the difference easier. When we multiply time sensitive values like this, we make them [b]time-dependent[/b] rather than [b]frame-dependent[/b]." visual_element_path = "" diff --git a/course/lesson-11-time-delta/lesson.tres b/course/lesson-11-time-delta/lesson.tres index 9afa8eb62..b17dc0dbf 100644 --- a/course/lesson-11-time-delta/lesson.tres +++ b/course/lesson-11-time-delta/lesson.tres @@ -1,9 +1,10 @@ -[gd_resource type="Resource" load_steps=17 format=2] +[gd_resource type="Resource" load_steps=18 format=2] [ext_resource path="res://resources/Lesson.gd" type="Script" id=1] [ext_resource path="res://course/lesson-11-time-delta/quiz-HARbBWNb.tres" type="Resource" id=2] [ext_resource path="res://course/lesson-11-time-delta/content-hcIb5BnV.tres" type="Resource" id=3] [ext_resource path="res://course/lesson-11-time-delta/content-N4rS5AJT.tres" type="Resource" id=4] +[ext_resource path="res://course/lesson-11-time-delta/practice-UdOCQiGj.tres" type="Resource" id=5] [ext_resource path="res://course/lesson-11-time-delta/content-DwfyqdYO.tres" type="Resource" id=6] [ext_resource path="res://course/lesson-11-time-delta/content-exRjTRhZ.tres" type="Resource" id=7] [ext_resource path="res://course/lesson-11-time-delta/content-1TxlTtcy.tres" type="Resource" id=8] @@ -21,4 +22,4 @@ script = ExtResource( 1 ) title = "Time Delta" content_blocks = [ ExtResource( 6 ), ExtResource( 7 ), ExtResource( 4 ), ExtResource( 8 ), ExtResource( 3 ), ExtResource( 2 ), ExtResource( 12 ), ExtResource( 10 ), ExtResource( 13 ), ExtResource( 15 ), ExtResource( 9 ), ExtResource( 11 ), ExtResource( 14 ), ExtResource( 17 ), ExtResource( 16 ) ] -practices = [ ] +practices = [ ExtResource( 5 ) ] diff --git a/course/lesson-11-time-delta/practice-UdOCQiGj.tres b/course/lesson-11-time-delta/practice-UdOCQiGj.tres new file mode 100644 index 000000000..91eb32dc6 --- /dev/null +++ b/course/lesson-11-time-delta/practice-UdOCQiGj.tres @@ -0,0 +1,20 @@ +[gd_resource type="Resource" load_steps=3 format=2] + +[ext_resource path="res://resources/Practice.gd" type="Script" id=1] +[ext_resource path="res://course/Documentation.tres" type="Resource" id=2] + +[resource] +script = ExtResource( 1 ) +title = "Rotating Using Delta" +goal = "At the minute, the rotation of the robot is frame-dependent. + +Add [code]delta[/code] to make the rotational speed time-dependent. + +The robot should rotate 2 radians per second." +starting_code = "func _process(delta): + rotate(2)" +hints = PoolStringArray( "Multiple the radians by [code]delta[/code]." ) +validator_script_path = "rotating-using-delta/TestsRotatingDelta.gd" +script_slice_path = "rotating-using-delta/RotatingSpriteDelta.live-editor/slices/RotatingSpriteDelta.move_and_rotate.slice.tres" +documentation_references = PoolStringArray( ) +documentation_resource = ExtResource( 2 ) diff --git a/course/lesson-11-time-delta/quiz-PRw9clsF.tres b/course/lesson-11-time-delta/quiz-PRw9clsF.tres index e8b90c762..b9272c240 100644 --- a/course/lesson-11-time-delta/quiz-PRw9clsF.tres +++ b/course/lesson-11-time-delta/quiz-PRw9clsF.tres @@ -5,10 +5,10 @@ [resource] script = ExtResource( 1 ) question = "What does this mean?" -content_bbcode = "[code] speed * time [/code]" +content_bbcode = "[code] rotation_speed * delta [/code]" hint = "" -explanation_bbcode = "The [code]*[/code] symbol means we're multiplying [code]speed[/code] by [code]time[/code]." -answer_options = [ "We're multiplying speed by time.", "We're dividing time by speed.", "We're adding speed to time.", "We're subtracting time from speed." ] -valid_answers = [ "We're multiplying speed by time." ] +explanation_bbcode = "The [code]*[/code] symbol means we're multiplying [code]rotation_speed[/code] by [code]delta[/code] time." +answer_options = [ "We're multiplying rotation_speed by delta.", "We're dividing delta by rotation_speed.", "We're adding rotation_speed to delta.", "We're subtracting delta from rotation_speed." ] +valid_answers = [ "We're multiplying rotation_speed by delta." ] is_multiple_choice = false do_shuffle_answers = true diff --git a/course/lesson-11-time-delta/rotating-using-delta/RotatingSpriteDelta.gd b/course/lesson-11-time-delta/rotating-using-delta/RotatingSpriteDelta.gd new file mode 100644 index 000000000..0162dbcf4 --- /dev/null +++ b/course/lesson-11-time-delta/rotating-using-delta/RotatingSpriteDelta.gd @@ -0,0 +1,22 @@ +extends Node2D + + +func _ready() -> void: + set_process(false) + + +# EXPORT move_and_rotate +func _process(delta): + rotate(2 * delta) +# /EXPORT move_and_rotate + + +func _run() -> void: + reset() + _process(0.0) + set_process(true) + + +func reset() -> void: + rotation = 0.0 + set_process(false) diff --git a/course/lesson-11-time-delta/rotating-using-delta/RotatingSpriteDelta.live-editor/scene/RotatingSpriteDelta.tscn.tres b/course/lesson-11-time-delta/rotating-using-delta/RotatingSpriteDelta.live-editor/scene/RotatingSpriteDelta.tscn.tres new file mode 100644 index 000000000..92edad24c --- /dev/null +++ b/course/lesson-11-time-delta/rotating-using-delta/RotatingSpriteDelta.live-editor/scene/RotatingSpriteDelta.tscn.tres @@ -0,0 +1,9 @@ +[gd_resource type="Resource" load_steps=3 format=2] + +[ext_resource path="res://course/lesson-11-time-delta/rotating-using-delta/RotatingSpriteDelta.tscn" type="PackedScene" id=1] +[ext_resource path="res://addons/gdscript-slice-exporter/collections/SceneProperties.gd" type="Script" id=2] + +[resource] +script = ExtResource( 2 ) +scene = ExtResource( 1 ) +viewport_size = Vector2( 1920, 1080 ) diff --git a/course/lesson-11-time-delta/rotating-using-delta/RotatingSpriteDelta.live-editor/scripts/RotatingSpriteDelta.gd.tres b/course/lesson-11-time-delta/rotating-using-delta/RotatingSpriteDelta.live-editor/scripts/RotatingSpriteDelta.gd.tres new file mode 100644 index 000000000..8d67a9493 --- /dev/null +++ b/course/lesson-11-time-delta/rotating-using-delta/RotatingSpriteDelta.live-editor/scripts/RotatingSpriteDelta.gd.tres @@ -0,0 +1,32 @@ +[gd_resource type="Resource" load_steps=3 format=2] + +[ext_resource path="res://addons/gdscript-slice-exporter/collections/ScriptProperties.gd" type="Script" id=1] +[ext_resource path="res://course/lesson-11-time-delta/rotating-using-delta/RotatingSpriteDelta.gd" type="Script" id=2] + +[resource] +script = ExtResource( 1 ) +nodes_paths = [ NodePath("RotatingSprite") ] +script_file = ExtResource( 2 ) +original_script = "extends Node2D + + +func _ready() -> void: + set_process(false) + + +# EXPORT move_and_rotate +func _process(delta): + rotate(2 * delta) +# /EXPORT move_and_rotate + + +func _run() -> void: + reset() + _process(0.0) + set_process(true) + + +func reset() -> void: + rotation = 0.0 + set_process(false) +" diff --git a/course/lesson-11-time-delta/rotating-using-delta/RotatingSpriteDelta.live-editor/slices/RotatingSpriteDelta.move_and_rotate.slice.tres b/course/lesson-11-time-delta/rotating-using-delta/RotatingSpriteDelta.live-editor/slices/RotatingSpriteDelta.move_and_rotate.slice.tres new file mode 100644 index 000000000..c1edc0ce9 --- /dev/null +++ b/course/lesson-11-time-delta/rotating-using-delta/RotatingSpriteDelta.live-editor/slices/RotatingSpriteDelta.move_and_rotate.slice.tres @@ -0,0 +1,20 @@ +[gd_resource type="Resource" load_steps=4 format=2] + +[ext_resource path="res://course/lesson-11-time-delta/rotating-using-delta/RotatingSpriteDelta.live-editor/scripts/RotatingSpriteDelta.gd.tres" type="Resource" id=1] +[ext_resource path="res://course/lesson-11-time-delta/rotating-using-delta/RotatingSpriteDelta.live-editor/scene/RotatingSpriteDelta.tscn.tres" type="Resource" id=2] +[ext_resource path="res://addons/gdscript-slice-exporter/collections/SliceProperties.gd" type="Script" id=3] + +[resource] +script = ExtResource( 3 ) +scene_properties = ExtResource( 2 ) +script_properties = ExtResource( 1 ) +leading_spaces = 0 +keyword = "EXPORT" +closing = false +name = "move_and_rotate" +is_full_file = false +start = 7 +end = 10 +lines_before = [ "extends Node2D", "", "", "func _ready() -> void:", " set_process(false)", "", "" ] +lines_after = [ "", "", "func _run() -> void:", " reset()", " _process(0.0)", " set_process(true)", "", "", "func reset() -> void:", " rotation = 0.0", " set_process(false)", "" ] +lines_editable = [ "func _process(delta):", " rotate(2 * delta)" ] diff --git a/course/lesson-11-time-delta/rotating-using-delta/RotatingSpriteDelta.tscn b/course/lesson-11-time-delta/rotating-using-delta/RotatingSpriteDelta.tscn new file mode 100644 index 000000000..8000862c6 --- /dev/null +++ b/course/lesson-11-time-delta/rotating-using-delta/RotatingSpriteDelta.tscn @@ -0,0 +1,26 @@ +[gd_scene load_steps=4 format=2] + +[ext_resource path="res://course/lesson-11-time-delta/rotating-using-delta/RotatingSpriteDelta.gd" type="Script" id=1] +[ext_resource path="res://course/lesson-1-what-code-is-like/first_practice/hand_ice.png" type="Texture" id=2] +[ext_resource path="res://course/lesson-1-what-code-is-like/first_practice/godot_bottom.png" type="Texture" id=3] + +[node name="Position2D" type="Position2D"] + +[node name="RotatingSprite" type="Node2D" parent="."] +position = Vector2( 300, 300 ) +script = ExtResource( 1 ) + +[node name="GodotBottom" type="Sprite" parent="RotatingSprite"] +position = Vector2( 0, -17 ) +texture = ExtResource( 3 ) + +[node name="HandIce" type="Sprite" parent="RotatingSprite"] +position = Vector2( 66, 14 ) +rotation = 0.36894 +texture = ExtResource( 2 ) + +[node name="HandIce2" type="Sprite" parent="RotatingSprite"] +position = Vector2( -65, 19 ) +rotation = -0.483649 +texture = ExtResource( 2 ) +flip_h = true diff --git a/course/lesson-11-time-delta/rotating-using-delta/TestsRotatingDelta.gd b/course/lesson-11-time-delta/rotating-using-delta/TestsRotatingDelta.gd new file mode 100644 index 000000000..f7e7c021f --- /dev/null +++ b/course/lesson-11-time-delta/rotating-using-delta/TestsRotatingDelta.gd @@ -0,0 +1,18 @@ +extends PracticeTester + + +func test_rotating_character_is_time_dependent() -> String: + var has_delta := _slice.current_text.rfind("delta") > 0 + var has_spaces := _slice.current_text.rfind(" * ") > 0 + var has_two := _slice.current_text.rfind("2") > 0 + + if not has_delta: + return "Did you use delta to make the rotation time-dependent?" + elif not has_two: + return "Is the rotation speed correct?" + elif not has_spaces: + return "Did you use spaces between *?" + elif not _slice.current_text.match(_slice.get_slice_text()): + return "There's something wrong here." + + return "" From ce85c0514332660fb430a89edae6bfe31f8288df Mon Sep 17 00:00:00 2001 From: johnnygossdev Date: Mon, 27 Dec 2021 18:36:53 +0000 Subject: [PATCH 11/21] improvement: typos and clean up --- course/lesson-10-the-game-loop/practice-tKRHJMQ2.tres | 6 +++--- course/lesson-11-time-delta/content-f8B67UJ8.tres | 2 +- course/lesson-11-time-delta/content-vGm22rtQ.tres | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/course/lesson-10-the-game-loop/practice-tKRHJMQ2.tres b/course/lesson-10-the-game-loop/practice-tKRHJMQ2.tres index f8681c6fe..b24618bb9 100644 --- a/course/lesson-10-the-game-loop/practice-tKRHJMQ2.tres +++ b/course/lesson-10-the-game-loop/practice-tKRHJMQ2.tres @@ -11,8 +11,8 @@ goal = "Make the robot rotate slowly by adding to the [code]_process()[/code] fu A rotation speed of about 0.05 each frame should do." starting_code = "func _process(_delta): pass" -hints = PoolStringArray( "Replace [code]pass[/code] with the [code]rotate()[/code] function." ) -validator_script_path = "res://course/lesson-10-the-game-loop/rotating-sprite/TestsRotating.gd" -script_slice_path = "res://course/lesson-10-the-game-loop/rotating-sprite/RotatingSprite.live-editor/slices/RotatingSprite.move_and_rotate.slice.tres" +hints = PoolStringArray( "Replace [code]pass[/code] with the [code]rotate()[/code] function.", "The [code]rotate[/code] function takes one parameter." ) +validator_script_path = "rotating-sprite/TestsRotating.gd" +script_slice_path = "rotating-sprite/RotatingSprite.live-editor/slices/RotatingSprite.move_and_rotate.slice.tres" documentation_references = PoolStringArray( ) documentation_resource = ExtResource( 2 ) diff --git a/course/lesson-11-time-delta/content-f8B67UJ8.tres b/course/lesson-11-time-delta/content-f8B67UJ8.tres index 37c1ac1de..47442b3bf 100644 --- a/course/lesson-11-time-delta/content-f8B67UJ8.tres +++ b/course/lesson-11-time-delta/content-f8B67UJ8.tres @@ -5,6 +5,6 @@ [resource] script = ExtResource( 1 ) text = "" -visual_element_path = "res://course/lesson-11-time-delta/visuals/ExampleRotatingSpriteTime.tscn" +visual_element_path = "visuals/ExampleRotatingSpriteTime.tscn" reverse_blocks = false type = 0 diff --git a/course/lesson-11-time-delta/content-vGm22rtQ.tres b/course/lesson-11-time-delta/content-vGm22rtQ.tres index 944104f40..3e9510738 100644 --- a/course/lesson-11-time-delta/content-vGm22rtQ.tres +++ b/course/lesson-11-time-delta/content-vGm22rtQ.tres @@ -5,6 +5,6 @@ [resource] script = ExtResource( 1 ) text = "" -visual_element_path = "res://course/lesson-11-time-delta/visuals/ExampleRotatingSpriteFrame.tscn" +visual_element_path = "visuals/ExampleRotatingSpriteFrame.tscn" reverse_blocks = false type = 0 From e56dabddba5bf1864d897f03a011499289387421 Mon Sep 17 00:00:00 2001 From: johnnygossdev Date: Mon, 3 Jan 2022 17:00:25 +0000 Subject: [PATCH 12/21] content: add lesson 10 practice 2 --- course/lesson-10-the-game-loop/lesson.tres | 5 +-- .../practice-QiGjB7tK.tres | 20 +++++++++++ .../practice-tKRHJMQ2.tres | 6 ++-- .../RotateAndMoveSprite.gd | 2 +- .../scene/RotateAndMoveSprite.tscn.tres | 8 ++--- .../scripts/RotateAndMoveSprite.gd.tres | 10 +++--- .../scripts/RotatingSprite.gd.tres | 34 ------------------- ...teAndMoveSprite.move_and_rotate.slice.tres | 10 +++--- .../RotatingSprite.move_and_rotate.slice.tres | 20 ----------- .../RotateAndMoveSprite.tscn | 2 +- .../TestsRotatingAndMoving.gd | 12 +++---- 11 files changed, 48 insertions(+), 81 deletions(-) create mode 100644 course/lesson-10-the-game-loop/practice-QiGjB7tK.tres delete mode 100644 course/lesson-10-the-game-loop/rotating-and-moving/RotateAndMoveSprite.live-editor/scripts/RotatingSprite.gd.tres delete mode 100644 course/lesson-10-the-game-loop/rotating-and-moving/RotateAndMoveSprite.live-editor/slices/RotatingSprite.move_and_rotate.slice.tres diff --git a/course/lesson-10-the-game-loop/lesson.tres b/course/lesson-10-the-game-loop/lesson.tres index aed502ee0..240dd8b96 100644 --- a/course/lesson-10-the-game-loop/lesson.tres +++ b/course/lesson-10-the-game-loop/lesson.tres @@ -1,6 +1,7 @@ -[gd_resource type="Resource" load_steps=15 format=2] +[gd_resource type="Resource" load_steps=16 format=2] [ext_resource path="res://resources/Lesson.gd" type="Script" id=1] +[ext_resource path="res://course/lesson-10-the-game-loop/practice-QiGjB7tK.tres" type="Resource" id=2] [ext_resource path="res://course/lesson-10-the-game-loop/content-pPwQDwfy.tres" type="Resource" id=3] [ext_resource path="res://course/lesson-10-the-game-loop/content-TRhZN4rS.tres" type="Resource" id=4] [ext_resource path="res://course/lesson-10-the-game-loop/content-RHJMQ2XN.tres" type="Resource" id=5] @@ -19,4 +20,4 @@ script = ExtResource( 1 ) title = "The Game Loop" content_blocks = [ ExtResource( 9 ), ExtResource( 12 ), ExtResource( 5 ), ExtResource( 7 ), ExtResource( 13 ), ExtResource( 3 ), ExtResource( 8 ), ExtResource( 4 ), ExtResource( 6 ), ExtResource( 10 ), ExtResource( 11 ), ExtResource( 14 ) ] -practices = [ ExtResource( 15 ) ] +practices = [ ExtResource( 15 ), ExtResource( 2 ) ] diff --git a/course/lesson-10-the-game-loop/practice-QiGjB7tK.tres b/course/lesson-10-the-game-loop/practice-QiGjB7tK.tres new file mode 100644 index 000000000..b0f01ec75 --- /dev/null +++ b/course/lesson-10-the-game-loop/practice-QiGjB7tK.tres @@ -0,0 +1,20 @@ +[gd_resource type="Resource" load_steps=3 format=2] + +[ext_resource path="res://resources/Practice.gd" type="Script" id=1] +[ext_resource path="res://course/Documentation.tres" type="Resource" id=2] + +[resource] +script = ExtResource( 1 ) +title = "" +goal = "Make the robot move in a circle slowly by rotating it, then moving it in the x direction. + +To do this, add the [code]rotate()[/code] and [code]move_local_x()[/code] functions to [code]_process()[/code]. + +Use a rotation speed of [code]0.05[/code] radians per frame, and move the robot [code]5[/code] pixels per frame." +starting_code = "func _process(_delta): + pass" +hints = PoolStringArray( "Replace [code]pass[/code] with the [code]rotate()[/code] and [code]move_local_x()[/code] functions" ) +validator_script_path = "rotating-and-moving/TestsRotatingAndMoving.gd" +script_slice_path = "rotating-and-moving/RotateAndMoveSprite.live-editor/slices/RotateAndMoveSprite.move_and_rotate.slice.tres" +documentation_references = PoolStringArray( "rotate", "move_local_x" ) +documentation_resource = ExtResource( 2 ) diff --git a/course/lesson-10-the-game-loop/practice-tKRHJMQ2.tres b/course/lesson-10-the-game-loop/practice-tKRHJMQ2.tres index b24618bb9..3ab8ad002 100644 --- a/course/lesson-10-the-game-loop/practice-tKRHJMQ2.tres +++ b/course/lesson-10-the-game-loop/practice-tKRHJMQ2.tres @@ -8,11 +8,11 @@ script = ExtResource( 1 ) title = "Rotating a Character Continuously" goal = "Make the robot rotate slowly by adding to the [code]_process()[/code] function. -A rotation speed of about 0.05 each frame should do." +A rotation speed of about [code]0.05[/code] each frame should do." starting_code = "func _process(_delta): pass" -hints = PoolStringArray( "Replace [code]pass[/code] with the [code]rotate()[/code] function.", "The [code]rotate[/code] function takes one parameter." ) +hints = PoolStringArray( "Replace [code]pass[/code] with the [code]rotate()[/code] function", "The [code]rotate()[/code] function takes one parameter" ) validator_script_path = "rotating-sprite/TestsRotating.gd" script_slice_path = "rotating-sprite/RotatingSprite.live-editor/slices/RotatingSprite.move_and_rotate.slice.tres" -documentation_references = PoolStringArray( ) +documentation_references = PoolStringArray( "rotate" ) documentation_resource = ExtResource( 2 ) diff --git a/course/lesson-10-the-game-loop/rotating-and-moving/RotateAndMoveSprite.gd b/course/lesson-10-the-game-loop/rotating-and-moving/RotateAndMoveSprite.gd index 673ad6206..0288a1828 100644 --- a/course/lesson-10-the-game-loop/rotating-and-moving/RotateAndMoveSprite.gd +++ b/course/lesson-10-the-game-loop/rotating-and-moving/RotateAndMoveSprite.gd @@ -20,5 +20,5 @@ func _run() -> void: func reset() -> void: rotation = 0.0 - position = Vector2.ZERO + position = Vector2(300, 200) set_process(false) diff --git a/course/lesson-10-the-game-loop/rotating-and-moving/RotateAndMoveSprite.live-editor/scene/RotateAndMoveSprite.tscn.tres b/course/lesson-10-the-game-loop/rotating-and-moving/RotateAndMoveSprite.live-editor/scene/RotateAndMoveSprite.tscn.tres index 3362cbdac..61e6ef478 100644 --- a/course/lesson-10-the-game-loop/rotating-and-moving/RotateAndMoveSprite.live-editor/scene/RotateAndMoveSprite.tscn.tres +++ b/course/lesson-10-the-game-loop/rotating-and-moving/RotateAndMoveSprite.live-editor/scene/RotateAndMoveSprite.tscn.tres @@ -1,9 +1,9 @@ [gd_resource type="Resource" load_steps=3 format=2] -[ext_resource path="res://course/lesson-10-the-game-loop/rotating-and-moving/RotateAndMoveSprite.tscn" type="PackedScene" id=1] -[ext_resource path="res://addons/gdscript-slice-exporter/collections/SceneProperties.gd" type="Script" id=2] +[ext_resource path="res://addons/gdscript-slice-exporter/collections/SceneProperties.gd" type="Script" id=1] +[ext_resource path="res://course/lesson-10-the-game-loop/rotating-and-moving/RotateAndMoveSprite.tscn" type="PackedScene" id=2] [resource] -script = ExtResource( 2 ) -scene = ExtResource( 1 ) +script = ExtResource( 1 ) +scene = ExtResource( 2 ) viewport_size = Vector2( 1920, 1080 ) diff --git a/course/lesson-10-the-game-loop/rotating-and-moving/RotateAndMoveSprite.live-editor/scripts/RotateAndMoveSprite.gd.tres b/course/lesson-10-the-game-loop/rotating-and-moving/RotateAndMoveSprite.live-editor/scripts/RotateAndMoveSprite.gd.tres index a7aeafb31..3f226bf1a 100644 --- a/course/lesson-10-the-game-loop/rotating-and-moving/RotateAndMoveSprite.live-editor/scripts/RotateAndMoveSprite.gd.tres +++ b/course/lesson-10-the-game-loop/rotating-and-moving/RotateAndMoveSprite.live-editor/scripts/RotateAndMoveSprite.gd.tres @@ -1,12 +1,12 @@ [gd_resource type="Resource" load_steps=3 format=2] -[ext_resource path="res://course/lesson-10-the-game-loop/rotating-and-moving/RotateAndMoveSprite.gd" type="Script" id=1] -[ext_resource path="res://addons/gdscript-slice-exporter/collections/ScriptProperties.gd" type="Script" id=2] +[ext_resource path="res://addons/gdscript-slice-exporter/collections/ScriptProperties.gd" type="Script" id=1] +[ext_resource path="res://course/lesson-10-the-game-loop/rotating-and-moving/RotateAndMoveSprite.gd" type="Script" id=2] [resource] -script = ExtResource( 2 ) +script = ExtResource( 1 ) nodes_paths = [ NodePath("RotateAndMoveSprite") ] -script_file = ExtResource( 1 ) +script_file = ExtResource( 2 ) original_script = "extends Node2D @@ -29,6 +29,6 @@ func _run() -> void: func reset() -> void: rotation = 0.0 - position = Vector2.ZERO + position = Vector2(300, 200) set_process(false) " diff --git a/course/lesson-10-the-game-loop/rotating-and-moving/RotateAndMoveSprite.live-editor/scripts/RotatingSprite.gd.tres b/course/lesson-10-the-game-loop/rotating-and-moving/RotateAndMoveSprite.live-editor/scripts/RotatingSprite.gd.tres deleted file mode 100644 index 34a8c8053..000000000 --- a/course/lesson-10-the-game-loop/rotating-and-moving/RotateAndMoveSprite.live-editor/scripts/RotatingSprite.gd.tres +++ /dev/null @@ -1,34 +0,0 @@ -[gd_resource type="Resource" load_steps=3 format=2] - -[ext_resource path="res://course/lesson-10-the-game-loop/rotating-sprite/RotatingSprite.gd" type="Script" id=1] -[ext_resource path="res://addons/gdscript-slice-exporter/collections/ScriptProperties.gd" type="Script" id=2] - -[resource] -script = ExtResource( 2 ) -nodes_paths = [ NodePath("RotateAndMoveSprite") ] -script_file = ExtResource( 1 ) -original_script = "extends Node2D - - -func _ready() -> void: - set_process(false) - - -# EXPORT move_and_rotate -func _process(_delta): - rotate(0.05) - move_local_x(5) -# /EXPORT move_and_rotate - - -func _run() -> void: - reset() - _process(0.0) - set_process(true) - - -func reset() -> void: - rotation = 0.0 - position = Vector2.ZERO - set_process(false) -" diff --git a/course/lesson-10-the-game-loop/rotating-and-moving/RotateAndMoveSprite.live-editor/slices/RotateAndMoveSprite.move_and_rotate.slice.tres b/course/lesson-10-the-game-loop/rotating-and-moving/RotateAndMoveSprite.live-editor/slices/RotateAndMoveSprite.move_and_rotate.slice.tres index a51ebb9aa..842ae9d00 100644 --- a/course/lesson-10-the-game-loop/rotating-and-moving/RotateAndMoveSprite.live-editor/slices/RotateAndMoveSprite.move_and_rotate.slice.tres +++ b/course/lesson-10-the-game-loop/rotating-and-moving/RotateAndMoveSprite.live-editor/slices/RotateAndMoveSprite.move_and_rotate.slice.tres @@ -1,12 +1,12 @@ [gd_resource type="Resource" load_steps=4 format=2] -[ext_resource path="res://course/lesson-10-the-game-loop/rotating-and-moving/RotateAndMoveSprite.live-editor/scene/RotateAndMoveSprite.tscn.tres" type="Resource" id=1] +[ext_resource path="res://addons/gdscript-slice-exporter/collections/SliceProperties.gd" type="Script" id=1] [ext_resource path="res://course/lesson-10-the-game-loop/rotating-and-moving/RotateAndMoveSprite.live-editor/scripts/RotateAndMoveSprite.gd.tres" type="Resource" id=2] -[ext_resource path="res://addons/gdscript-slice-exporter/collections/SliceProperties.gd" type="Script" id=3] +[ext_resource path="res://course/lesson-10-the-game-loop/rotating-and-moving/RotateAndMoveSprite.live-editor/scene/RotateAndMoveSprite.tscn.tres" type="Resource" id=3] [resource] -script = ExtResource( 3 ) -scene_properties = ExtResource( 1 ) +script = ExtResource( 1 ) +scene_properties = ExtResource( 3 ) script_properties = ExtResource( 2 ) leading_spaces = 0 keyword = "EXPORT" @@ -16,5 +16,5 @@ is_full_file = false start = 7 end = 11 lines_before = [ "extends Node2D", "", "", "func _ready() -> void:", " set_process(false)", "", "" ] -lines_after = [ "", "", "func _run() -> void:", " reset()", " _process(0.0)", " set_process(true)", "", "", "func reset() -> void:", " rotation = 0.0", " position = Vector2.ZERO", " set_process(false)", "" ] +lines_after = [ "", "", "func _run() -> void:", " reset()", " _process(0.0)", " set_process(true)", "", "", "func reset() -> void:", " rotation = 0.0", " position = Vector2(300, 200)", " set_process(false)", "" ] lines_editable = [ "func _process(_delta):", " rotate(0.05)", " move_local_x(5)" ] diff --git a/course/lesson-10-the-game-loop/rotating-and-moving/RotateAndMoveSprite.live-editor/slices/RotatingSprite.move_and_rotate.slice.tres b/course/lesson-10-the-game-loop/rotating-and-moving/RotateAndMoveSprite.live-editor/slices/RotatingSprite.move_and_rotate.slice.tres deleted file mode 100644 index f72f61569..000000000 --- a/course/lesson-10-the-game-loop/rotating-and-moving/RotateAndMoveSprite.live-editor/slices/RotatingSprite.move_and_rotate.slice.tres +++ /dev/null @@ -1,20 +0,0 @@ -[gd_resource type="Resource" load_steps=4 format=2] - -[ext_resource path="res://course/lesson-10-the-game-loop/rotating-and-moving/RotateAndMoveSprite.live-editor/scene/RotateAndMoveSprite.tscn.tres" type="Resource" id=1] -[ext_resource path="res://course/lesson-10-the-game-loop/rotating-and-moving/RotateAndMoveSprite.live-editor/scripts/RotatingSprite.gd.tres" type="Resource" id=2] -[ext_resource path="res://addons/gdscript-slice-exporter/collections/SliceProperties.gd" type="Script" id=3] - -[resource] -script = ExtResource( 3 ) -scene_properties = ExtResource( 1 ) -script_properties = ExtResource( 2 ) -leading_spaces = 0 -keyword = "EXPORT" -closing = false -name = "move_and_rotate" -is_full_file = false -start = 7 -end = 11 -lines_before = [ "extends Node2D", "", "", "func _ready() -> void:", " set_process(false)", "", "" ] -lines_after = [ "", "", "func _run() -> void:", " reset()", " _process(0.0)", " set_process(true)", "", "", "func reset() -> void:", " rotation = 0.0", " position = Vector2.ZERO", " set_process(false)", "" ] -lines_editable = [ "func _process(_delta):", " rotate(0.05)", " move_local_x(5)" ] diff --git a/course/lesson-10-the-game-loop/rotating-and-moving/RotateAndMoveSprite.tscn b/course/lesson-10-the-game-loop/rotating-and-moving/RotateAndMoveSprite.tscn index 36641db70..d9e078d14 100644 --- a/course/lesson-10-the-game-loop/rotating-and-moving/RotateAndMoveSprite.tscn +++ b/course/lesson-10-the-game-loop/rotating-and-moving/RotateAndMoveSprite.tscn @@ -7,7 +7,7 @@ [node name="Position2D" type="Position2D"] [node name="RotateAndMoveSprite" type="Node2D" parent="."] -position = Vector2( 300, 300 ) +position = Vector2( 300, 200 ) script = ExtResource( 1 ) [node name="GodotBottom" type="Sprite" parent="RotateAndMoveSprite"] diff --git a/course/lesson-10-the-game-loop/rotating-and-moving/TestsRotatingAndMoving.gd b/course/lesson-10-the-game-loop/rotating-and-moving/TestsRotatingAndMoving.gd index a9249a774..4b6c162e3 100644 --- a/course/lesson-10-the-game-loop/rotating-and-moving/TestsRotatingAndMoving.gd +++ b/course/lesson-10-the-game-loop/rotating-and-moving/TestsRotatingAndMoving.gd @@ -4,16 +4,16 @@ extends PracticeTester func test_character_is_rotating_slowly() -> String: var node_2d = _scene_root_viewport.get_child(0).get_child(0) var node_rotation = node_2d.rotation - var node_position := node_2d.position as Vector2 - var test = node_position - Vector2(4.994, 0.25) + var node_position = node_2d.position as Vector2 + if node_rotation < 0.0: return "The robot is turning in the wrong direction!" elif node_rotation > 0.06: return "The robot is turning too fast!" elif not is_equal_approx(node_rotation, 0.05): return "The robot's rotation speed isn't right." - - - elif not test.is_equal_approx(Vector2.ZERO): - return "false" + elif not is_equal_approx(node_position.x, 304.994): + return "The value of a parameter isn't right." + elif not is_equal_approx(node_position.y, 200.25): + return "The value of a parameter isn't right." return "" From da4350eee291c43e502f04d8d2faaa663479c8ca Mon Sep 17 00:00:00 2001 From: johnnygossdev Date: Mon, 3 Jan 2022 17:04:31 +0000 Subject: [PATCH 13/21] fix: add title to lesson 10 practice 2 --- course/lesson-10-the-game-loop/practice-QiGjB7tK.tres | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/course/lesson-10-the-game-loop/practice-QiGjB7tK.tres b/course/lesson-10-the-game-loop/practice-QiGjB7tK.tres index b0f01ec75..1c860c649 100644 --- a/course/lesson-10-the-game-loop/practice-QiGjB7tK.tres +++ b/course/lesson-10-the-game-loop/practice-QiGjB7tK.tres @@ -5,7 +5,7 @@ [resource] script = ExtResource( 1 ) -title = "" +title = "Creating Circular Movement" goal = "Make the robot move in a circle slowly by rotating it, then moving it in the x direction. To do this, add the [code]rotate()[/code] and [code]move_local_x()[/code] functions to [code]_process()[/code]. From 30a7858ad010250f4a58bfbb0c98730ba60c0781 Mon Sep 17 00:00:00 2001 From: johnnygossdev Date: Mon, 3 Jan 2022 17:06:45 +0000 Subject: [PATCH 14/21] fix: rename test --- .../rotating-and-moving/TestsRotatingAndMoving.gd | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/course/lesson-10-the-game-loop/rotating-and-moving/TestsRotatingAndMoving.gd b/course/lesson-10-the-game-loop/rotating-and-moving/TestsRotatingAndMoving.gd index 4b6c162e3..001014f0c 100644 --- a/course/lesson-10-the-game-loop/rotating-and-moving/TestsRotatingAndMoving.gd +++ b/course/lesson-10-the-game-loop/rotating-and-moving/TestsRotatingAndMoving.gd @@ -1,7 +1,7 @@ extends PracticeTester -func test_character_is_rotating_slowly() -> String: +func test_character_is_moving_in_a_circle_slowly() -> String: var node_2d = _scene_root_viewport.get_child(0).get_child(0) var node_rotation = node_2d.rotation var node_position = node_2d.position as Vector2 From 84bcc8574b456c243175b446a1c7108fa6f014ed Mon Sep 17 00:00:00 2001 From: johnnygossdev Date: Mon, 3 Jan 2022 17:25:43 +0000 Subject: [PATCH 15/21] content: add lesson 11 practice 2 --- course/course-learn-gdscript.tres | 2 +- course/lesson-11-time-delta/lesson.tres | 5 +-- .../practice-UdOCQiGj.tres | 6 ++-- .../practice-x0c7DDiz.tres | 18 ++++++++++ .../RotatingMovingSpriteDelta.gd | 24 +++++++++++++ .../scene/RotatingMovingSpriteDelta.tscn.tres | 9 +++++ .../scripts/RotatingMovingSpriteDelta.gd.tres | 34 +++++++++++++++++++ ...vingSpriteDelta.move_and_rotate.slice.tres | 20 +++++++++++ .../RotatingMovingSpriteDelta.tscn | 26 ++++++++++++++ .../TestsRotatingMovingDelta.gd | 21 ++++++++++++ .../RotatingSpriteDelta.gd | 1 + .../scene/RotatingSpriteDelta.tscn.tres | 8 ++--- .../scripts/RotatingSpriteDelta.gd.tres | 1 + ...tingSpriteDelta.move_and_rotate.slice.tres | 10 +++--- 14 files changed, 170 insertions(+), 15 deletions(-) create mode 100644 course/lesson-11-time-delta/practice-x0c7DDiz.tres create mode 100644 course/lesson-11-time-delta/rotating-and-moving-delta/RotatingMovingSpriteDelta.gd create mode 100644 course/lesson-11-time-delta/rotating-and-moving-delta/RotatingMovingSpriteDelta.live-editor/scene/RotatingMovingSpriteDelta.tscn.tres create mode 100644 course/lesson-11-time-delta/rotating-and-moving-delta/RotatingMovingSpriteDelta.live-editor/scripts/RotatingMovingSpriteDelta.gd.tres create mode 100644 course/lesson-11-time-delta/rotating-and-moving-delta/RotatingMovingSpriteDelta.live-editor/slices/RotatingMovingSpriteDelta.move_and_rotate.slice.tres create mode 100644 course/lesson-11-time-delta/rotating-and-moving-delta/RotatingMovingSpriteDelta.tscn create mode 100644 course/lesson-11-time-delta/rotating-and-moving-delta/TestsRotatingMovingDelta.gd diff --git a/course/course-learn-gdscript.tres b/course/course-learn-gdscript.tres index 632514b14..42355afe0 100644 --- a/course/course-learn-gdscript.tres +++ b/course/course-learn-gdscript.tres @@ -15,6 +15,6 @@ [ext_resource path="res://course/lesson-14-multiplying/lesson.tres" type="Resource" id=13] [resource] -script = ExtResource( 1 ) +script = ExtResource( 2 ) title = "Learn GDScript From Zero" lessons = [ ExtResource( 9 ), ExtResource( 4 ), ExtResource( 7 ), ExtResource( 2 ), ExtResource( 10 ), ExtResource( 6 ), ExtResource( 5 ), ExtResource( 3 ), ExtResource( 8 ), ExtResource( 11 ), ExtResource( 12 ), ExtResource( 13 ) ] diff --git a/course/lesson-11-time-delta/lesson.tres b/course/lesson-11-time-delta/lesson.tres index b17dc0dbf..822ec1c1e 100644 --- a/course/lesson-11-time-delta/lesson.tres +++ b/course/lesson-11-time-delta/lesson.tres @@ -1,4 +1,4 @@ -[gd_resource type="Resource" load_steps=18 format=2] +[gd_resource type="Resource" load_steps=19 format=2] [ext_resource path="res://resources/Lesson.gd" type="Script" id=1] [ext_resource path="res://course/lesson-11-time-delta/quiz-HARbBWNb.tres" type="Resource" id=2] @@ -17,9 +17,10 @@ [ext_resource path="res://course/lesson-11-time-delta/content-vGm22rtQ.tres" type="Resource" id=15] [ext_resource path="res://course/lesson-11-time-delta/content-cSrGQgrV.tres" type="Resource" id=16] [ext_resource path="res://course/lesson-11-time-delta/quiz-PRw9clsF.tres" type="Resource" id=17] +[ext_resource path="res://course/lesson-11-time-delta/practice-x0c7DDiz.tres" type="Resource" id=18] [resource] script = ExtResource( 1 ) title = "Time Delta" content_blocks = [ ExtResource( 6 ), ExtResource( 7 ), ExtResource( 4 ), ExtResource( 8 ), ExtResource( 3 ), ExtResource( 2 ), ExtResource( 12 ), ExtResource( 10 ), ExtResource( 13 ), ExtResource( 15 ), ExtResource( 9 ), ExtResource( 11 ), ExtResource( 14 ), ExtResource( 17 ), ExtResource( 16 ) ] -practices = [ ExtResource( 5 ) ] +practices = [ ExtResource( 5 ), ExtResource( 18 ) ] diff --git a/course/lesson-11-time-delta/practice-UdOCQiGj.tres b/course/lesson-11-time-delta/practice-UdOCQiGj.tres index 91eb32dc6..c17c2e4ea 100644 --- a/course/lesson-11-time-delta/practice-UdOCQiGj.tres +++ b/course/lesson-11-time-delta/practice-UdOCQiGj.tres @@ -10,11 +10,11 @@ goal = "At the minute, the rotation of the robot is frame-dependent. Add [code]delta[/code] to make the rotational speed time-dependent. -The robot should rotate 2 radians per second." +The robot should rotate [code]2[/code] radians per second." starting_code = "func _process(delta): rotate(2)" -hints = PoolStringArray( "Multiple the radians by [code]delta[/code]." ) +hints = PoolStringArray( "Multiply the radians by [code]delta[/code]" ) validator_script_path = "rotating-using-delta/TestsRotatingDelta.gd" script_slice_path = "rotating-using-delta/RotatingSpriteDelta.live-editor/slices/RotatingSpriteDelta.move_and_rotate.slice.tres" -documentation_references = PoolStringArray( ) +documentation_references = PoolStringArray( "rotate" ) documentation_resource = ExtResource( 2 ) diff --git a/course/lesson-11-time-delta/practice-x0c7DDiz.tres b/course/lesson-11-time-delta/practice-x0c7DDiz.tres new file mode 100644 index 000000000..96d809054 --- /dev/null +++ b/course/lesson-11-time-delta/practice-x0c7DDiz.tres @@ -0,0 +1,18 @@ +[gd_resource type="Resource" load_steps=3 format=2] + +[ext_resource path="res://resources/Practice.gd" type="Script" id=1] +[ext_resource path="res://course/Documentation.tres" type="Resource" id=2] + +[resource] +script = ExtResource( 1 ) +title = "Moving in a Circle Using Delta" +goal = "In this practice, make the robot move in a smooth circle using delta. + +To get this movement, the robot should rotate [code]5[/code] radians per second and move [code]100[/code] pixels per second in the x direction." +starting_code = "func _process(delta): + pass" +hints = PoolStringArray( "Replace [code]pass[/code] with the [code]rotate()[/code] and [code]move_local_x()[/code] functions", "Make sure to multiply each parameter by [code]delta[/code]" ) +validator_script_path = "rotating-and-moving-delta/TestsRotatingMovingDelta.gd" +script_slice_path = "rotating-and-moving-delta/RotatingMovingSpriteDelta.live-editor/slices/RotatingMovingSpriteDelta.move_and_rotate.slice.tres" +documentation_references = PoolStringArray( "rotate", "move_local_x" ) +documentation_resource = ExtResource( 2 ) diff --git a/course/lesson-11-time-delta/rotating-and-moving-delta/RotatingMovingSpriteDelta.gd b/course/lesson-11-time-delta/rotating-and-moving-delta/RotatingMovingSpriteDelta.gd new file mode 100644 index 000000000..3a5f4c887 --- /dev/null +++ b/course/lesson-11-time-delta/rotating-and-moving-delta/RotatingMovingSpriteDelta.gd @@ -0,0 +1,24 @@ +extends Node2D + + +func _ready() -> void: + set_process(false) + + +# EXPORT move_and_rotate +func _process(delta): + rotate(2 * delta) + move_local_x(100 * delta) +# /EXPORT move_and_rotate + + +func _run() -> void: + reset() + _process(0.0) + set_process(true) + + +func reset() -> void: + rotation = 0.0 + position = Vector2(300, 200) + set_process(false) diff --git a/course/lesson-11-time-delta/rotating-and-moving-delta/RotatingMovingSpriteDelta.live-editor/scene/RotatingMovingSpriteDelta.tscn.tres b/course/lesson-11-time-delta/rotating-and-moving-delta/RotatingMovingSpriteDelta.live-editor/scene/RotatingMovingSpriteDelta.tscn.tres new file mode 100644 index 000000000..fded0ca8e --- /dev/null +++ b/course/lesson-11-time-delta/rotating-and-moving-delta/RotatingMovingSpriteDelta.live-editor/scene/RotatingMovingSpriteDelta.tscn.tres @@ -0,0 +1,9 @@ +[gd_resource type="Resource" load_steps=3 format=2] + +[ext_resource path="res://addons/gdscript-slice-exporter/collections/SceneProperties.gd" type="Script" id=1] +[ext_resource path="res://course/lesson-11-time-delta/rotating-and-moving-delta/RotatingMovingSpriteDelta.tscn" type="PackedScene" id=2] + +[resource] +script = ExtResource( 1 ) +scene = ExtResource( 2 ) +viewport_size = Vector2( 1920, 1080 ) diff --git a/course/lesson-11-time-delta/rotating-and-moving-delta/RotatingMovingSpriteDelta.live-editor/scripts/RotatingMovingSpriteDelta.gd.tres b/course/lesson-11-time-delta/rotating-and-moving-delta/RotatingMovingSpriteDelta.live-editor/scripts/RotatingMovingSpriteDelta.gd.tres new file mode 100644 index 000000000..25663383e --- /dev/null +++ b/course/lesson-11-time-delta/rotating-and-moving-delta/RotatingMovingSpriteDelta.live-editor/scripts/RotatingMovingSpriteDelta.gd.tres @@ -0,0 +1,34 @@ +[gd_resource type="Resource" load_steps=3 format=2] + +[ext_resource path="res://addons/gdscript-slice-exporter/collections/ScriptProperties.gd" type="Script" id=1] +[ext_resource path="res://course/lesson-11-time-delta/rotating-and-moving-delta/RotatingMovingSpriteDelta.gd" type="Script" id=2] + +[resource] +script = ExtResource( 1 ) +nodes_paths = [ NodePath("RotatingSprite") ] +script_file = ExtResource( 2 ) +original_script = "extends Node2D + + +func _ready() -> void: + set_process(false) + + +# EXPORT move_and_rotate +func _process(delta): + rotate(2 * delta) + move_local_x(100 * delta) +# /EXPORT move_and_rotate + + +func _run() -> void: + reset() + _process(0.0) + set_process(true) + + +func reset() -> void: + rotation = 0.0 + position = Vector2(300, 200) + set_process(false) +" diff --git a/course/lesson-11-time-delta/rotating-and-moving-delta/RotatingMovingSpriteDelta.live-editor/slices/RotatingMovingSpriteDelta.move_and_rotate.slice.tres b/course/lesson-11-time-delta/rotating-and-moving-delta/RotatingMovingSpriteDelta.live-editor/slices/RotatingMovingSpriteDelta.move_and_rotate.slice.tres new file mode 100644 index 000000000..28bafcd28 --- /dev/null +++ b/course/lesson-11-time-delta/rotating-and-moving-delta/RotatingMovingSpriteDelta.live-editor/slices/RotatingMovingSpriteDelta.move_and_rotate.slice.tres @@ -0,0 +1,20 @@ +[gd_resource type="Resource" load_steps=4 format=2] + +[ext_resource path="res://addons/gdscript-slice-exporter/collections/SliceProperties.gd" type="Script" id=1] +[ext_resource path="res://course/lesson-11-time-delta/rotating-and-moving-delta/RotatingMovingSpriteDelta.live-editor/scene/RotatingMovingSpriteDelta.tscn.tres" type="Resource" id=2] +[ext_resource path="res://course/lesson-11-time-delta/rotating-and-moving-delta/RotatingMovingSpriteDelta.live-editor/scripts/RotatingMovingSpriteDelta.gd.tres" type="Resource" id=3] + +[resource] +script = ExtResource( 1 ) +scene_properties = ExtResource( 2 ) +script_properties = ExtResource( 3 ) +leading_spaces = 0 +keyword = "EXPORT" +closing = false +name = "move_and_rotate" +is_full_file = false +start = 7 +end = 11 +lines_before = [ "extends Node2D", "", "", "func _ready() -> void:", " set_process(false)", "", "" ] +lines_after = [ "", "", "func _run() -> void:", " reset()", " _process(0.0)", " set_process(true)", "", "", "func reset() -> void:", " rotation = 0.0", " position = Vector2(300, 200)", " set_process(false)", "" ] +lines_editable = [ "func _process(delta):", " rotate(2 * delta)", " move_local_x(100 * delta)" ] diff --git a/course/lesson-11-time-delta/rotating-and-moving-delta/RotatingMovingSpriteDelta.tscn b/course/lesson-11-time-delta/rotating-and-moving-delta/RotatingMovingSpriteDelta.tscn new file mode 100644 index 000000000..0abf79c4d --- /dev/null +++ b/course/lesson-11-time-delta/rotating-and-moving-delta/RotatingMovingSpriteDelta.tscn @@ -0,0 +1,26 @@ +[gd_scene load_steps=4 format=2] + +[ext_resource path="res://course/lesson-11-time-delta/rotating-and-moving-delta/RotatingMovingSpriteDelta.gd" type="Script" id=1] +[ext_resource path="res://course/lesson-1-what-code-is-like/first_practice/hand_ice.png" type="Texture" id=2] +[ext_resource path="res://course/lesson-1-what-code-is-like/first_practice/godot_bottom.png" type="Texture" id=3] + +[node name="Position2D" type="Position2D"] + +[node name="RotatingSprite" type="Node2D" parent="."] +position = Vector2( 300, 200 ) +script = ExtResource( 1 ) + +[node name="GodotBottom" type="Sprite" parent="RotatingSprite"] +position = Vector2( 0, -17 ) +texture = ExtResource( 3 ) + +[node name="HandIce" type="Sprite" parent="RotatingSprite"] +position = Vector2( 66, 14 ) +rotation = 0.36894 +texture = ExtResource( 2 ) + +[node name="HandIce2" type="Sprite" parent="RotatingSprite"] +position = Vector2( -65, 19 ) +rotation = -0.483649 +texture = ExtResource( 2 ) +flip_h = true diff --git a/course/lesson-11-time-delta/rotating-and-moving-delta/TestsRotatingMovingDelta.gd b/course/lesson-11-time-delta/rotating-and-moving-delta/TestsRotatingMovingDelta.gd new file mode 100644 index 000000000..8fc0cf6f7 --- /dev/null +++ b/course/lesson-11-time-delta/rotating-and-moving-delta/TestsRotatingMovingDelta.gd @@ -0,0 +1,21 @@ +extends PracticeTester + + +func test_moving_in_a_circle_is_time_dependent() -> String: + var has_delta := _slice.current_text.rfind("delta") > 0 + var has_spaces := _slice.current_text.rfind(" * ") > 0 + var has_two := _slice.current_text.rfind("2") > 0 + var has_hundred := _slice.current_text.rfind("100") > 0 + + if not has_delta: + return "Did you use delta to make the rotation time-dependent?" + elif not has_two: + return "Is the rotation speed correct?" + elif not has_hundred: + return "Is the movement speed correct?" + elif not has_spaces: + return "Did you use spaces between *?" + elif not _slice.current_text.match(_slice.get_slice_text()): + return "There's something wrong here." + + return "" diff --git a/course/lesson-11-time-delta/rotating-using-delta/RotatingSpriteDelta.gd b/course/lesson-11-time-delta/rotating-using-delta/RotatingSpriteDelta.gd index 0162dbcf4..2d8b01ee9 100644 --- a/course/lesson-11-time-delta/rotating-using-delta/RotatingSpriteDelta.gd +++ b/course/lesson-11-time-delta/rotating-using-delta/RotatingSpriteDelta.gd @@ -19,4 +19,5 @@ func _run() -> void: func reset() -> void: rotation = 0.0 + position = Vector2(300, 200) set_process(false) diff --git a/course/lesson-11-time-delta/rotating-using-delta/RotatingSpriteDelta.live-editor/scene/RotatingSpriteDelta.tscn.tres b/course/lesson-11-time-delta/rotating-using-delta/RotatingSpriteDelta.live-editor/scene/RotatingSpriteDelta.tscn.tres index 92edad24c..0250903da 100644 --- a/course/lesson-11-time-delta/rotating-using-delta/RotatingSpriteDelta.live-editor/scene/RotatingSpriteDelta.tscn.tres +++ b/course/lesson-11-time-delta/rotating-using-delta/RotatingSpriteDelta.live-editor/scene/RotatingSpriteDelta.tscn.tres @@ -1,9 +1,9 @@ [gd_resource type="Resource" load_steps=3 format=2] -[ext_resource path="res://course/lesson-11-time-delta/rotating-using-delta/RotatingSpriteDelta.tscn" type="PackedScene" id=1] -[ext_resource path="res://addons/gdscript-slice-exporter/collections/SceneProperties.gd" type="Script" id=2] +[ext_resource path="res://addons/gdscript-slice-exporter/collections/SceneProperties.gd" type="Script" id=1] +[ext_resource path="res://course/lesson-11-time-delta/rotating-using-delta/RotatingSpriteDelta.tscn" type="PackedScene" id=2] [resource] -script = ExtResource( 2 ) -scene = ExtResource( 1 ) +script = ExtResource( 1 ) +scene = ExtResource( 2 ) viewport_size = Vector2( 1920, 1080 ) diff --git a/course/lesson-11-time-delta/rotating-using-delta/RotatingSpriteDelta.live-editor/scripts/RotatingSpriteDelta.gd.tres b/course/lesson-11-time-delta/rotating-using-delta/RotatingSpriteDelta.live-editor/scripts/RotatingSpriteDelta.gd.tres index 8d67a9493..1eecddd07 100644 --- a/course/lesson-11-time-delta/rotating-using-delta/RotatingSpriteDelta.live-editor/scripts/RotatingSpriteDelta.gd.tres +++ b/course/lesson-11-time-delta/rotating-using-delta/RotatingSpriteDelta.live-editor/scripts/RotatingSpriteDelta.gd.tres @@ -28,5 +28,6 @@ func _run() -> void: func reset() -> void: rotation = 0.0 + position = Vector2(300, 200) set_process(false) " diff --git a/course/lesson-11-time-delta/rotating-using-delta/RotatingSpriteDelta.live-editor/slices/RotatingSpriteDelta.move_and_rotate.slice.tres b/course/lesson-11-time-delta/rotating-using-delta/RotatingSpriteDelta.live-editor/slices/RotatingSpriteDelta.move_and_rotate.slice.tres index c1edc0ce9..0e0202772 100644 --- a/course/lesson-11-time-delta/rotating-using-delta/RotatingSpriteDelta.live-editor/slices/RotatingSpriteDelta.move_and_rotate.slice.tres +++ b/course/lesson-11-time-delta/rotating-using-delta/RotatingSpriteDelta.live-editor/slices/RotatingSpriteDelta.move_and_rotate.slice.tres @@ -1,13 +1,13 @@ [gd_resource type="Resource" load_steps=4 format=2] -[ext_resource path="res://course/lesson-11-time-delta/rotating-using-delta/RotatingSpriteDelta.live-editor/scripts/RotatingSpriteDelta.gd.tres" type="Resource" id=1] +[ext_resource path="res://addons/gdscript-slice-exporter/collections/SliceProperties.gd" type="Script" id=1] [ext_resource path="res://course/lesson-11-time-delta/rotating-using-delta/RotatingSpriteDelta.live-editor/scene/RotatingSpriteDelta.tscn.tres" type="Resource" id=2] -[ext_resource path="res://addons/gdscript-slice-exporter/collections/SliceProperties.gd" type="Script" id=3] +[ext_resource path="res://course/lesson-11-time-delta/rotating-using-delta/RotatingSpriteDelta.live-editor/scripts/RotatingSpriteDelta.gd.tres" type="Resource" id=3] [resource] -script = ExtResource( 3 ) +script = ExtResource( 1 ) scene_properties = ExtResource( 2 ) -script_properties = ExtResource( 1 ) +script_properties = ExtResource( 3 ) leading_spaces = 0 keyword = "EXPORT" closing = false @@ -16,5 +16,5 @@ is_full_file = false start = 7 end = 10 lines_before = [ "extends Node2D", "", "", "func _ready() -> void:", " set_process(false)", "", "" ] -lines_after = [ "", "", "func _run() -> void:", " reset()", " _process(0.0)", " set_process(true)", "", "", "func reset() -> void:", " rotation = 0.0", " set_process(false)", "" ] +lines_after = [ "", "", "func _run() -> void:", " reset()", " _process(0.0)", " set_process(true)", "", "", "func reset() -> void:", " rotation = 0.0", " position = Vector2(300, 200)", " set_process(false)", "" ] lines_editable = [ "func _process(delta):", " rotate(2 * delta)" ] From edb6e95982fb01510eb45949ffa60256fda824e7 Mon Sep 17 00:00:00 2001 From: Xananax Date: Tue, 11 Jan 2022 01:09:20 +0400 Subject: [PATCH 16/21] improvement: stylistic changes to lessons 10 & 11 --- course/course-learn-gdscript.tres | 2 +- .../content-RHJMQ2XN.tres | 2 +- .../content-pPwQDwfy.tres | 4 ++-- .../content-tT6n1Txl.tres | 4 ++-- .../practice-QiGjB7tK.tres | 2 +- .../lesson-11-time-delta/content-B7tKRHJM.tres | 16 ++++++++++++++++ .../lesson-11-time-delta/content-DGt6fUqb.tres | 12 ++++++------ .../lesson-11-time-delta/content-En91c9ll.tres | 4 +++- .../lesson-11-time-delta/content-N4rS5AJT.tres | 8 +++----- .../lesson-11-time-delta/content-TLtZixQO.tres | 10 ++-------- .../lesson-11-time-delta/content-qE82V6jG.tres | 10 ++++++++-- course/lesson-11-time-delta/lesson.tres | 5 +++-- 12 files changed, 48 insertions(+), 31 deletions(-) create mode 100644 course/lesson-11-time-delta/content-B7tKRHJM.tres diff --git a/course/course-learn-gdscript.tres b/course/course-learn-gdscript.tres index 42355afe0..632514b14 100644 --- a/course/course-learn-gdscript.tres +++ b/course/course-learn-gdscript.tres @@ -15,6 +15,6 @@ [ext_resource path="res://course/lesson-14-multiplying/lesson.tres" type="Resource" id=13] [resource] -script = ExtResource( 2 ) +script = ExtResource( 1 ) title = "Learn GDScript From Zero" lessons = [ ExtResource( 9 ), ExtResource( 4 ), ExtResource( 7 ), ExtResource( 2 ), ExtResource( 10 ), ExtResource( 6 ), ExtResource( 5 ), ExtResource( 3 ), ExtResource( 8 ), ExtResource( 11 ), ExtResource( 12 ), ExtResource( 13 ) ] diff --git a/course/lesson-10-the-game-loop/content-RHJMQ2XN.tres b/course/lesson-10-the-game-loop/content-RHJMQ2XN.tres index b79c5f79c..cccd06acd 100644 --- a/course/lesson-10-the-game-loop/content-RHJMQ2XN.tres +++ b/course/lesson-10-the-game-loop/content-RHJMQ2XN.tres @@ -6,7 +6,7 @@ script = ExtResource( 1 ) text = "The [code]_process()[/code] function gets its name because it does calculations or continuous actions. -It's like a factory that [b]processes[/b] food; the food is always moving along a conveyer belt." +It's like a juice factory that [b]processes[/b] juice bottles; the bottles are always moving along a conveyor belt, while different machines operate on them." visual_element_path = "" reverse_blocks = false type = 0 diff --git a/course/lesson-10-the-game-loop/content-pPwQDwfy.tres b/course/lesson-10-the-game-loop/content-pPwQDwfy.tres index 081bbd312..4eb848f86 100644 --- a/course/lesson-10-the-game-loop/content-pPwQDwfy.tres +++ b/course/lesson-10-the-game-loop/content-pPwQDwfy.tres @@ -6,9 +6,9 @@ script = ExtResource( 1 ) text = "The [code]_process()[/code] function won't do anything until we add something to it. -You might notice the underscore [code]_[/code] in front of the function name. This means the function is built into Godot. Because it's already there, we can add to it. +You might notice the underscore [code]_[/code] in front of the function name. This is a convention. It means the function is already defined by Godot. -Using an underscore in this way is common in lots of languages to show developers they can add to the function." +If the function exists, and is called exactly [code]_process[/code], then Godot will automatically run it every frame. " visual_element_path = "" reverse_blocks = false type = 0 diff --git a/course/lesson-10-the-game-loop/content-tT6n1Txl.tres b/course/lesson-10-the-game-loop/content-tT6n1Txl.tres index 8f0fd4600..c2cf93412 100644 --- a/course/lesson-10-the-game-loop/content-tT6n1Txl.tres +++ b/course/lesson-10-the-game-loop/content-tT6n1Txl.tres @@ -4,9 +4,9 @@ [resource] script = ExtResource( 1 ) -text = "We've added to the character's [code]_process()[/code] function so that it continuously rotates. +text = "Every frame, Godot runs the [code]_process()[/code] function. -Godot is rotating the character by [code]0.05[/code] radians [b]many[/b] times a second." +Since we wrote a [code]rotate()[/code] instruction, Godot is rotating the character by [code]0.05[/code] radians [b]many[/b] times a second." visual_element_path = "" reverse_blocks = false type = 0 diff --git a/course/lesson-10-the-game-loop/practice-QiGjB7tK.tres b/course/lesson-10-the-game-loop/practice-QiGjB7tK.tres index 1c860c649..9d95c6a9e 100644 --- a/course/lesson-10-the-game-loop/practice-QiGjB7tK.tres +++ b/course/lesson-10-the-game-loop/practice-QiGjB7tK.tres @@ -6,7 +6,7 @@ [resource] script = ExtResource( 1 ) title = "Creating Circular Movement" -goal = "Make the robot move in a circle slowly by rotating it, then moving it in the x direction. +goal = "Make the robot move in a large circle slowly by rotating it and simultaneously moving it along its x direction. To do this, add the [code]rotate()[/code] and [code]move_local_x()[/code] functions to [code]_process()[/code]. diff --git a/course/lesson-11-time-delta/content-B7tKRHJM.tres b/course/lesson-11-time-delta/content-B7tKRHJM.tres new file mode 100644 index 000000000..cf3369f6e --- /dev/null +++ b/course/lesson-11-time-delta/content-B7tKRHJM.tres @@ -0,0 +1,16 @@ +[gd_resource type="Resource" load_steps=2 format=2] + +[ext_resource path="res://resources/ContentBlock.gd" type="Script" id=1] + +[resource] +script = ExtResource( 1 ) +text = "Remember! [code]delta[/code] is [b]very small[/b]. In case your Maths is rusty, here are a few examples of multiplications by very small numbers: + +- [code]2 * 0.5 = 1[/code] +- [code]10 * 0.2 = 2[/code] +- [code]1 * 0.01 = 0.01[/code] + +Since delta is often something like [code]0.016667[/code], you should expect numbers to become [b]smaller[/b] when you multiply by it. " +visual_element_path = "" +reverse_blocks = false +type = 2 diff --git a/course/lesson-11-time-delta/content-DGt6fUqb.tres b/course/lesson-11-time-delta/content-DGt6fUqb.tres index aac26a0fc..506203190 100644 --- a/course/lesson-11-time-delta/content-DGt6fUqb.tres +++ b/course/lesson-11-time-delta/content-DGt6fUqb.tres @@ -4,17 +4,17 @@ [resource] script = ExtResource( 1 ) -text = "In mathematics, delta is often used to describe a very small change in something. +text = "[font=res://ui/theme/fonts/font_title.tres]Frames Time Variance[/font] -We know that Godot runs all the [code]_process()[/code] functions as fast as it can. +Your computer controls the speed at which each software runs. Depending on how busy the computer is, this can vary. -The parameter [code]delta[/code] is how fast in seconds Godot took to complete the [b]previous frame[/b]. +For that reason, no game engine can guarantee a constant framerate. There will always be milliseconds variations from frame to frame. -Because lots of different things happen at different times in games, Godot might take more or less time to complete one frame. +That is why the [code]_process()[/code] function receives a [code]delta[/code] parameter. -For example, the player might fire lots of bullets at once, and now Godot has all of these bullets to process! +In mathematics, the word \"delta\" is often used to describe a very small change between two numbers. -This means that [code]delta[/code] also varies." +The [code]delta[/code] parameter tells us how fast Godot took to complete the [b]previous frame[/b]. We can use that to ensure that the variations between frames have no visible effect." visual_element_path = "" reverse_blocks = false type = 0 diff --git a/course/lesson-11-time-delta/content-En91c9ll.tres b/course/lesson-11-time-delta/content-En91c9ll.tres index f82325f33..96a403778 100644 --- a/course/lesson-11-time-delta/content-En91c9ll.tres +++ b/course/lesson-11-time-delta/content-En91c9ll.tres @@ -4,7 +4,9 @@ [resource] script = ExtResource( 1 ) -text = "However, if we use [code]delta[/code] to compensate, we get a smoother animation." +text = "In this second example, we set an [b]different rotation[/b] every frame, adjusting the character's rotation based on [code]delta[/code]. + +Thanks to that, we get a [b]constant rotation[/b] per second. The character seems to rotate at a regular speed." visual_element_path = "" reverse_blocks = false type = 0 diff --git a/course/lesson-11-time-delta/content-N4rS5AJT.tres b/course/lesson-11-time-delta/content-N4rS5AJT.tres index 600bd3f42..b66c72288 100644 --- a/course/lesson-11-time-delta/content-N4rS5AJT.tres +++ b/course/lesson-11-time-delta/content-N4rS5AJT.tres @@ -10,13 +10,11 @@ Godot runs each [code]_process()[/code] function as fast as it can. When Godot has run every [code]_process()[/code] function in the game, it has completed one game loop, or [b]frame[/b]. -Godot then moves on to the next frame. +Godot then moves on to the next frame. This runs very fast, giving us the illusion of movement. This is similar to how movies or animations work, which is why we use the word [b]frame[/b]. -And this can happen many, many times a second! +And this happens many, many times a second! -This is how we get fluid motion in games. - -In many ways, each frame is like a page in a flip book." +This is how we get fluid motion in games. " visual_element_path = "" reverse_blocks = false type = 0 diff --git a/course/lesson-11-time-delta/content-TLtZixQO.tres b/course/lesson-11-time-delta/content-TLtZixQO.tres index e2ce65001..f38c92057 100644 --- a/course/lesson-11-time-delta/content-TLtZixQO.tres +++ b/course/lesson-11-time-delta/content-TLtZixQO.tres @@ -4,15 +4,9 @@ [resource] script = ExtResource( 1 ) -text = "Rather than jumping the full amount every frame, we rotate the character by part of the value based on the [code]delta[/code]. +text = "If the frame is fast (0.1s), we only rotate a little. When the frame is slow (0.2s), we rotate more to compensate. -These values are bigger because [code]delta[/code] is so small. - -By multiplying 1 radians by [code]delta[/code], we rotate the character by 1 radian per second. - -We've slowed the above down to see the difference easier. - -When we multiply time sensitive values like this, we make them [b]time-dependent[/b] rather than [b]frame-dependent[/b]." +Multiplying time sensitive values by delta makes them [b]time-dependent[/b] rather than [b]frame-dependent[/b]." visual_element_path = "" reverse_blocks = false type = 0 diff --git a/course/lesson-11-time-delta/content-qE82V6jG.tres b/course/lesson-11-time-delta/content-qE82V6jG.tres index 0956405c3..243230f30 100644 --- a/course/lesson-11-time-delta/content-qE82V6jG.tres +++ b/course/lesson-11-time-delta/content-qE82V6jG.tres @@ -4,9 +4,15 @@ [resource] script = ExtResource( 1 ) -text = "What would happen if our computer slows down or has irregular frame times? +text = "[font=res://ui/theme/fonts/font_title.tres]Why Does Frame Variance Matter?[/font] -Without [code]delta[/code], we'd get an irregular animation because the movement is dependent on frames." +What would happen if our computer slows down or has irregular frame times? + +In the examples below, we artificially made the frames last different times. Some last 0.1 seconds, some 0.2 seconds. + +In the first example, we use the [b]same rotation[/b] every frame. + +But since the frames are unequal, we get a [b]varying rotation[/b] per second. Because of that, the character seems to jump." visual_element_path = "" reverse_blocks = false type = 0 diff --git a/course/lesson-11-time-delta/lesson.tres b/course/lesson-11-time-delta/lesson.tres index 822ec1c1e..227a29f66 100644 --- a/course/lesson-11-time-delta/lesson.tres +++ b/course/lesson-11-time-delta/lesson.tres @@ -1,4 +1,4 @@ -[gd_resource type="Resource" load_steps=19 format=2] +[gd_resource type="Resource" load_steps=20 format=2] [ext_resource path="res://resources/Lesson.gd" type="Script" id=1] [ext_resource path="res://course/lesson-11-time-delta/quiz-HARbBWNb.tres" type="Resource" id=2] @@ -18,9 +18,10 @@ [ext_resource path="res://course/lesson-11-time-delta/content-cSrGQgrV.tres" type="Resource" id=16] [ext_resource path="res://course/lesson-11-time-delta/quiz-PRw9clsF.tres" type="Resource" id=17] [ext_resource path="res://course/lesson-11-time-delta/practice-x0c7DDiz.tres" type="Resource" id=18] +[ext_resource path="res://course/lesson-11-time-delta/content-B7tKRHJM.tres" type="Resource" id=19] [resource] script = ExtResource( 1 ) title = "Time Delta" -content_blocks = [ ExtResource( 6 ), ExtResource( 7 ), ExtResource( 4 ), ExtResource( 8 ), ExtResource( 3 ), ExtResource( 2 ), ExtResource( 12 ), ExtResource( 10 ), ExtResource( 13 ), ExtResource( 15 ), ExtResource( 9 ), ExtResource( 11 ), ExtResource( 14 ), ExtResource( 17 ), ExtResource( 16 ) ] +content_blocks = [ ExtResource( 6 ), ExtResource( 7 ), ExtResource( 4 ), ExtResource( 8 ), ExtResource( 3 ), ExtResource( 2 ), ExtResource( 12 ), ExtResource( 10 ), ExtResource( 13 ), ExtResource( 15 ), ExtResource( 9 ), ExtResource( 11 ), ExtResource( 14 ), ExtResource( 19 ), ExtResource( 17 ), ExtResource( 16 ) ] practices = [ ExtResource( 5 ), ExtResource( 18 ) ] From f244f649bc870d38fbcfafd0a23bc6bb4bd07645 Mon Sep 17 00:00:00 2001 From: Xananax Date: Tue, 11 Jan 2022 01:10:03 +0400 Subject: [PATCH 17/21] improvement: show framerate & rotation on examples --- .../visuals/DemoRotatingSpriteFrame.gd | 19 +++++++++---- .../visuals/DemoRotatingSpriteFrame.tscn | 27 ++++++++++++++++--- .../visuals/DemoRotatingTime.gd | 19 +++++++++---- .../visuals/DemoRotatingTime.tscn | 27 ++++++++++++++++--- 4 files changed, 76 insertions(+), 16 deletions(-) diff --git a/course/lesson-11-time-delta/visuals/DemoRotatingSpriteFrame.gd b/course/lesson-11-time-delta/visuals/DemoRotatingSpriteFrame.gd index 297a94880..d9e897894 100644 --- a/course/lesson-11-time-delta/visuals/DemoRotatingSpriteFrame.gd +++ b/course/lesson-11-time-delta/visuals/DemoRotatingSpriteFrame.gd @@ -1,14 +1,23 @@ extends Node2D -var _times := [0.1, 0.1, 0.2, 0.1, 0.2] +const _times := preload("./DemoRotatingTime.gd")._times; var _index := 0 -onready var _timer := $Timer -onready var _sprite := $DemoRotateSprite +onready var _timer := $Timer as Timer +onready var _sprite := $DemoRotateSprite as Node2D +onready var _label_rotation := $LabelRotation as Label +onready var _label_frame := $LabelFrame as Label +func _ready(): + _on_Timer_timeout() func _on_Timer_timeout(): - _sprite.rotate(0.2) - _timer.start(_times[_index]) + var rotation_amount := 0.2; + var frame_speed:float = _times[_index] + _sprite.rotate(rotation_amount) + _timer.start(frame_speed) + + _label_rotation.text = "rotation: %s"%[rotation_amount] + _label_frame.text = "frame speed: %s"%[frame_speed] _index = wrapi(_index + 1, 0, _times.size() - 1) diff --git a/course/lesson-11-time-delta/visuals/DemoRotatingSpriteFrame.tscn b/course/lesson-11-time-delta/visuals/DemoRotatingSpriteFrame.tscn index d58707606..0be12167b 100644 --- a/course/lesson-11-time-delta/visuals/DemoRotatingSpriteFrame.tscn +++ b/course/lesson-11-time-delta/visuals/DemoRotatingSpriteFrame.tscn @@ -1,8 +1,9 @@ -[gd_scene load_steps=4 format=2] +[gd_scene load_steps=5 format=2] [ext_resource path="res://course/lesson-11-time-delta/visuals/DemoRotatingSpriteFrame.gd" type="Script" id=1] [ext_resource path="res://course/lesson-1-what-code-is-like/first_practice/godot_bottom.png" type="Texture" id=2] [ext_resource path="res://course/lesson-1-what-code-is-like/first_practice/hand_ice.png" type="Texture" id=3] +[ext_resource path="res://ui/theme/gdscript_app_theme.tres" type="Theme" id=4] [node name="Node2D" type="Node2D"] script = ExtResource( 1 ) @@ -25,7 +26,27 @@ texture = ExtResource( 3 ) flip_h = true [node name="Timer" type="Timer" parent="."] -wait_time = 0.1 -autostart = true + +[node name="LabelRotation" type="Label" parent="."] +margin_left = -127.0 +margin_top = -94.0 +margin_right = 55.0 +margin_bottom = -66.0 +theme = ExtResource( 4 ) +text = "rotation: 0" +__meta__ = { +"_edit_use_anchors_": false +} + +[node name="LabelFrame" type="Label" parent="."] +margin_left = -127.0 +margin_top = -118.0 +margin_right = 55.0 +margin_bottom = -90.0 +theme = ExtResource( 4 ) +text = "frame speed: 0" +__meta__ = { +"_edit_use_anchors_": false +} [connection signal="timeout" from="Timer" to="." method="_on_Timer_timeout"] diff --git a/course/lesson-11-time-delta/visuals/DemoRotatingTime.gd b/course/lesson-11-time-delta/visuals/DemoRotatingTime.gd index 191032198..ee0792eed 100644 --- a/course/lesson-11-time-delta/visuals/DemoRotatingTime.gd +++ b/course/lesson-11-time-delta/visuals/DemoRotatingTime.gd @@ -1,14 +1,23 @@ extends Node2D -var _times := [0.1, 0.1, 0.2, 0.1, 0.2] +const _times := [0.1, 0.1, 0.2, 0.1, 0.2] var _index := 0 -onready var _timer := $Timer -onready var _sprite := $DemoRotateSprite +onready var _timer := $Timer as Timer +onready var _sprite := $DemoRotateSprite as Node2D +onready var _label_rotation := $LabelRotation as Label +onready var _label_frame := $LabelFrame as Label +func _ready(): + _on_Timer_timeout() func _on_Timer_timeout(): - _sprite.rotate(1 * _timer.wait_time) - _timer.start(_times[_index]) + var rotation_amount := 1 * _timer.wait_time; + var frame_speed:float = _times[_index] + _sprite.rotate(rotation_amount) + _timer.start(frame_speed) + + _label_rotation.text = "rotation: %s"%[rotation_amount] + _label_frame.text = "frame speed: %s"%[frame_speed] _index = wrapi(_index + 1, 0, _times.size() - 1) diff --git a/course/lesson-11-time-delta/visuals/DemoRotatingTime.tscn b/course/lesson-11-time-delta/visuals/DemoRotatingTime.tscn index c8423664d..7d2219b93 100644 --- a/course/lesson-11-time-delta/visuals/DemoRotatingTime.tscn +++ b/course/lesson-11-time-delta/visuals/DemoRotatingTime.tscn @@ -1,8 +1,9 @@ -[gd_scene load_steps=4 format=2] +[gd_scene load_steps=5 format=2] [ext_resource path="res://course/lesson-11-time-delta/visuals/DemoRotatingTime.gd" type="Script" id=1] [ext_resource path="res://course/lesson-1-what-code-is-like/first_practice/godot_bottom.png" type="Texture" id=2] [ext_resource path="res://course/lesson-1-what-code-is-like/first_practice/hand_ice.png" type="Texture" id=3] +[ext_resource path="res://ui/theme/gdscript_app_theme.tres" type="Theme" id=4] [node name="Node2D" type="Node2D"] script = ExtResource( 1 ) @@ -25,7 +26,27 @@ texture = ExtResource( 3 ) flip_h = true [node name="Timer" type="Timer" parent="."] -wait_time = 0.1 -autostart = true + +[node name="LabelRotation" type="Label" parent="."] +margin_left = -135.0 +margin_top = -94.0 +margin_right = 47.0 +margin_bottom = -66.0 +theme = ExtResource( 4 ) +text = "rotation: 0" +__meta__ = { +"_edit_use_anchors_": false +} + +[node name="LabelFrame" type="Label" parent="."] +margin_left = -135.0 +margin_top = -118.0 +margin_right = 47.0 +margin_bottom = -90.0 +theme = ExtResource( 4 ) +text = "frame speed: 0" +__meta__ = { +"_edit_use_anchors_": false +} [connection signal="timeout" from="Timer" to="." method="_on_Timer_timeout"] From 2b011d2fc761c32afc0b6d88206fdeb59f7cb4d2 Mon Sep 17 00:00:00 2001 From: johnnygossdev Date: Sun, 16 Jan 2022 17:00:08 +0000 Subject: [PATCH 18/21] improvement: add better delta visual --- course/course-learn-gdscript.tres | 2 +- .../content-5AJTESv5.tres | 4 +- .../content-DizKUdOC.tres | 4 +- .../content-QiGjB7tK.tres | 4 +- .../content-RHJMQ2XN.tres | 4 +- .../content-TRhZN4rS.tres | 4 +- .../content-ZPxY8VUD.tres | 4 +- .../content-bTxYej47.tres | 4 +- .../content-otxF5HUx.tres | 4 +- .../content-pPwQDwfy.tres | 4 +- .../content-tT6n1Txl.tres | 4 +- .../practice-QiGjB7tK.tres | 1 + .../practice-tKRHJMQ2.tres | 1 + .../content-1TxlTtcy.tres | 4 +- .../content-B7tKRHJM.tres | 4 +- .../content-DGt6fUqb.tres | 4 +- .../content-DwfyqdYO.tres | 4 +- .../content-En91c9ll.tres | 4 +- .../content-Gx0c7DDi.tres | 12 ++ .../content-N4rS5AJT.tres | 4 +- .../content-TLtZixQO.tres | 4 +- .../content-cSrGQgrV.tres | 4 +- .../content-exRjTRhZ.tres | 4 +- .../content-f8B67UJ8.tres | 4 +- .../content-hcIb5BnV.tres | 4 +- .../content-qE82V6jG.tres | 8 +- course/lesson-11-time-delta/lesson.tres | 7 +- .../practice-UdOCQiGj.tres | 1 + .../practice-x0c7DDiz.tres | 1 + .../visuals/DemoRobotRace.gd | 9 + .../visuals/DemoRobotRace.tscn | 39 ++++ .../lesson-11-time-delta/visuals/RobotRace.gd | 24 +++ .../visuals/RobotRace.tscn | 166 ++++++++++++++++++ .../visuals/RunningRobot.gd | 16 ++ .../visuals/RunningRobot.tscn | 11 ++ 35 files changed, 352 insertions(+), 30 deletions(-) create mode 100644 course/lesson-11-time-delta/content-Gx0c7DDi.tres create mode 100644 course/lesson-11-time-delta/visuals/DemoRobotRace.gd create mode 100644 course/lesson-11-time-delta/visuals/DemoRobotRace.tscn create mode 100644 course/lesson-11-time-delta/visuals/RobotRace.gd create mode 100644 course/lesson-11-time-delta/visuals/RobotRace.tscn create mode 100644 course/lesson-11-time-delta/visuals/RunningRobot.gd create mode 100644 course/lesson-11-time-delta/visuals/RunningRobot.tscn diff --git a/course/course-learn-gdscript.tres b/course/course-learn-gdscript.tres index 632514b14..42355afe0 100644 --- a/course/course-learn-gdscript.tres +++ b/course/course-learn-gdscript.tres @@ -15,6 +15,6 @@ [ext_resource path="res://course/lesson-14-multiplying/lesson.tres" type="Resource" id=13] [resource] -script = ExtResource( 1 ) +script = ExtResource( 2 ) title = "Learn GDScript From Zero" lessons = [ ExtResource( 9 ), ExtResource( 4 ), ExtResource( 7 ), ExtResource( 2 ), ExtResource( 10 ), ExtResource( 6 ), ExtResource( 5 ), ExtResource( 3 ), ExtResource( 8 ), ExtResource( 11 ), ExtResource( 12 ), ExtResource( 13 ) ] diff --git a/course/lesson-10-the-game-loop/content-5AJTESv5.tres b/course/lesson-10-the-game-loop/content-5AJTESv5.tres index 4d7c9a5ef..6a12d130b 100644 --- a/course/lesson-10-the-game-loop/content-5AJTESv5.tres +++ b/course/lesson-10-the-game-loop/content-5AJTESv5.tres @@ -4,7 +4,9 @@ [resource] script = ExtResource( 1 ) +title = "" +type = 0 text = "" visual_element_path = "visuals/ExampleRotatingSprite.tscn" reverse_blocks = false -type = 0 +has_separator = false diff --git a/course/lesson-10-the-game-loop/content-DizKUdOC.tres b/course/lesson-10-the-game-loop/content-DizKUdOC.tres index b52f2fd4b..a04a94861 100644 --- a/course/lesson-10-the-game-loop/content-DizKUdOC.tres +++ b/course/lesson-10-the-game-loop/content-DizKUdOC.tres @@ -4,6 +4,8 @@ [resource] script = ExtResource( 1 ) +title = "" +type = 0 text = "As we've seen, Godot has functions that do certain actions. For example, the [code]show()[/code] and [code]hide()[/code] functions change the visibility of things. We can also create our own functions to make custom effects like adding or removing health to a character. @@ -13,4 +15,4 @@ Godot also has special functions we can customise or add to. Take the [code]_process()[/code] function." visual_element_path = "" reverse_blocks = false -type = 0 +has_separator = false diff --git a/course/lesson-10-the-game-loop/content-QiGjB7tK.tres b/course/lesson-10-the-game-loop/content-QiGjB7tK.tres index 34762831f..91082d061 100644 --- a/course/lesson-10-the-game-loop/content-QiGjB7tK.tres +++ b/course/lesson-10-the-game-loop/content-QiGjB7tK.tres @@ -4,7 +4,9 @@ [resource] script = ExtResource( 1 ) +title = "" +type = 0 text = "" visual_element_path = "visuals/ExampleProcessFunction.tscn" reverse_blocks = false -type = 0 +has_separator = false diff --git a/course/lesson-10-the-game-loop/content-RHJMQ2XN.tres b/course/lesson-10-the-game-loop/content-RHJMQ2XN.tres index cccd06acd..dbd599bab 100644 --- a/course/lesson-10-the-game-loop/content-RHJMQ2XN.tres +++ b/course/lesson-10-the-game-loop/content-RHJMQ2XN.tres @@ -4,9 +4,11 @@ [resource] script = ExtResource( 1 ) +title = "" +type = 0 text = "The [code]_process()[/code] function gets its name because it does calculations or continuous actions. It's like a juice factory that [b]processes[/b] juice bottles; the bottles are always moving along a conveyor belt, while different machines operate on them." visual_element_path = "" reverse_blocks = false -type = 0 +has_separator = false diff --git a/course/lesson-10-the-game-loop/content-TRhZN4rS.tres b/course/lesson-10-the-game-loop/content-TRhZN4rS.tres index 4037d7e08..356b9ccfe 100644 --- a/course/lesson-10-the-game-loop/content-TRhZN4rS.tres +++ b/course/lesson-10-the-game-loop/content-TRhZN4rS.tres @@ -4,6 +4,8 @@ [resource] script = ExtResource( 1 ) +title = "" +type = 0 text = "[font=res://ui/theme/fonts/font_title.tres]Why is [code]_process()[/code] useful?[/font] It's perhaps better to see the [code]_process()[/code] function in action. @@ -11,4 +13,4 @@ It's perhaps better to see the [code]_process()[/code] function in action. Take the following example." visual_element_path = "" reverse_blocks = false -type = 0 +has_separator = false diff --git a/course/lesson-10-the-game-loop/content-ZPxY8VUD.tres b/course/lesson-10-the-game-loop/content-ZPxY8VUD.tres index 23f7a459d..f59be1985 100644 --- a/course/lesson-10-the-game-loop/content-ZPxY8VUD.tres +++ b/course/lesson-10-the-game-loop/content-ZPxY8VUD.tres @@ -4,7 +4,9 @@ [resource] script = ExtResource( 1 ) +title = "" +type = 2 text = "Other game engines might use different names like [code]_update()[/code]." visual_element_path = "" reverse_blocks = false -type = 2 +has_separator = false diff --git a/course/lesson-10-the-game-loop/content-bTxYej47.tres b/course/lesson-10-the-game-loop/content-bTxYej47.tres index ccd8e1a76..7173d193f 100644 --- a/course/lesson-10-the-game-loop/content-bTxYej47.tres +++ b/course/lesson-10-the-game-loop/content-bTxYej47.tres @@ -4,7 +4,9 @@ [resource] script = ExtResource( 1 ) +title = "" +type = 0 text = "In the practice, you'll learn how to use the process function to rotate and move a character yourself." visual_element_path = "" reverse_blocks = false -type = 0 +has_separator = false diff --git a/course/lesson-10-the-game-loop/content-otxF5HUx.tres b/course/lesson-10-the-game-loop/content-otxF5HUx.tres index d7bc2d2d2..caf06a144 100644 --- a/course/lesson-10-the-game-loop/content-otxF5HUx.tres +++ b/course/lesson-10-the-game-loop/content-otxF5HUx.tres @@ -4,7 +4,9 @@ [resource] script = ExtResource( 1 ) +title = "" +type = 0 text = "It's similar in Godot, but this function can run [b]hundreds of times a second[/b]." visual_element_path = "" reverse_blocks = false -type = 0 +has_separator = false diff --git a/course/lesson-10-the-game-loop/content-pPwQDwfy.tres b/course/lesson-10-the-game-loop/content-pPwQDwfy.tres index 4eb848f86..dcf35e828 100644 --- a/course/lesson-10-the-game-loop/content-pPwQDwfy.tres +++ b/course/lesson-10-the-game-loop/content-pPwQDwfy.tres @@ -4,6 +4,8 @@ [resource] script = ExtResource( 1 ) +title = "" +type = 0 text = "The [code]_process()[/code] function won't do anything until we add something to it. You might notice the underscore [code]_[/code] in front of the function name. This is a convention. It means the function is already defined by Godot. @@ -11,4 +13,4 @@ You might notice the underscore [code]_[/code] in front of the function name. Th If the function exists, and is called exactly [code]_process[/code], then Godot will automatically run it every frame. " visual_element_path = "" reverse_blocks = false -type = 0 +has_separator = false diff --git a/course/lesson-10-the-game-loop/content-tT6n1Txl.tres b/course/lesson-10-the-game-loop/content-tT6n1Txl.tres index c2cf93412..c742b2aca 100644 --- a/course/lesson-10-the-game-loop/content-tT6n1Txl.tres +++ b/course/lesson-10-the-game-loop/content-tT6n1Txl.tres @@ -4,9 +4,11 @@ [resource] script = ExtResource( 1 ) +title = "" +type = 0 text = "Every frame, Godot runs the [code]_process()[/code] function. Since we wrote a [code]rotate()[/code] instruction, Godot is rotating the character by [code]0.05[/code] radians [b]many[/b] times a second." visual_element_path = "" reverse_blocks = false -type = 0 +has_separator = false diff --git a/course/lesson-10-the-game-loop/practice-QiGjB7tK.tres b/course/lesson-10-the-game-loop/practice-QiGjB7tK.tres index 9d95c6a9e..b674d6608 100644 --- a/course/lesson-10-the-game-loop/practice-QiGjB7tK.tres +++ b/course/lesson-10-the-game-loop/practice-QiGjB7tK.tres @@ -18,3 +18,4 @@ validator_script_path = "rotating-and-moving/TestsRotatingAndMoving.gd" script_slice_path = "rotating-and-moving/RotateAndMoveSprite.live-editor/slices/RotateAndMoveSprite.move_and_rotate.slice.tres" documentation_references = PoolStringArray( "rotate", "move_local_x" ) documentation_resource = ExtResource( 2 ) +description = "" diff --git a/course/lesson-10-the-game-loop/practice-tKRHJMQ2.tres b/course/lesson-10-the-game-loop/practice-tKRHJMQ2.tres index 3ab8ad002..49dbf6232 100644 --- a/course/lesson-10-the-game-loop/practice-tKRHJMQ2.tres +++ b/course/lesson-10-the-game-loop/practice-tKRHJMQ2.tres @@ -16,3 +16,4 @@ validator_script_path = "rotating-sprite/TestsRotating.gd" script_slice_path = "rotating-sprite/RotatingSprite.live-editor/slices/RotatingSprite.move_and_rotate.slice.tres" documentation_references = PoolStringArray( "rotate" ) documentation_resource = ExtResource( 2 ) +description = "" diff --git a/course/lesson-11-time-delta/content-1TxlTtcy.tres b/course/lesson-11-time-delta/content-1TxlTtcy.tres index a7788db95..ea008eaac 100644 --- a/course/lesson-11-time-delta/content-1TxlTtcy.tres +++ b/course/lesson-11-time-delta/content-1TxlTtcy.tres @@ -4,6 +4,8 @@ [resource] script = ExtResource( 1 ) +title = "" +type = 2 text = "You may have heard of frames-per-second or FPS. Games often run at 30 or 60 frames-per-second. This means that each second, everything in the game is updated 30 or 60 times. @@ -11,4 +13,4 @@ This means that each second, everything in the game is updated 30 or 60 times. On powerful computers, it's possible to unlock the frame rate to get hundreds or thousands of frames-per-second." visual_element_path = "" reverse_blocks = false -type = 2 +has_separator = false diff --git a/course/lesson-11-time-delta/content-B7tKRHJM.tres b/course/lesson-11-time-delta/content-B7tKRHJM.tres index cf3369f6e..d5a4950ba 100644 --- a/course/lesson-11-time-delta/content-B7tKRHJM.tres +++ b/course/lesson-11-time-delta/content-B7tKRHJM.tres @@ -4,6 +4,8 @@ [resource] script = ExtResource( 1 ) +title = "" +type = 2 text = "Remember! [code]delta[/code] is [b]very small[/b]. In case your Maths is rusty, here are a few examples of multiplications by very small numbers: - [code]2 * 0.5 = 1[/code] @@ -13,4 +15,4 @@ text = "Remember! [code]delta[/code] is [b]very small[/b]. In case your Maths is Since delta is often something like [code]0.016667[/code], you should expect numbers to become [b]smaller[/b] when you multiply by it. " visual_element_path = "" reverse_blocks = false -type = 2 +has_separator = false diff --git a/course/lesson-11-time-delta/content-DGt6fUqb.tres b/course/lesson-11-time-delta/content-DGt6fUqb.tres index 506203190..01d236ec6 100644 --- a/course/lesson-11-time-delta/content-DGt6fUqb.tres +++ b/course/lesson-11-time-delta/content-DGt6fUqb.tres @@ -4,6 +4,8 @@ [resource] script = ExtResource( 1 ) +title = "" +type = 0 text = "[font=res://ui/theme/fonts/font_title.tres]Frames Time Variance[/font] Your computer controls the speed at which each software runs. Depending on how busy the computer is, this can vary. @@ -17,4 +19,4 @@ In mathematics, the word \"delta\" is often used to describe a very small change The [code]delta[/code] parameter tells us how fast Godot took to complete the [b]previous frame[/b]. We can use that to ensure that the variations between frames have no visible effect." visual_element_path = "" reverse_blocks = false -type = 0 +has_separator = false diff --git a/course/lesson-11-time-delta/content-DwfyqdYO.tres b/course/lesson-11-time-delta/content-DwfyqdYO.tres index b10224a6e..8ba165b36 100644 --- a/course/lesson-11-time-delta/content-DwfyqdYO.tres +++ b/course/lesson-11-time-delta/content-DwfyqdYO.tres @@ -4,7 +4,9 @@ [resource] script = ExtResource( 1 ) +title = "" +type = 0 text = "We've seen how we can use our character's [code]_process()[/code] function to make it move continuously." visual_element_path = "" reverse_blocks = false -type = 0 +has_separator = false diff --git a/course/lesson-11-time-delta/content-En91c9ll.tres b/course/lesson-11-time-delta/content-En91c9ll.tres index 96a403778..858cf2798 100644 --- a/course/lesson-11-time-delta/content-En91c9ll.tres +++ b/course/lesson-11-time-delta/content-En91c9ll.tres @@ -4,9 +4,11 @@ [resource] script = ExtResource( 1 ) +title = "" +type = 0 text = "In this second example, we set an [b]different rotation[/b] every frame, adjusting the character's rotation based on [code]delta[/code]. Thanks to that, we get a [b]constant rotation[/b] per second. The character seems to rotate at a regular speed." visual_element_path = "" reverse_blocks = false -type = 0 +has_separator = false diff --git a/course/lesson-11-time-delta/content-Gx0c7DDi.tres b/course/lesson-11-time-delta/content-Gx0c7DDi.tres new file mode 100644 index 000000000..1f5a68429 --- /dev/null +++ b/course/lesson-11-time-delta/content-Gx0c7DDi.tres @@ -0,0 +1,12 @@ +[gd_resource type="Resource" load_steps=2 format=2] + +[ext_resource path="res://resources/ContentBlock.gd" type="Script" id=1] + +[resource] +script = ExtResource( 1 ) +title = "" +type = 0 +text = "" +visual_element_path = "visuals/DemoRobotRace.tscn" +reverse_blocks = false +has_separator = false diff --git a/course/lesson-11-time-delta/content-N4rS5AJT.tres b/course/lesson-11-time-delta/content-N4rS5AJT.tres index b66c72288..6e29ef073 100644 --- a/course/lesson-11-time-delta/content-N4rS5AJT.tres +++ b/course/lesson-11-time-delta/content-N4rS5AJT.tres @@ -4,6 +4,8 @@ [resource] script = ExtResource( 1 ) +title = "" +type = 0 text = "But it's not just our character that has a [code]_process()[/code] function; almost everything in the game has a [code]_process()[/code] function! Godot runs each [code]_process()[/code] function as fast as it can. @@ -17,4 +19,4 @@ And this happens many, many times a second! This is how we get fluid motion in games. " visual_element_path = "" reverse_blocks = false -type = 0 +has_separator = false diff --git a/course/lesson-11-time-delta/content-TLtZixQO.tres b/course/lesson-11-time-delta/content-TLtZixQO.tres index f38c92057..fcf6d2671 100644 --- a/course/lesson-11-time-delta/content-TLtZixQO.tres +++ b/course/lesson-11-time-delta/content-TLtZixQO.tres @@ -4,9 +4,11 @@ [resource] script = ExtResource( 1 ) +title = "" +type = 0 text = "If the frame is fast (0.1s), we only rotate a little. When the frame is slow (0.2s), we rotate more to compensate. Multiplying time sensitive values by delta makes them [b]time-dependent[/b] rather than [b]frame-dependent[/b]." visual_element_path = "" reverse_blocks = false -type = 0 +has_separator = false diff --git a/course/lesson-11-time-delta/content-cSrGQgrV.tres b/course/lesson-11-time-delta/content-cSrGQgrV.tres index 055075638..6d91b24d6 100644 --- a/course/lesson-11-time-delta/content-cSrGQgrV.tres +++ b/course/lesson-11-time-delta/content-cSrGQgrV.tres @@ -4,7 +4,9 @@ [resource] script = ExtResource( 1 ) +title = "" +type = 0 text = "In the next practice, we'll use delta to make rotating time-dependant." visual_element_path = "" reverse_blocks = false -type = 0 +has_separator = false diff --git a/course/lesson-11-time-delta/content-exRjTRhZ.tres b/course/lesson-11-time-delta/content-exRjTRhZ.tres index a7c21f33e..620a68d0e 100644 --- a/course/lesson-11-time-delta/content-exRjTRhZ.tres +++ b/course/lesson-11-time-delta/content-exRjTRhZ.tres @@ -4,7 +4,9 @@ [resource] script = ExtResource( 1 ) +title = "" +type = 0 text = "" visual_element_path = "res://course/lesson-10-the-game-loop/visuals/ExampleRotatingSprite.tscn" reverse_blocks = false -type = 0 +has_separator = false diff --git a/course/lesson-11-time-delta/content-f8B67UJ8.tres b/course/lesson-11-time-delta/content-f8B67UJ8.tres index 47442b3bf..3d1afa5e0 100644 --- a/course/lesson-11-time-delta/content-f8B67UJ8.tres +++ b/course/lesson-11-time-delta/content-f8B67UJ8.tres @@ -4,7 +4,9 @@ [resource] script = ExtResource( 1 ) +title = "" +type = 0 text = "" visual_element_path = "visuals/ExampleRotatingSpriteTime.tscn" reverse_blocks = false -type = 0 +has_separator = false diff --git a/course/lesson-11-time-delta/content-hcIb5BnV.tres b/course/lesson-11-time-delta/content-hcIb5BnV.tres index 3c394e619..d229e0774 100644 --- a/course/lesson-11-time-delta/content-hcIb5BnV.tres +++ b/course/lesson-11-time-delta/content-hcIb5BnV.tres @@ -4,7 +4,9 @@ [resource] script = ExtResource( 1 ) +title = "" +type = 0 text = "Let's look at the [code]_process()[/code] function in more detail." visual_element_path = "" reverse_blocks = false -type = 0 +has_separator = false diff --git a/course/lesson-11-time-delta/content-qE82V6jG.tres b/course/lesson-11-time-delta/content-qE82V6jG.tres index 243230f30..16c9a5307 100644 --- a/course/lesson-11-time-delta/content-qE82V6jG.tres +++ b/course/lesson-11-time-delta/content-qE82V6jG.tres @@ -4,9 +4,9 @@ [resource] script = ExtResource( 1 ) -text = "[font=res://ui/theme/fonts/font_title.tres]Why Does Frame Variance Matter?[/font] - -What would happen if our computer slows down or has irregular frame times? +title = "Why Does Frame Variance Matter?" +type = 0 +text = "What would happen if our computer slows down or has irregular frame times? In the examples below, we artificially made the frames last different times. Some last 0.1 seconds, some 0.2 seconds. @@ -15,4 +15,4 @@ In the first example, we use the [b]same rotation[/b] every frame. But since the frames are unequal, we get a [b]varying rotation[/b] per second. Because of that, the character seems to jump." visual_element_path = "" reverse_blocks = false -type = 0 +has_separator = false diff --git a/course/lesson-11-time-delta/lesson.tres b/course/lesson-11-time-delta/lesson.tres index 227a29f66..a47984fd9 100644 --- a/course/lesson-11-time-delta/lesson.tres +++ b/course/lesson-11-time-delta/lesson.tres @@ -1,4 +1,4 @@ -[gd_resource type="Resource" load_steps=20 format=2] +[gd_resource type="Resource" load_steps=19 format=2] [ext_resource path="res://resources/Lesson.gd" type="Script" id=1] [ext_resource path="res://course/lesson-11-time-delta/quiz-HARbBWNb.tres" type="Resource" id=2] @@ -10,11 +10,10 @@ [ext_resource path="res://course/lesson-11-time-delta/content-1TxlTtcy.tres" type="Resource" id=8] [ext_resource path="res://course/lesson-11-time-delta/content-En91c9ll.tres" type="Resource" id=9] [ext_resource path="res://course/lesson-11-time-delta/quiz-TxYej47M.tres" type="Resource" id=10] -[ext_resource path="res://course/lesson-11-time-delta/content-f8B67UJ8.tres" type="Resource" id=11] [ext_resource path="res://course/lesson-11-time-delta/content-DGt6fUqb.tres" type="Resource" id=12] [ext_resource path="res://course/lesson-11-time-delta/content-qE82V6jG.tres" type="Resource" id=13] [ext_resource path="res://course/lesson-11-time-delta/content-TLtZixQO.tres" type="Resource" id=14] -[ext_resource path="res://course/lesson-11-time-delta/content-vGm22rtQ.tres" type="Resource" id=15] +[ext_resource path="res://course/lesson-11-time-delta/content-Gx0c7DDi.tres" type="Resource" id=15] [ext_resource path="res://course/lesson-11-time-delta/content-cSrGQgrV.tres" type="Resource" id=16] [ext_resource path="res://course/lesson-11-time-delta/quiz-PRw9clsF.tres" type="Resource" id=17] [ext_resource path="res://course/lesson-11-time-delta/practice-x0c7DDiz.tres" type="Resource" id=18] @@ -23,5 +22,5 @@ [resource] script = ExtResource( 1 ) title = "Time Delta" -content_blocks = [ ExtResource( 6 ), ExtResource( 7 ), ExtResource( 4 ), ExtResource( 8 ), ExtResource( 3 ), ExtResource( 2 ), ExtResource( 12 ), ExtResource( 10 ), ExtResource( 13 ), ExtResource( 15 ), ExtResource( 9 ), ExtResource( 11 ), ExtResource( 14 ), ExtResource( 19 ), ExtResource( 17 ), ExtResource( 16 ) ] +content_blocks = [ ExtResource( 6 ), ExtResource( 7 ), ExtResource( 4 ), ExtResource( 8 ), ExtResource( 3 ), ExtResource( 2 ), ExtResource( 12 ), ExtResource( 10 ), ExtResource( 13 ), ExtResource( 15 ), ExtResource( 9 ), ExtResource( 14 ), ExtResource( 19 ), ExtResource( 17 ), ExtResource( 16 ) ] practices = [ ExtResource( 5 ), ExtResource( 18 ) ] diff --git a/course/lesson-11-time-delta/practice-UdOCQiGj.tres b/course/lesson-11-time-delta/practice-UdOCQiGj.tres index c17c2e4ea..106143c02 100644 --- a/course/lesson-11-time-delta/practice-UdOCQiGj.tres +++ b/course/lesson-11-time-delta/practice-UdOCQiGj.tres @@ -18,3 +18,4 @@ validator_script_path = "rotating-using-delta/TestsRotatingDelta.gd" script_slice_path = "rotating-using-delta/RotatingSpriteDelta.live-editor/slices/RotatingSpriteDelta.move_and_rotate.slice.tres" documentation_references = PoolStringArray( "rotate" ) documentation_resource = ExtResource( 2 ) +description = "" diff --git a/course/lesson-11-time-delta/practice-x0c7DDiz.tres b/course/lesson-11-time-delta/practice-x0c7DDiz.tres index 96d809054..c807f8841 100644 --- a/course/lesson-11-time-delta/practice-x0c7DDiz.tres +++ b/course/lesson-11-time-delta/practice-x0c7DDiz.tres @@ -16,3 +16,4 @@ validator_script_path = "rotating-and-moving-delta/TestsRotatingMovingDelta.gd" script_slice_path = "rotating-and-moving-delta/RotatingMovingSpriteDelta.live-editor/slices/RotatingMovingSpriteDelta.move_and_rotate.slice.tres" documentation_references = PoolStringArray( "rotate", "move_local_x" ) documentation_resource = ExtResource( 2 ) +description = "" diff --git a/course/lesson-11-time-delta/visuals/DemoRobotRace.gd b/course/lesson-11-time-delta/visuals/DemoRobotRace.gd new file mode 100644 index 000000000..68ebb6f82 --- /dev/null +++ b/course/lesson-11-time-delta/visuals/DemoRobotRace.gd @@ -0,0 +1,9 @@ +tool +extends RunnableCodeExample + +func _ready(): + create_slider_for("computer_speed", 0.1, 1.0, 0.1) + +func _set_instance_value(value: float, property_name: String, value_label: Label) -> void: + ._set_instance_value(value, property_name, value_label) + _gdscript_text_edit.text = gdscript_code.replace(property_name, "%s [=%s]"%[property_name, value]) diff --git a/course/lesson-11-time-delta/visuals/DemoRobotRace.tscn b/course/lesson-11-time-delta/visuals/DemoRobotRace.tscn new file mode 100644 index 000000000..f6a835135 --- /dev/null +++ b/course/lesson-11-time-delta/visuals/DemoRobotRace.tscn @@ -0,0 +1,39 @@ +[gd_scene load_steps=4 format=2] + +[ext_resource path="res://course/lesson-11-time-delta/visuals/RobotRace.tscn" type="PackedScene" id=1] +[ext_resource path="res://ui/components/RunnableCodeExample.tscn" type="PackedScene" id=2] +[ext_resource path="res://course/lesson-11-time-delta/visuals/DemoRobotRace.gd" type="Script" id=3] + +[node name="Control" type="PanelContainer"] +anchor_right = 1.0 +anchor_bottom = 1.0 +margin_right = -1220.0 +margin_bottom = -560.0 +rect_min_size = Vector2( 700, 560 ) +__meta__ = { +"_edit_use_anchors_": false +} + +[node name="RunnableCodeExample" parent="." instance=ExtResource( 2 )] +margin_left = 7.0 +margin_top = 7.0 +margin_right = 693.0 +margin_bottom = 553.0 +script = ExtResource( 3 ) +scene = ExtResource( 1 ) + +[node name="Frame" parent="RunnableCodeExample" index="0"] +margin_right = 686.0 +margin_bottom = 546.0 + +[node name="ResetButton" parent="RunnableCodeExample/Frame/HBoxContainer" index="0"] +visible = false + +[node name="GDScriptCode" parent="RunnableCodeExample" index="1"] +visible = false +margin_left = 463.0 +margin_right = 923.0 +margin_bottom = 460.0 +draw_spaces = true + +[editable path="RunnableCodeExample"] diff --git a/course/lesson-11-time-delta/visuals/RobotRace.gd b/course/lesson-11-time-delta/visuals/RobotRace.gd new file mode 100644 index 000000000..c5b154c81 --- /dev/null +++ b/course/lesson-11-time-delta/visuals/RobotRace.gd @@ -0,0 +1,24 @@ +extends Node2D + +var computer_speed := 0.1 setget _set_computer_speed, get_computer_speed + +onready var _robots := $Robots + +func run(): + for child in _robots.get_children(): + child.run() + + +func _set_computer_speed(new_computer_speed: float): + computer_speed = new_computer_speed * 10 + + if not _robots: + return + + for child in _robots.get_children(): + child.computer_speed = computer_speed + child.reset() + + +func get_computer_speed(): + return computer_speed diff --git a/course/lesson-11-time-delta/visuals/RobotRace.tscn b/course/lesson-11-time-delta/visuals/RobotRace.tscn new file mode 100644 index 000000000..ee3f674e1 --- /dev/null +++ b/course/lesson-11-time-delta/visuals/RobotRace.tscn @@ -0,0 +1,166 @@ +[gd_scene load_steps=6 format=2] + +[ext_resource path="res://course/lesson-11-time-delta/visuals/RunningRobot.tscn" type="PackedScene" id=1] +[ext_resource path="res://course/lesson-11-time-delta/visuals/RobotRace.gd" type="Script" id=2] + +[sub_resource type="GDScript" id=2] +script/source = "extends \"res://course/lesson-11-time-delta/visuals/RunningRobot.gd\" + + +func _ready(): + set_process(false) + update() + +func _process(delta): + _sprite.position.x += speed * delta * computer_speed + + if _sprite.position.x > distance/2: + reset() + +func _draw(): + draw_line(Vector2(distance/2, 0), Vector2(distance/2, distance), Color.white * 0.5, 4, true) + + draw_line(Vector2(-distance/2, 0), Vector2(distance/2, 0), Color.white, 4, true) + draw_circle(Vector2(-distance/2, 0), 6, Color.white) + draw_circle(Vector2(distance/2, 0), 6, Color.white) + + +func run(): + reset() + set_process(true) + + +func reset(): + _sprite.position.x = -distance/2 + set_process(false) +" + +[sub_resource type="GDScript" id=1] +script/source = "extends \"res://course/lesson-11-time-delta/visuals/RunningRobot.gd\" + +const _deltas := [0.1, 0.3, 0.5, 0.1, 0.2, 0.2, 0.6, 0.1, 0.1, 0.1, 0.7] + +var _index := 0 + +onready var _timer := $Timer + +func _ready(): + _timer.connect(\"timeout\", self, \"_on_Timer_timeout\") + + +func run(): + reset() + _on_Timer_timeout() + + +func reset(): + _timer.stop() + _index = 0 + _sprite.position.x = -distance/2 + + +func _on_Timer_timeout(): + if _index > _deltas.size() - 1: + _index = 0 + _sprite.position.x = -distance/2 + return + + var time = _deltas[_index] + _sprite.position.x += speed * time + + _timer.start(_deltas[_index] / computer_speed) + _index += 1 +" + +[sub_resource type="GDScript" id=3] +script/source = "extends \"res://course/lesson-11-time-delta/visuals/RunningRobot.gd\" + +const _deltas := [0.1, 0.3, 0.5, 0.1, 0.2, 0.2, 0.6, 0.1, 0.1, 0.1, 0.7] + +var _index := 0 + +onready var _timer := $Timer + +func _ready(): + speed /= 3 + _timer.connect(\"timeout\", self, \"_on_Timer_timeout\") + + +func run(): + reset() + + _on_Timer_timeout() + +func reset(): + _timer.stop() + _index = 0 + _sprite.position.x = -distance/2 + +func _on_Timer_timeout(): + if _index > _deltas.size() - 1: + _index = 0 + _sprite.position.x = -distance/2 + return + + var time = _deltas[_index] + _sprite.position.x += speed + + _timer.start(_deltas[_index] / computer_speed) + _index += 1 +" + +[node name="RobotRace" type="Node2D"] +script = ExtResource( 2 ) + +[node name="Robots" type="Node2D" parent="."] + +[node name="RunningRobotNormal" parent="Robots" instance=ExtResource( 1 )] +position = Vector2( 0, -120 ) +script = SubResource( 2 ) + +[node name="Label" type="Label" parent="Robots/RunningRobotNormal"] +margin_left = -264.0 +margin_top = 8.0 +margin_right = -124.0 +margin_bottom = 22.0 +rect_min_size = Vector2( 140, 0 ) +text = "Desired Path" +__meta__ = { +"_edit_use_anchors_": false +} + +[node name="RunningRobotFrame" parent="Robots" instance=ExtResource( 1 )] +position = Vector2( 0, 70 ) +script = SubResource( 1 ) + +[node name="Timer" type="Timer" parent="Robots/RunningRobotFrame"] +one_shot = true + +[node name="Label2" type="Label" parent="Robots/RunningRobotFrame"] +margin_left = -264.0 +margin_top = 8.0 +margin_right = -124.0 +margin_bottom = 22.0 +rect_min_size = Vector2( 140, 0 ) +text = "Using Delta" +__meta__ = { +"_edit_use_anchors_": false +} + +[node name="RunningRobotFrame2" parent="Robots" instance=ExtResource( 1 )] +position = Vector2( 0, 220 ) +script = SubResource( 3 ) + +[node name="Timer" type="Timer" parent="Robots/RunningRobotFrame2"] +one_shot = true + +[node name="Label3" type="Label" parent="Robots/RunningRobotFrame2"] +margin_left = -264.0 +margin_top = 8.0 +margin_right = -124.0 +margin_bottom = 22.0 +rect_min_size = Vector2( 140, 0 ) +text = "Constant Distance" +__meta__ = { +"_edit_use_anchors_": false +} diff --git a/course/lesson-11-time-delta/visuals/RunningRobot.gd b/course/lesson-11-time-delta/visuals/RunningRobot.gd new file mode 100644 index 000000000..6e639c24b --- /dev/null +++ b/course/lesson-11-time-delta/visuals/RunningRobot.gd @@ -0,0 +1,16 @@ +extends Node2D + +var computer_speed := 1.0 +var distance := 400 +var speed := distance/3 + +onready var _sprite := $Robot + +func _ready(): + _sprite.position.x = -distance/2 + +func run(): + pass + +func reset(): + pass diff --git a/course/lesson-11-time-delta/visuals/RunningRobot.tscn b/course/lesson-11-time-delta/visuals/RunningRobot.tscn new file mode 100644 index 000000000..c4ba3daef --- /dev/null +++ b/course/lesson-11-time-delta/visuals/RunningRobot.tscn @@ -0,0 +1,11 @@ +[gd_scene load_steps=3 format=2] + +[ext_resource path="res://course/lesson-1-what-code-is-like/first_practice/godot_bottom.png" type="Texture" id=1] +[ext_resource path="res://course/lesson-11-time-delta/visuals/RunningRobot.gd" type="Script" id=2] + +[node name="RunningRobot" type="Node2D"] +script = ExtResource( 2 ) + +[node name="Robot" type="Sprite" parent="."] +position = Vector2( 0, -60 ) +texture = ExtResource( 1 ) From 9519c6f84d13c6f3dada900679873c8ee146fb63 Mon Sep 17 00:00:00 2001 From: johnnygossdev Date: Sun, 16 Jan 2022 18:41:25 +0000 Subject: [PATCH 19/21] improvement: delta visual --- .../content-qE82V6jG.tres | 6 +- .../lesson-11-time-delta/visuals/RobotRace.gd | 49 ++++++++-- .../visuals/RobotRace.tscn | 98 +++++-------------- .../visuals/RunningRobot.gd | 12 ++- 4 files changed, 81 insertions(+), 84 deletions(-) diff --git a/course/lesson-11-time-delta/content-qE82V6jG.tres b/course/lesson-11-time-delta/content-qE82V6jG.tres index 16c9a5307..39675faad 100644 --- a/course/lesson-11-time-delta/content-qE82V6jG.tres +++ b/course/lesson-11-time-delta/content-qE82V6jG.tres @@ -8,9 +8,11 @@ title = "Why Does Frame Variance Matter?" type = 0 text = "What would happen if our computer slows down or has irregular frame times? -In the examples below, we artificially made the frames last different times. Some last 0.1 seconds, some 0.2 seconds. +In the examples below, we artificially made the frames last different times. Some last 0.1 seconds, some as much as 0.7 seconds. + +When we use `delta`, the robot takes into account the varying frames so aligns with the desired path; it gets the end of the line at the correct time. + -In the first example, we use the [b]same rotation[/b] every frame. But since the frames are unequal, we get a [b]varying rotation[/b] per second. Because of that, the character seems to jump." visual_element_path = "" diff --git a/course/lesson-11-time-delta/visuals/RobotRace.gd b/course/lesson-11-time-delta/visuals/RobotRace.gd index c5b154c81..fd801ca50 100644 --- a/course/lesson-11-time-delta/visuals/RobotRace.gd +++ b/course/lesson-11-time-delta/visuals/RobotRace.gd @@ -1,24 +1,59 @@ extends Node2D -var computer_speed := 0.1 setget _set_computer_speed, get_computer_speed +const DELTAS := [0.1, 0.3, 0.5, 0.1, 0.2, 0.2, 0.6, 0.1, 0.1, 0.1, 0.3, 0.2, 0.1, 0.1, 0.1, 0.1] + +var computer_speed := 1.0 setget _set_computer_speed, get_computer_speed +var _index := 0 onready var _robots := $Robots +onready var _timer := $Timer +onready var _robot_normal := $Robots/RunningRobotNormal +onready var _robot_frame_delta := $Robots/RunningRobotFrameDelta +onready var _robot_frame := $Robots/RunningRobotFrame + -func run(): +func run() -> void: + if not _robot_normal.is_connected("animation_complete", _robot_frame_delta, "reset"): + _robot_normal.connect("animation_complete", _robot_frame_delta, "reset") + if not _robot_normal.is_connected("animation_complete", _robot_frame, "reset"): + _robot_normal.connect("animation_complete", _robot_frame, "reset") + + reset() for child in _robots.get_children(): child.run() + _on_Timer_timeout() + -func _set_computer_speed(new_computer_speed: float): +func _set_computer_speed(new_computer_speed: float) -> void: computer_speed = new_computer_speed * 10 - + if not _robots: return - + for child in _robots.get_children(): child.computer_speed = computer_speed - child.reset() + + reset() -func get_computer_speed(): +func get_computer_speed() -> float: return computer_speed + + +func reset() -> void: + _index = 0 + _timer.stop() + _robot_normal.reset() + + +func _on_Timer_timeout() -> void: + if _index > DELTAS.size() - 1: + _index = 0 + return + + _robot_frame_delta.set_sprite_position(_robot_normal.get_sprite_position()) + _robot_frame.move(Vector2(30, 0)) + + _timer.start(DELTAS[_index] / computer_speed) + _index += 1 diff --git a/course/lesson-11-time-delta/visuals/RobotRace.tscn b/course/lesson-11-time-delta/visuals/RobotRace.tscn index ee3f674e1..99a9951ef 100644 --- a/course/lesson-11-time-delta/visuals/RobotRace.tscn +++ b/course/lesson-11-time-delta/visuals/RobotRace.tscn @@ -6,18 +6,22 @@ [sub_resource type="GDScript" id=2] script/source = "extends \"res://course/lesson-11-time-delta/visuals/RunningRobot.gd\" +signal animation_complete -func _ready(): + +func _ready() -> void: set_process(false) update() -func _process(delta): + +func _process(delta) -> void: _sprite.position.x += speed * delta * computer_speed if _sprite.position.x > distance/2: - reset() + set_process(false) -func _draw(): + +func _draw() -> void: draw_line(Vector2(distance/2, 0), Vector2(distance/2, distance), Color.white * 0.5, 4, true) draw_line(Vector2(-distance/2, 0), Vector2(distance/2, 0), Color.white, 4, true) @@ -25,88 +29,39 @@ func _draw(): draw_circle(Vector2(distance/2, 0), 6, Color.white) -func run(): +func run() -> void: reset() set_process(true) -func reset(): +func reset() -> void: _sprite.position.x = -distance/2 set_process(false) + emit_signal(\"animation_complete\") " [sub_resource type="GDScript" id=1] script/source = "extends \"res://course/lesson-11-time-delta/visuals/RunningRobot.gd\" -const _deltas := [0.1, 0.3, 0.5, 0.1, 0.2, 0.2, 0.6, 0.1, 0.1, 0.1, 0.7] - -var _index := 0 - -onready var _timer := $Timer - -func _ready(): - _timer.connect(\"timeout\", self, \"_on_Timer_timeout\") - - -func run(): - reset() - _on_Timer_timeout() - -func reset(): - _timer.stop() - _index = 0 +func reset() -> void: _sprite.position.x = -distance/2 - - -func _on_Timer_timeout(): - if _index > _deltas.size() - 1: - _index = 0 - _sprite.position.x = -distance/2 - return - - var time = _deltas[_index] - _sprite.position.x += speed * time - - _timer.start(_deltas[_index] / computer_speed) - _index += 1 " [sub_resource type="GDScript" id=3] script/source = "extends \"res://course/lesson-11-time-delta/visuals/RunningRobot.gd\" -const _deltas := [0.1, 0.3, 0.5, 0.1, 0.2, 0.2, 0.6, 0.1, 0.1, 0.1, 0.7] - -var _index := 0 - -onready var _timer := $Timer -func _ready(): +func _ready() -> void: speed /= 3 - _timer.connect(\"timeout\", self, \"_on_Timer_timeout\") -func run(): - reset() - - _on_Timer_timeout() - -func reset(): - _timer.stop() - _index = 0 +func reset() -> void: _sprite.position.x = -distance/2 -func _on_Timer_timeout(): - if _index > _deltas.size() - 1: - _index = 0 - _sprite.position.x = -distance/2 - return - - var time = _deltas[_index] - _sprite.position.x += speed - - _timer.start(_deltas[_index] / computer_speed) - _index += 1 + +func move(vector: Vector2) -> void: + _sprite.position += vector " [node name="RobotRace" type="Node2D"] @@ -129,14 +84,11 @@ __meta__ = { "_edit_use_anchors_": false } -[node name="RunningRobotFrame" parent="Robots" instance=ExtResource( 1 )] +[node name="RunningRobotFrameDelta" parent="Robots" instance=ExtResource( 1 )] position = Vector2( 0, 70 ) script = SubResource( 1 ) -[node name="Timer" type="Timer" parent="Robots/RunningRobotFrame"] -one_shot = true - -[node name="Label2" type="Label" parent="Robots/RunningRobotFrame"] +[node name="Label" type="Label" parent="Robots/RunningRobotFrameDelta"] margin_left = -264.0 margin_top = 8.0 margin_right = -124.0 @@ -147,14 +99,11 @@ __meta__ = { "_edit_use_anchors_": false } -[node name="RunningRobotFrame2" parent="Robots" instance=ExtResource( 1 )] +[node name="RunningRobotFrame" parent="Robots" instance=ExtResource( 1 )] position = Vector2( 0, 220 ) script = SubResource( 3 ) -[node name="Timer" type="Timer" parent="Robots/RunningRobotFrame2"] -one_shot = true - -[node name="Label3" type="Label" parent="Robots/RunningRobotFrame2"] +[node name="Label" type="Label" parent="Robots/RunningRobotFrame"] margin_left = -264.0 margin_top = 8.0 margin_right = -124.0 @@ -164,3 +113,8 @@ text = "Constant Distance" __meta__ = { "_edit_use_anchors_": false } + +[node name="Timer" type="Timer" parent="."] +one_shot = true + +[connection signal="timeout" from="Timer" to="." method="_on_Timer_timeout"] diff --git a/course/lesson-11-time-delta/visuals/RunningRobot.gd b/course/lesson-11-time-delta/visuals/RunningRobot.gd index 6e639c24b..fca41034b 100644 --- a/course/lesson-11-time-delta/visuals/RunningRobot.gd +++ b/course/lesson-11-time-delta/visuals/RunningRobot.gd @@ -6,11 +6,17 @@ var speed := distance/3 onready var _sprite := $Robot -func _ready(): +func _ready() -> void: _sprite.position.x = -distance/2 -func run(): +func run() -> void: pass -func reset(): +func reset() -> void: pass + +func set_sprite_position(new_position: Vector2) -> void: + _sprite.position = new_position + +func get_sprite_position() -> Vector2: + return _sprite.position From 870b79d559f8885e40eed87f7d25f6ed04b7af52 Mon Sep 17 00:00:00 2001 From: johnnygossdev Date: Tue, 18 Jan 2022 12:58:57 +0000 Subject: [PATCH 20/21] content: explain visual --- course/course-learn-gdscript.tres | 2 +- course/lesson-11-time-delta/content-B7tKRHJM.tres | 2 +- course/lesson-11-time-delta/content-TLtZixQO.tres | 4 ++-- course/lesson-11-time-delta/content-qE82V6jG.tres | 6 ++++-- course/lesson-11-time-delta/lesson.tres | 5 ++--- 5 files changed, 10 insertions(+), 9 deletions(-) diff --git a/course/course-learn-gdscript.tres b/course/course-learn-gdscript.tres index 42355afe0..632514b14 100644 --- a/course/course-learn-gdscript.tres +++ b/course/course-learn-gdscript.tres @@ -15,6 +15,6 @@ [ext_resource path="res://course/lesson-14-multiplying/lesson.tres" type="Resource" id=13] [resource] -script = ExtResource( 2 ) +script = ExtResource( 1 ) title = "Learn GDScript From Zero" lessons = [ ExtResource( 9 ), ExtResource( 4 ), ExtResource( 7 ), ExtResource( 2 ), ExtResource( 10 ), ExtResource( 6 ), ExtResource( 5 ), ExtResource( 3 ), ExtResource( 8 ), ExtResource( 11 ), ExtResource( 12 ), ExtResource( 13 ) ] diff --git a/course/lesson-11-time-delta/content-B7tKRHJM.tres b/course/lesson-11-time-delta/content-B7tKRHJM.tres index d5a4950ba..4e75e8257 100644 --- a/course/lesson-11-time-delta/content-B7tKRHJM.tres +++ b/course/lesson-11-time-delta/content-B7tKRHJM.tres @@ -12,7 +12,7 @@ text = "Remember! [code]delta[/code] is [b]very small[/b]. In case your Maths is - [code]10 * 0.2 = 2[/code] - [code]1 * 0.01 = 0.01[/code] -Since delta is often something like [code]0.016667[/code], you should expect numbers to become [b]smaller[/b] when you multiply by it. " +Since delta is often something like [code]0.016667[/code], you should expect numbers to become [b]smaller[/b] when you multiply by it." visual_element_path = "" reverse_blocks = false has_separator = false diff --git a/course/lesson-11-time-delta/content-TLtZixQO.tres b/course/lesson-11-time-delta/content-TLtZixQO.tres index fcf6d2671..9216d6fa7 100644 --- a/course/lesson-11-time-delta/content-TLtZixQO.tres +++ b/course/lesson-11-time-delta/content-TLtZixQO.tres @@ -6,9 +6,9 @@ script = ExtResource( 1 ) title = "" type = 0 -text = "If the frame is fast (0.1s), we only rotate a little. When the frame is slow (0.2s), we rotate more to compensate. +text = "If the frame is fast (0.1s), we only move a little. When the frame is slow (0.2s), we move more to compensate. -Multiplying time sensitive values by delta makes them [b]time-dependent[/b] rather than [b]frame-dependent[/b]." +Multiplying time sensitive values by [code]delta[/code] makes them [b]time-dependent[/b] rather than [b]frame-dependent[/b]." visual_element_path = "" reverse_blocks = false has_separator = false diff --git a/course/lesson-11-time-delta/content-qE82V6jG.tres b/course/lesson-11-time-delta/content-qE82V6jG.tres index 39675faad..a782ea340 100644 --- a/course/lesson-11-time-delta/content-qE82V6jG.tres +++ b/course/lesson-11-time-delta/content-qE82V6jG.tres @@ -10,11 +10,13 @@ text = "What would happen if our computer slows down or has irregular frame time In the examples below, we artificially made the frames last different times. Some last 0.1 seconds, some as much as 0.7 seconds. -When we use `delta`, the robot takes into account the varying frames so aligns with the desired path; it gets the end of the line at the correct time. +When we use [code]delta[/code], the robot takes into account the varying frames so aligns with the desired path; it gets the end of the line at the correct time. +By using [code]delta[/code], we move a [b]different amount[/b] every frame, adjusting the character's position based on [code]delta[/code]. +Thanks to that, we get [b]constant movement[/b] per second. The character seems to move at a regular speed. -But since the frames are unequal, we get a [b]varying rotation[/b] per second. Because of that, the character seems to jump." +Using a constant distance each frame instead, we get [b]varying movement[/b] per second. Because of that, the character seems to jump and overshoots the target." visual_element_path = "" reverse_blocks = false has_separator = false diff --git a/course/lesson-11-time-delta/lesson.tres b/course/lesson-11-time-delta/lesson.tres index a47984fd9..3625ab4d7 100644 --- a/course/lesson-11-time-delta/lesson.tres +++ b/course/lesson-11-time-delta/lesson.tres @@ -1,4 +1,4 @@ -[gd_resource type="Resource" load_steps=19 format=2] +[gd_resource type="Resource" load_steps=18 format=2] [ext_resource path="res://resources/Lesson.gd" type="Script" id=1] [ext_resource path="res://course/lesson-11-time-delta/quiz-HARbBWNb.tres" type="Resource" id=2] @@ -8,7 +8,6 @@ [ext_resource path="res://course/lesson-11-time-delta/content-DwfyqdYO.tres" type="Resource" id=6] [ext_resource path="res://course/lesson-11-time-delta/content-exRjTRhZ.tres" type="Resource" id=7] [ext_resource path="res://course/lesson-11-time-delta/content-1TxlTtcy.tres" type="Resource" id=8] -[ext_resource path="res://course/lesson-11-time-delta/content-En91c9ll.tres" type="Resource" id=9] [ext_resource path="res://course/lesson-11-time-delta/quiz-TxYej47M.tres" type="Resource" id=10] [ext_resource path="res://course/lesson-11-time-delta/content-DGt6fUqb.tres" type="Resource" id=12] [ext_resource path="res://course/lesson-11-time-delta/content-qE82V6jG.tres" type="Resource" id=13] @@ -22,5 +21,5 @@ [resource] script = ExtResource( 1 ) title = "Time Delta" -content_blocks = [ ExtResource( 6 ), ExtResource( 7 ), ExtResource( 4 ), ExtResource( 8 ), ExtResource( 3 ), ExtResource( 2 ), ExtResource( 12 ), ExtResource( 10 ), ExtResource( 13 ), ExtResource( 15 ), ExtResource( 9 ), ExtResource( 14 ), ExtResource( 19 ), ExtResource( 17 ), ExtResource( 16 ) ] +content_blocks = [ ExtResource( 6 ), ExtResource( 7 ), ExtResource( 4 ), ExtResource( 8 ), ExtResource( 3 ), ExtResource( 2 ), ExtResource( 12 ), ExtResource( 10 ), ExtResource( 13 ), ExtResource( 15 ), ExtResource( 14 ), ExtResource( 19 ), ExtResource( 17 ), ExtResource( 16 ) ] practices = [ ExtResource( 5 ), ExtResource( 18 ) ] From 43380e7bac6eeca498e5010705f6807aed6a6559 Mon Sep 17 00:00:00 2001 From: Nathan Lovato Date: Sun, 23 Jan 2022 20:04:34 -0600 Subject: [PATCH 21/21] chore: make assignments tests work in lesson 10 --- course/course-learn-gdscript.tres | 10 ++++++---- .../rotating-and-moving/RotateAndMoveSprite.gd | 3 ++- .../scripts/RotateAndMoveSprite.gd.tres | 3 ++- .../RotateAndMoveSprite.move_and_rotate.slice.tres | 10 +++++----- .../rotating-and-moving/TestsRotatingAndMoving.gd | 12 +++--------- .../rotating-sprite/RotatingSprite.gd | 3 ++- .../scene/RotatingSprite.tscn.tres | 8 ++++---- .../scripts/RotatingSprite.gd.tres | 11 ++++++----- .../RotatingSprite.move_and_rotate.slice.tres | 14 +++++++------- .../rotating-sprite/TestsRotating.gd | 6 +----- 10 files changed, 38 insertions(+), 42 deletions(-) diff --git a/course/course-learn-gdscript.tres b/course/course-learn-gdscript.tres index 632514b14..8b2e6540d 100644 --- a/course/course-learn-gdscript.tres +++ b/course/course-learn-gdscript.tres @@ -1,8 +1,8 @@ -[gd_resource type="Resource" load_steps=14 format=2] +[gd_resource type="Resource" load_steps=16 format=2] [ext_resource path="res://resources/Course.gd" type="Script" id=1] -[ext_resource path="res://course/lesson-4-drawing-a-rectangle/lesson.tres" type="Resource" id=2] -[ext_resource path="res://course/lesson-8-defining-variables/lesson.tres" type="Resource" id=3] +[ext_resource path="res://course/lesson-8-defining-variables/lesson.tres" type="Resource" id=2] +[ext_resource path="res://course/lesson-4-drawing-a-rectangle/lesson.tres" type="Resource" id=3] [ext_resource path="res://course/lesson-2-your-first-error/lesson.tres" type="Resource" id=4] [ext_resource path="res://course/lesson-7-member-variables/lesson.tres" type="Resource" id=5] [ext_resource path="res://course/lesson-6-multiple-function-parameters/lesson.tres" type="Resource" id=6] @@ -13,8 +13,10 @@ [ext_resource path="res://course/lesson-12-using-variables/lesson.tres" type="Resource" id=11] [ext_resource path="res://course/lesson-13-conditions/lesson.tres" type="Resource" id=12] [ext_resource path="res://course/lesson-14-multiplying/lesson.tres" type="Resource" id=13] +[ext_resource path="res://course/lesson-10-the-game-loop/lesson.tres" type="Resource" id=14] +[ext_resource path="res://course/lesson-11-time-delta/lesson.tres" type="Resource" id=15] [resource] script = ExtResource( 1 ) title = "Learn GDScript From Zero" -lessons = [ ExtResource( 9 ), ExtResource( 4 ), ExtResource( 7 ), ExtResource( 2 ), ExtResource( 10 ), ExtResource( 6 ), ExtResource( 5 ), ExtResource( 3 ), ExtResource( 8 ), ExtResource( 11 ), ExtResource( 12 ), ExtResource( 13 ) ] +lessons = [ ExtResource( 9 ), ExtResource( 4 ), ExtResource( 7 ), ExtResource( 3 ), ExtResource( 10 ), ExtResource( 6 ), ExtResource( 5 ), ExtResource( 2 ), ExtResource( 8 ), ExtResource( 14 ), ExtResource( 15 ), ExtResource( 11 ), ExtResource( 12 ), ExtResource( 13 ) ] diff --git a/course/lesson-10-the-game-loop/rotating-and-moving/RotateAndMoveSprite.gd b/course/lesson-10-the-game-loop/rotating-and-moving/RotateAndMoveSprite.gd index 0288a1828..d4c9a60ae 100644 --- a/course/lesson-10-the-game-loop/rotating-and-moving/RotateAndMoveSprite.gd +++ b/course/lesson-10-the-game-loop/rotating-and-moving/RotateAndMoveSprite.gd @@ -14,8 +14,9 @@ func _process(_delta): func _run() -> void: reset() - _process(0.0) set_process(true) + yield(get_tree().create_timer(1.0), "timeout") + Events.emit_signal("practice_run_completed") func reset() -> void: diff --git a/course/lesson-10-the-game-loop/rotating-and-moving/RotateAndMoveSprite.live-editor/scripts/RotateAndMoveSprite.gd.tres b/course/lesson-10-the-game-loop/rotating-and-moving/RotateAndMoveSprite.live-editor/scripts/RotateAndMoveSprite.gd.tres index 3f226bf1a..379fbf206 100644 --- a/course/lesson-10-the-game-loop/rotating-and-moving/RotateAndMoveSprite.live-editor/scripts/RotateAndMoveSprite.gd.tres +++ b/course/lesson-10-the-game-loop/rotating-and-moving/RotateAndMoveSprite.live-editor/scripts/RotateAndMoveSprite.gd.tres @@ -23,8 +23,9 @@ func _process(_delta): func _run() -> void: reset() - _process(0.0) set_process(true) + yield(get_tree().create_timer(1.0), \"timeout\") + Events.emit_signal(\"practice_run_completed\") func reset() -> void: diff --git a/course/lesson-10-the-game-loop/rotating-and-moving/RotateAndMoveSprite.live-editor/slices/RotateAndMoveSprite.move_and_rotate.slice.tres b/course/lesson-10-the-game-loop/rotating-and-moving/RotateAndMoveSprite.live-editor/slices/RotateAndMoveSprite.move_and_rotate.slice.tres index 842ae9d00..73429e9a9 100644 --- a/course/lesson-10-the-game-loop/rotating-and-moving/RotateAndMoveSprite.live-editor/slices/RotateAndMoveSprite.move_and_rotate.slice.tres +++ b/course/lesson-10-the-game-loop/rotating-and-moving/RotateAndMoveSprite.live-editor/slices/RotateAndMoveSprite.move_and_rotate.slice.tres @@ -1,13 +1,13 @@ [gd_resource type="Resource" load_steps=4 format=2] [ext_resource path="res://addons/gdscript-slice-exporter/collections/SliceProperties.gd" type="Script" id=1] -[ext_resource path="res://course/lesson-10-the-game-loop/rotating-and-moving/RotateAndMoveSprite.live-editor/scripts/RotateAndMoveSprite.gd.tres" type="Resource" id=2] -[ext_resource path="res://course/lesson-10-the-game-loop/rotating-and-moving/RotateAndMoveSprite.live-editor/scene/RotateAndMoveSprite.tscn.tres" type="Resource" id=3] +[ext_resource path="res://course/lesson-10-the-game-loop/rotating-and-moving/RotateAndMoveSprite.live-editor/scene/RotateAndMoveSprite.tscn.tres" type="Resource" id=2] +[ext_resource path="res://course/lesson-10-the-game-loop/rotating-and-moving/RotateAndMoveSprite.live-editor/scripts/RotateAndMoveSprite.gd.tres" type="Resource" id=3] [resource] script = ExtResource( 1 ) -scene_properties = ExtResource( 3 ) -script_properties = ExtResource( 2 ) +scene_properties = ExtResource( 2 ) +script_properties = ExtResource( 3 ) leading_spaces = 0 keyword = "EXPORT" closing = false @@ -16,5 +16,5 @@ is_full_file = false start = 7 end = 11 lines_before = [ "extends Node2D", "", "", "func _ready() -> void:", " set_process(false)", "", "" ] -lines_after = [ "", "", "func _run() -> void:", " reset()", " _process(0.0)", " set_process(true)", "", "", "func reset() -> void:", " rotation = 0.0", " position = Vector2(300, 200)", " set_process(false)", "" ] +lines_after = [ "", "", "func _run() -> void:", " reset()", " set_process(true)", " yield(get_tree().create_timer(1.0), \"timeout\")", " Events.emit_signal(\"practice_run_completed\")", "", "", "func reset() -> void:", " rotation = 0.0", " position = Vector2(300, 200)", " set_process(false)", "" ] lines_editable = [ "func _process(_delta):", " rotate(0.05)", " move_local_x(5)" ] diff --git a/course/lesson-10-the-game-loop/rotating-and-moving/TestsRotatingAndMoving.gd b/course/lesson-10-the-game-loop/rotating-and-moving/TestsRotatingAndMoving.gd index 001014f0c..168d599d4 100644 --- a/course/lesson-10-the-game-loop/rotating-and-moving/TestsRotatingAndMoving.gd +++ b/course/lesson-10-the-game-loop/rotating-and-moving/TestsRotatingAndMoving.gd @@ -1,19 +1,13 @@ extends PracticeTester -func test_character_is_moving_in_a_circle_slowly() -> String: +func test_character_is_moving_in_a_circle() -> String: var node_2d = _scene_root_viewport.get_child(0).get_child(0) var node_rotation = node_2d.rotation var node_position = node_2d.position as Vector2 if node_rotation < 0.0: return "The robot is turning in the wrong direction!" - elif node_rotation > 0.06: - return "The robot is turning too fast!" - elif not is_equal_approx(node_rotation, 0.05): - return "The robot's rotation speed isn't right." - elif not is_equal_approx(node_position.x, 304.994): - return "The value of a parameter isn't right." - elif not is_equal_approx(node_position.y, 200.25): - return "The value of a parameter isn't right." + elif is_equal_approx(node_position.x, 300.0): + return "The character didn't move as expected." return "" diff --git a/course/lesson-10-the-game-loop/rotating-sprite/RotatingSprite.gd b/course/lesson-10-the-game-loop/rotating-sprite/RotatingSprite.gd index 60a2fcd6c..628553e70 100644 --- a/course/lesson-10-the-game-loop/rotating-sprite/RotatingSprite.gd +++ b/course/lesson-10-the-game-loop/rotating-sprite/RotatingSprite.gd @@ -13,8 +13,9 @@ func _process(_delta): func _run() -> void: reset() - _process(0.0) set_process(true) + yield(get_tree().create_timer(1.0), "timeout") + Events.emit_signal("practice_run_completed") func reset() -> void: diff --git a/course/lesson-10-the-game-loop/rotating-sprite/RotatingSprite.live-editor/scene/RotatingSprite.tscn.tres b/course/lesson-10-the-game-loop/rotating-sprite/RotatingSprite.live-editor/scene/RotatingSprite.tscn.tres index 26ffaf340..777e6ed6a 100644 --- a/course/lesson-10-the-game-loop/rotating-sprite/RotatingSprite.live-editor/scene/RotatingSprite.tscn.tres +++ b/course/lesson-10-the-game-loop/rotating-sprite/RotatingSprite.live-editor/scene/RotatingSprite.tscn.tres @@ -1,9 +1,9 @@ [gd_resource type="Resource" load_steps=3 format=2] -[ext_resource path="res://course/lesson-10-the-game-loop/rotating-sprite/RotatingSprite.tscn" type="PackedScene" id=1] -[ext_resource path="res://addons/gdscript-slice-exporter/collections/SceneProperties.gd" type="Script" id=2] +[ext_resource path="res://addons/gdscript-slice-exporter/collections/SceneProperties.gd" type="Script" id=1] +[ext_resource path="res://course/lesson-10-the-game-loop/rotating-sprite/RotatingSprite.tscn" type="PackedScene" id=2] [resource] -script = ExtResource( 2 ) -scene = ExtResource( 1 ) +script = ExtResource( 1 ) +scene = ExtResource( 2 ) viewport_size = Vector2( 1920, 1080 ) diff --git a/course/lesson-10-the-game-loop/rotating-sprite/RotatingSprite.live-editor/scripts/RotatingSprite.gd.tres b/course/lesson-10-the-game-loop/rotating-sprite/RotatingSprite.live-editor/scripts/RotatingSprite.gd.tres index b676e9425..3e7a492cc 100644 --- a/course/lesson-10-the-game-loop/rotating-sprite/RotatingSprite.live-editor/scripts/RotatingSprite.gd.tres +++ b/course/lesson-10-the-game-loop/rotating-sprite/RotatingSprite.live-editor/scripts/RotatingSprite.gd.tres @@ -1,12 +1,12 @@ [gd_resource type="Resource" load_steps=3 format=2] -[ext_resource path="res://course/lesson-10-the-game-loop/rotating-sprite/RotatingSprite.gd" type="Script" id=1] -[ext_resource path="res://addons/gdscript-slice-exporter/collections/ScriptProperties.gd" type="Script" id=2] +[ext_resource path="res://addons/gdscript-slice-exporter/collections/ScriptProperties.gd" type="Script" id=1] +[ext_resource path="res://course/lesson-10-the-game-loop/rotating-sprite/RotatingSprite.gd" type="Script" id=2] [resource] -script = ExtResource( 2 ) +script = ExtResource( 1 ) nodes_paths = [ NodePath("RotatingSprite") ] -script_file = ExtResource( 1 ) +script_file = ExtResource( 2 ) original_script = "extends Node2D @@ -22,8 +22,9 @@ func _process(_delta): func _run() -> void: reset() - _process(0.0) set_process(true) + yield(get_tree().create_timer(1.0), \"timeout\") + Events.emit_signal(\"practice_run_completed\") func reset() -> void: diff --git a/course/lesson-10-the-game-loop/rotating-sprite/RotatingSprite.live-editor/slices/RotatingSprite.move_and_rotate.slice.tres b/course/lesson-10-the-game-loop/rotating-sprite/RotatingSprite.live-editor/slices/RotatingSprite.move_and_rotate.slice.tres index decc675e5..9c318b66e 100644 --- a/course/lesson-10-the-game-loop/rotating-sprite/RotatingSprite.live-editor/slices/RotatingSprite.move_and_rotate.slice.tres +++ b/course/lesson-10-the-game-loop/rotating-sprite/RotatingSprite.live-editor/slices/RotatingSprite.move_and_rotate.slice.tres @@ -1,13 +1,13 @@ [gd_resource type="Resource" load_steps=4 format=2] -[ext_resource path="res://course/lesson-10-the-game-loop/rotating-sprite/RotatingSprite.live-editor/scene/RotatingSprite.tscn.tres" type="Resource" id=1] -[ext_resource path="res://course/lesson-10-the-game-loop/rotating-sprite/RotatingSprite.live-editor/scripts/RotatingSprite.gd.tres" type="Resource" id=2] -[ext_resource path="res://addons/gdscript-slice-exporter/collections/SliceProperties.gd" type="Script" id=3] +[ext_resource path="res://addons/gdscript-slice-exporter/collections/SliceProperties.gd" type="Script" id=1] +[ext_resource path="res://course/lesson-10-the-game-loop/rotating-sprite/RotatingSprite.live-editor/scene/RotatingSprite.tscn.tres" type="Resource" id=2] +[ext_resource path="res://course/lesson-10-the-game-loop/rotating-sprite/RotatingSprite.live-editor/scripts/RotatingSprite.gd.tres" type="Resource" id=3] [resource] -script = ExtResource( 3 ) -scene_properties = ExtResource( 1 ) -script_properties = ExtResource( 2 ) +script = ExtResource( 1 ) +scene_properties = ExtResource( 2 ) +script_properties = ExtResource( 3 ) leading_spaces = 0 keyword = "EXPORT" closing = false @@ -16,5 +16,5 @@ is_full_file = false start = 7 end = 10 lines_before = [ "extends Node2D", "", "", "func _ready() -> void:", " set_process(false)", "", "" ] -lines_after = [ "", "", "func _run() -> void:", " reset()", " _process(0.0)", " set_process(true)", "", "", "func reset() -> void:", " rotation = 0.0", " set_process(false)", "" ] +lines_after = [ "", "", "func _run() -> void:", " reset()", " set_process(true)", " yield(get_tree().create_timer(1.0), \"timeout\")", " Events.emit_signal(\"practice_run_completed\")", "", "", "func reset() -> void:", " rotation = 0.0", " set_process(false)", "" ] lines_editable = [ "func _process(_delta):", " rotate(0.05)" ] diff --git a/course/lesson-10-the-game-loop/rotating-sprite/TestsRotating.gd b/course/lesson-10-the-game-loop/rotating-sprite/TestsRotating.gd index 6e4544088..3674ffbc2 100644 --- a/course/lesson-10-the-game-loop/rotating-sprite/TestsRotating.gd +++ b/course/lesson-10-the-game-loop/rotating-sprite/TestsRotating.gd @@ -1,13 +1,9 @@ extends PracticeTester -func test_character_is_rotating_slowly() -> String: +func test_character_is_rotating_clockwise() -> String: var node_2d = _scene_root_viewport.get_child(0).get_child(0) var node_rotation = node_2d.rotation if node_rotation < 0.0: return "The robot is turning in the wrong direction!" - elif node_rotation > 0.06: - return "The robot is turning too fast!" - elif not is_equal_approx(node_rotation, 0.05): - return "The robot's rotation speed isn't right." return ""