From 138555729892550cd772e69a7fe913288fa4e3ab Mon Sep 17 00:00:00 2001 From: ronny abraham Date: Tue, 17 Dec 2024 14:08:25 +0200 Subject: [PATCH] halfway through overview of gem catcher --- _subsections/sec03/lesson-30.org | 76 ++++++++++++++++++++++++++++++++ 1 file changed, 76 insertions(+) create mode 100644 _subsections/sec03/lesson-30.org diff --git a/_subsections/sec03/lesson-30.org b/_subsections/sec03/lesson-30.org new file mode 100644 index 0000000..d95da9a --- /dev/null +++ b/_subsections/sec03/lesson-30.org @@ -0,0 +1,76 @@ +#+title: Section 03 - Lesson 30 | Section Review +#+HTML_HEAD: + +* Links +- [[../../toc.org][TOC - Godot Notes]] +- [[https://www.udemy.com/course/jumpstart-to-2d-game-development-godot-4-for-beginners/learn/lecture/45070537#overview][S03:L42.30 - Section Review]] + +* Notes + +** paddle scene +*** node composition +- root: Area2D +- Sprite2D +- CollisionShape2D + +*** script view: paddle.gd +- extends Area2D + +**** use *@export* to create speed variable + - can be modified in Inspector + - give default value + +**** override _process function + - check if =Input.is_action_pressed= + - is 'left' + - is 'right' + + - move paddle + - get the Node2D.position property + - multiply speed by delta and add or subtract it from position.x + - delta is number of seconds that elapsed since the previous frame + +** gem scene +*** node composition +- root: Area2D +- Sprite2D +- CollisionShape2D + +*** script view: gem.gd +- extends Area2D + +**** set class name +- =class_name Gem= +- this allows us to instantiate Gem objects in scripts + +**** set a signal property +- =signal on_gem_off_screen= +- allows us to attach listeners who will be notified when we emit a signal + +**** set export property +- =@export var speed= +- lets us set the speed in the Inspector + +*** modify _process +**** determine if the gem has gone out of bounds +- this is going to be the edge of the viewport +- check position property against the viewport rect property + #+begin_src gdscript + if position.y > get_viewport_rect().size.y + #+end_src + +**** if gem went out of bounds +***** emit signal +#+begin_src gdscript +on_gem_off_screen.emit() +#+end_src + +***** stop the gem and remove it from the node tree +- stop going through the process function +- delete node at the end of the current frame +#+begin_src gdscript +set_process(false) +queue_free() +#+end_src + +** Game scene