Tutorial3
parent
a7875e29b7
commit
3b26592bb6
@ -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<Sprite2D>("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;
|
||||
}
|
||||
}
|
||||
@ -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<Sprite2D>("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);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,17 @@
|
||||
using Godot;
|
||||
|
||||
namespace Tutorial1.Scripts;
|
||||
|
||||
public partial class World : Node2D {
|
||||
private PackedScene packedScene;
|
||||
public override void _Ready() => packedScene = GD.Load<PackedScene>("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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -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)
|
||||
Loading…
Reference in New Issue