From 9753d64712fff099cf35d57c591b1996de9c7052 Mon Sep 17 00:00:00 2001 From: Laegnur Date: Wed, 11 Sep 2024 19:03:50 +0200 Subject: [PATCH] Step by step - Using signals --- assets/{ => img}/Bouncy Platform Long.png | Bin .../{ => img}/Bouncy Platform Long.png.import | 6 ++-- assets/{ => img}/Bouncy Platform Medium.png | Bin .../Bouncy Platform Medium.png.import | 6 ++-- assets/{ => img}/ballBlue_10.png | Bin assets/{ => img}/ballBlue_10.png.import | 6 ++-- project.godot | 2 +- scenes/ball.tscn | 2 +- scenes/{main.tscn => balls.tscn} | 4 +-- scenes/button.tscn | 19 +++++++++++++ scripts/{main.gd => balls.gd} | 0 scripts/icon.gd | 26 ++++++++++-------- 12 files changed, 46 insertions(+), 25 deletions(-) rename assets/{ => img}/Bouncy Platform Long.png (100%) rename assets/{ => img}/Bouncy Platform Long.png.import (69%) rename assets/{ => img}/Bouncy Platform Medium.png (100%) rename assets/{ => img}/Bouncy Platform Medium.png.import (68%) rename assets/{ => img}/ballBlue_10.png (100%) rename assets/{ => img}/ballBlue_10.png.import (71%) rename scenes/{main.tscn => balls.tscn} (97%) create mode 100644 scenes/button.tscn rename scripts/{main.gd => balls.gd} (100%) diff --git a/assets/Bouncy Platform Long.png b/assets/img/Bouncy Platform Long.png similarity index 100% rename from assets/Bouncy Platform Long.png rename to assets/img/Bouncy Platform Long.png diff --git a/assets/Bouncy Platform Long.png.import b/assets/img/Bouncy Platform Long.png.import similarity index 69% rename from assets/Bouncy Platform Long.png.import rename to assets/img/Bouncy Platform Long.png.import index 6c8f690..9c5f7bb 100644 --- a/assets/Bouncy Platform Long.png.import +++ b/assets/img/Bouncy Platform Long.png.import @@ -3,15 +3,15 @@ importer="texture" type="CompressedTexture2D" uid="uid://dkq1swbmmxmbq" -path="res://.godot/imported/Bouncy Platform Long.png-9b2628c180785c5ec622adb5c4ee7b17.ctex" +path="res://.godot/imported/Bouncy Platform Long.png-9922f702bfe5975e9b12c011e324e6e1.ctex" metadata={ "vram_texture": false } [deps] -source_file="res://assets/Bouncy Platform Long.png" -dest_files=["res://.godot/imported/Bouncy Platform Long.png-9b2628c180785c5ec622adb5c4ee7b17.ctex"] +source_file="res://assets/img/Bouncy Platform Long.png" +dest_files=["res://.godot/imported/Bouncy Platform Long.png-9922f702bfe5975e9b12c011e324e6e1.ctex"] [params] diff --git a/assets/Bouncy Platform Medium.png b/assets/img/Bouncy Platform Medium.png similarity index 100% rename from assets/Bouncy Platform Medium.png rename to assets/img/Bouncy Platform Medium.png diff --git a/assets/Bouncy Platform Medium.png.import b/assets/img/Bouncy Platform Medium.png.import similarity index 68% rename from assets/Bouncy Platform Medium.png.import rename to assets/img/Bouncy Platform Medium.png.import index 03dcd2b..2008aff 100644 --- a/assets/Bouncy Platform Medium.png.import +++ b/assets/img/Bouncy Platform Medium.png.import @@ -3,15 +3,15 @@ importer="texture" type="CompressedTexture2D" uid="uid://blqm0e7gm75u3" -path="res://.godot/imported/Bouncy Platform Medium.png-7896338a5f44da1e83084c154a3c4a9e.ctex" +path="res://.godot/imported/Bouncy Platform Medium.png-ff51edd1d52c01a38d58a533c35f8a59.ctex" metadata={ "vram_texture": false } [deps] -source_file="res://assets/Bouncy Platform Medium.png" -dest_files=["res://.godot/imported/Bouncy Platform Medium.png-7896338a5f44da1e83084c154a3c4a9e.ctex"] +source_file="res://assets/img/Bouncy Platform Medium.png" +dest_files=["res://.godot/imported/Bouncy Platform Medium.png-ff51edd1d52c01a38d58a533c35f8a59.ctex"] [params] diff --git a/assets/ballBlue_10.png b/assets/img/ballBlue_10.png similarity index 100% rename from assets/ballBlue_10.png rename to assets/img/ballBlue_10.png diff --git a/assets/ballBlue_10.png.import b/assets/img/ballBlue_10.png.import similarity index 71% rename from assets/ballBlue_10.png.import rename to assets/img/ballBlue_10.png.import index 936661b..cb791a6 100644 --- a/assets/ballBlue_10.png.import +++ b/assets/img/ballBlue_10.png.import @@ -3,15 +3,15 @@ importer="texture" type="CompressedTexture2D" uid="uid://dv6rx85s1gy3i" -path="res://.godot/imported/ballBlue_10.png-a6ac20f1eeff46860499a0f8c7bba4ff.ctex" +path="res://.godot/imported/ballBlue_10.png-83cd69a8a910b68487ca4d42f1af5893.ctex" metadata={ "vram_texture": false } [deps] -source_file="res://assets/ballBlue_10.png" -dest_files=["res://.godot/imported/ballBlue_10.png-a6ac20f1eeff46860499a0f8c7bba4ff.ctex"] +source_file="res://assets/img/ballBlue_10.png" +dest_files=["res://.godot/imported/ballBlue_10.png-83cd69a8a910b68487ca4d42f1af5893.ctex"] [params] diff --git a/project.godot b/project.godot index 83ee48c..a1da7ba 100644 --- a/project.godot +++ b/project.godot @@ -11,7 +11,7 @@ config_version=5 [application] config/name="Godot Docs" -run/main_scene="res://scenes/main.tscn" +run/main_scene="res://scenes/balls.tscn" config/features=PackedStringArray("4.3", "Forward Plus") config/icon="res://icon.png" diff --git a/scenes/ball.tscn b/scenes/ball.tscn index 8414640..c80b947 100644 --- a/scenes/ball.tscn +++ b/scenes/ball.tscn @@ -1,6 +1,6 @@ [gd_scene load_steps=4 format=3 uid="uid://dm5jrnxmxnuof"] -[ext_resource type="Texture2D" uid="uid://dv6rx85s1gy3i" path="res://assets/ballBlue_10.png" id="1"] +[ext_resource type="Texture2D" uid="uid://dv6rx85s1gy3i" path="res://assets/img/ballBlue_10.png" id="1"] [sub_resource type="PhysicsMaterial" id="1"] bounce = 0.5 diff --git a/scenes/main.tscn b/scenes/balls.tscn similarity index 97% rename from scenes/main.tscn rename to scenes/balls.tscn index b6ea510..429736e 100644 --- a/scenes/main.tscn +++ b/scenes/balls.tscn @@ -1,8 +1,8 @@ [gd_scene load_steps=13 format=3 uid="uid://coq78ajuagqrq"] -[ext_resource type="Script" path="res://scripts/main.gd" id="1"] +[ext_resource type="Script" path="res://scripts/balls.gd" id="1"] [ext_resource type="PackedScene" uid="uid://dm5jrnxmxnuof" path="res://scenes/ball.tscn" id="2"] -[ext_resource type="Texture2D" uid="uid://dkq1swbmmxmbq" path="res://assets/Bouncy Platform Long.png" id="3"] +[ext_resource type="Texture2D" uid="uid://dkq1swbmmxmbq" path="res://assets/img/Bouncy Platform Long.png" id="3"] [sub_resource type="PhysicsMaterial" id="1"] bounce = 0.5 diff --git a/scenes/button.tscn b/scenes/button.tscn new file mode 100644 index 0000000..7d29af3 --- /dev/null +++ b/scenes/button.tscn @@ -0,0 +1,19 @@ +[gd_scene load_steps=2 format=3 uid="uid://cn4bsud8kgyvp"] + +[ext_resource type="PackedScene" uid="uid://6ws803s4tnhy" path="res://scenes/icon.tscn" id="1_or1o1"] + +[node name="Node2D" type="Node2D"] + +[node name="Icon" parent="." instance=ExtResource("1_or1o1")] + +[node name="Timer" type="Timer" parent="Icon"] +autostart = true + +[node name="Button" type="Button" parent="."] +offset_left = 48.0 +offset_top = 33.0 +offset_right = 238.0 +offset_bottom = 108.0 +text = "Toggle motion" + +[connection signal="pressed" from="Button" to="Icon" method="_on_button_pressed"] diff --git a/scripts/main.gd b/scripts/balls.gd similarity index 100% rename from scripts/main.gd rename to scripts/balls.gd diff --git a/scripts/icon.gd b/scripts/icon.gd index 91de13e..6c7bd70 100644 --- a/scripts/icon.gd +++ b/scripts/icon.gd @@ -3,17 +3,19 @@ extends Sprite2D var speed = 400 var angular_speed = PI +func _ready(): + var timer = get_node("Timer") + timer.timeout.connect(_on_timer_timeout) + func _process(delta: float) -> void: - var direction = 0 - if Input.is_action_pressed("ui_left"): - direction = -1 - if Input.is_action_pressed("ui_right"): - direction = 1 - - rotation += angular_speed * direction * delta - - var velocity = Vector2.ZERO - if Input.is_action_pressed("ui_up"): - velocity = Vector2.UP.rotated(rotation) * speed - + rotation += angular_speed * delta + var velocity = Vector2.UP.rotated(rotation) * speed position += velocity * delta + + +func _on_button_pressed() -> void: + set_process(not is_processing()) + + +func _on_timer_timeout(): + visible = not visible