diff --git a/Abdullah.cs b/Abdullah.cs deleted file mode 100644 index f93c46a..0000000 --- a/Abdullah.cs +++ /dev/null @@ -1,18 +0,0 @@ -using Godot; - -namespace Tutorial1; - -public partial class Abdullah : Sprite2D { - private const int AMOUNT = 5; - private Sprite2D child; - - public override void _Ready() => child = GetNode("Child"); - - public override void _Process(double delta) { - if (Input.IsKeyPressed(Key.W)) Position += new Vector2(0, -AMOUNT); - if (Input.IsKeyPressed(Key.S)) Position += new Vector2(0, AMOUNT); - if (Input.IsKeyPressed(Key.A)) Position += new Vector2(-AMOUNT, 0); - if (Input.IsKeyPressed(Key.D)) Position += new Vector2(AMOUNT, 0); - if (Input.IsKeyPressed(Key.Space)) child.GlobalPosition = Vector2.Zero; - } -} \ No newline at end of file diff --git a/Abdullah.tscn b/Abdullah.tscn index 9fd390e..e11e451 100644 --- a/Abdullah.tscn +++ b/Abdullah.tscn @@ -1,13 +1,13 @@ [gd_scene load_steps=4 format=3 uid="uid://bdbubb2tx11e8"] [ext_resource type="Texture2D" uid="uid://d0ft51rdr6k02" path="res://Icons/Godot.svg" id="1_h0rd0"] -[ext_resource type="Script" path="res://Abdullah.cs" id="2_4iohr"] +[ext_resource type="Script" path="res://Scripts/Abdullah.cs" id="2_4tdcf"] [ext_resource type="Texture2D" uid="uid://b202jnjsma8y4" path="res://Icons/Tomato.png" id="3_ffpuj"] [node name="Abdullah" type="Sprite2D"] position = Vector2(460, 266) texture = ExtResource("1_h0rd0") -script = ExtResource("2_4iohr") +script = ExtResource("2_4tdcf") [node name="Child" type="Sprite2D" parent="."] position = Vector2(100, 100) diff --git a/Scripts/Abdullah.cs b/Scripts/Abdullah.cs new file mode 100644 index 0000000..7a113fc --- /dev/null +++ b/Scripts/Abdullah.cs @@ -0,0 +1,18 @@ +using Godot; + +namespace Tutorial1.Scripts; + +public partial class Abdullah : Sprite2D { + private const int AMOUNT = 5; + private Sprite2D child; + + public override void _Ready() => child = GetNode("Child"); + + public override void _Process(double delta) { + uint randomNumber = GD.Randi() % 4; + if (randomNumber == 0) Position += new Vector2(0, -AMOUNT); + if (randomNumber == 1) Position += new Vector2(0, AMOUNT); + if (randomNumber == 2) Position += new Vector2(-AMOUNT, 0); + if (randomNumber == 3) Position += new Vector2(AMOUNT, 0); + } +} \ No newline at end of file diff --git a/Scripts/World.cs b/Scripts/World.cs new file mode 100644 index 0000000..8d11234 --- /dev/null +++ b/Scripts/World.cs @@ -0,0 +1,17 @@ +using Godot; + +namespace Tutorial1.Scripts; + +public partial class World : Node2D { + private PackedScene packedScene; + public override void _Ready() => packedScene = GD.Load("res://Abdullah.tscn"); + + public override void _UnhandledInput(InputEvent @event) { + if (@event is InputEventMouseButton mouseEvent) + //Create instance of Sprite scene + if (packedScene.Instantiate() is Sprite2D abdullah) { + abdullah.Position = mouseEvent.Position; + AddChild(abdullah); + } + } +} \ No newline at end of file diff --git a/World.tscn b/World.tscn new file mode 100644 index 0000000..4a15d68 --- /dev/null +++ b/World.tscn @@ -0,0 +1,16 @@ +[gd_scene load_steps=3 format=3 uid="uid://cefeqjem0f3wo"] + +[ext_resource type="PackedScene" uid="uid://bdbubb2tx11e8" path="res://Abdullah.tscn" id="1_0rt2v"] +[ext_resource type="Script" path="res://Scripts/World.cs" id="1_4gg20"] + +[node name="World" type="Node2D"] +script = ExtResource("1_4gg20") + +[node name="Abdullah" parent="." instance=ExtResource("1_0rt2v")] +position = Vector2(540, 144) + +[node name="Abdullah2" parent="." instance=ExtResource("1_0rt2v")] +position = Vector2(206, 268) + +[node name="Abdullah3" parent="." instance=ExtResource("1_0rt2v")] +position = Vector2(855, 424) diff --git a/project.godot b/project.godot index 1879080..25a491d 100644 --- a/project.godot +++ b/project.godot @@ -11,9 +11,9 @@ config_version=5 [application] config/name="Tutorial1" -run/main_scene="res://Abdullah.tscn" +run/main_scene="res://World.tscn" config/features=PackedStringArray("4.1", "C#", "Forward Plus") -config/icon="res://icon.svg" +config/icon="res://Icons/Godot.svg" [dotnet]