aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorfreddie-a <57713959+freddie-a@users.noreply.github.com>2022-10-29 17:43:42 +0100
committerfreddie-a <57713959+freddie-a@users.noreply.github.com>2022-10-29 17:43:42 +0100
commite8204e78a292551bbb363d53411ba959cdc737b4 (patch)
tree9839cde235d31896900cf20f9240ab063d8b0d4d
parent1f7f6c8dc3e55e906ed5f933088c2d1d5fda4923 (diff)
Add homing projectiles
-rw-r--r--Enemy0.gd17
-rw-r--r--Enemy0.tscn9
-rw-r--r--Global.gd17
-rw-r--r--KinematicBody2D.gd2
-rw-r--r--Main.gd29
-rw-r--r--Node2D.gd16
-rw-r--r--Node2D.tscn22
-rw-r--r--Player.tscn1
-rw-r--r--project.godot4
9 files changed, 109 insertions, 8 deletions
diff --git a/Enemy0.gd b/Enemy0.gd
new file mode 100644
index 0000000..ecfb99c
--- /dev/null
+++ b/Enemy0.gd
@@ -0,0 +1,17 @@
+extends KinematicBody2D
+
+
+# Declare member variables here. Examples:
+# var a = 2
+# var b = "text"
+# var player = get_node("")
+onready var globals = get_node("/root/Global")
+
+# Called when the node enters the scene tree for the first time.
+func _ready():
+ pass # Replace with function body.
+
+
+# Called every frame. 'delta' is the elapsed time since the previous frame.
+func _process(delta):
+ move_and_collide(global_position.direction_to(globals.playerPos).normalized() * 2)
diff --git a/Enemy0.tscn b/Enemy0.tscn
index b3d156e..306afd6 100644
--- a/Enemy0.tscn
+++ b/Enemy0.tscn
@@ -1,18 +1,19 @@
-[gd_scene load_steps=2 format=2]
+[gd_scene load_steps=3 format=2]
[ext_resource path="res://assets/Likkan-boss.png" type="Texture" id=1]
+[ext_resource path="res://Enemy0.gd" type="Script" id=2]
[node name="KinematicBody2D" type="KinematicBody2D"]
+script = ExtResource( 2 )
[node name="Sprite" type="Sprite" parent="."]
-position = Vector2( 304, 313 )
+position = Vector2( 7.62939e-06, 3.8147e-06 )
scale = Vector2( 0.1, 0.1 )
texture = ExtResource( 1 )
[node name="VisibilityNotifier2D" type="VisibilityNotifier2D" parent="."]
-position = Vector2( 304, 313 )
[node name="CollisionPolygon2D" type="CollisionPolygon2D" parent="."]
-position = Vector2( 304, 313 )
+position = Vector2( 1.52588e-05, -9.53674e-07 )
scale = Vector2( 0.1, 0.1 )
polygon = PoolVector2Array( 78, -247, 78, -244.6, 91, -223.6, 91, -219.4, 96.6, -190.4, 139, -208.3, 139, -209.2, 169.5, -225, 173.7, -225, 186.7, -229, 201.9, -229, 218, -230.1, 218, -228.7, 233, -225.6, 233, -224.3, 242, -220.3, 242, -218.8, 250, -210, 250, -182.2, 239.1, -165, 237.7, -165, 209.7, -142, 207.5, -142, 146.5, -111, 143.3, -111, 116, -102.5, 116, -99.9, 109.8, -48, 108.2, -48, 102, -34.6, 102, -33.3, 106, -24, 103.7, -24, 97.3, 15.4, 102, 21.3, 102, 30, 100, 30, 96, 35, 92.1, 35, 90, 35.5, 90, 38.4, 82.3, 57, 81.1, 57, 74.2, 67.3, 91, 85.2, 91, 100.8, 80, 112.8, 81.3, 123, 79.4, 123, 78.6, 125.6, 91, 132.2, 91, 131.6, 88.7, 128.1, 89.8, 126, 91.5, 126, 105, 117.9, 105, 112.7, 108.6, 102, 110, 102, 118, 92, 120.5, 92, 139, 80.9, 139, 80, 227.8, 13.1, 224.8, 7, 227.9, 7, 229.9, 4, 233.4, 4, 236.7, 5.3, 245, 2, 245, 5.10001, 250, 9.39999, 250, 22.5, 230, 37, 235, 43.3, 235, 52, 233, 52, 229, 57, 226.6, 57, 183, 88, 183, 90.4, 190.3, 101.9, 189.2, 104, 187.7, 104, 168, 119, 168, 128, 166, 128, 163, 131.7, 171, 140.2, 171, 149.6, 167.1, 156, 165.7, 156, 152.7, 167, 146.7, 167, 139.5, 164.6, 147, 174.3, 147, 177.6, 155, 195.6, 155, 200, 161, 225.8, 161, 234, 162, 250, -250, 250, -250, 137, -228.5, 125, -225.4, 125, -162, 102.6, -162, 101.7, -132, 88.7, -132, 85.3, -119, 69, -116.6, 69, -112, 65.9, -112, 65.3, -114.8, 57, -112.4, 57, -110.4, 52, -108.8, 52, -102.8, 46, -100.4, 46, -94, 43.6, -94, 42.4, -86, 30.4, -86, 26, -91.8, 26, -102, 16.9, -102, 10.5, -100.7, 8, -105, -4.7, -105, -27.1, -102.8, -45, -100.8, -45, -96, -49.8, -96, -51, -102, -74.8, -102, -76, -101.1, -97.2, -180, -112.3, -180, -113.6, -232, -130.5, -232, -131.7, -239, -134.7, -239, -136.3, -250, -149, -250, -175, -235.9, -190, -233.4, -190, -210.3, -198, -186.8, -198, -139, -190.7, -139, -189.5, -85.7, -176.4, -75.6, -224, -74.3, -224, -69.3, -235, -67.8, -235, -58.8, -244, -56.5, -244, -51.6, -247, -38, -247, -38, -245.5, -30, -243.6, -30, -241.8, -8.2, -219, -6.8, -219, 7.10001, -215.5, 21, -219.5, 40, -246, 41.3, -246, 46, -249.9, 74, -250 )
diff --git a/Global.gd b/Global.gd
new file mode 100644
index 0000000..51a7a8e
--- /dev/null
+++ b/Global.gd
@@ -0,0 +1,17 @@
+extends Node
+
+
+# Declare member variables here. Examples:
+# var a = 2
+# var b = "text"
+var playerPos
+
+
+# Called when the node enters the scene tree for the first time.
+func _ready():
+ pass # Replace with function body.
+
+
+# Called every frame. 'delta' is the elapsed time since the previous frame.
+#func _process(delta):
+# pass
diff --git a/KinematicBody2D.gd b/KinematicBody2D.gd
index a1a3770..03dd45f 100644
--- a/KinematicBody2D.gd
+++ b/KinematicBody2D.gd
@@ -3,6 +3,7 @@ extends KinematicBody2D
export (int) var speed = 200
var spawn_object = load("res://Bullet.tscn")
var velocity = Vector2()
+onready var globals = get_node("/root/Global")
func get_input():
velocity = Vector2()
@@ -21,6 +22,7 @@ func _physics_process(delta):
get_input()
+ globals.playerPos = global_position
velocity = move_and_slide(velocity)
if Input.is_action_just_pressed("click"):
var obj = spawn_object.instance()
diff --git a/Main.gd b/Main.gd
new file mode 100644
index 0000000..958a7a7
--- /dev/null
+++ b/Main.gd
@@ -0,0 +1,29 @@
+extends Node2D
+
+export(PackedScene) var enemy_scene
+# Declare member variables here. Examples:
+# var a = 2
+# var b = "text"
+onready var globals = get_node("/root/Global")
+
+# Called when the node enters the scene tree for the first time.
+func _ready():
+ randomize()
+ $EnemySpawnTimer.start()
+
+
+# Called every frame. 'delta' is the elapsed time since the previous frame.
+#func _process(delta):
+# pass
+
+
+func _on_EnemySpawnTimer_timeout():
+ var enemy = enemy_scene.instance()
+ var spawn_loc = get_node("EnemySpawn/EnemySpawnLocation")
+ spawn_loc.offset = randi()
+ #var direction = spawn_loc.rotation + PI / 2
+ enemy.position = spawn_loc.position
+ #enemy.rotation = enemy.position.angle_to_point(globals.playerPos)
+ #var velocity = Vector2(rand_range(150.0, 250.0), 0.0)
+ #enemy.linear_velocity = velocity.rotated(direction)
+ add_child(enemy)
diff --git a/Node2D.gd b/Node2D.gd
new file mode 100644
index 0000000..d144d48
--- /dev/null
+++ b/Node2D.gd
@@ -0,0 +1,16 @@
+extends Node2D
+
+
+# Declare member variables here. Examples:
+# var a = 2
+# var b = "text"
+
+
+# Called when the node enters the scene tree for the first time.
+func _ready():
+ pass # Replace with function body.
+
+
+# Called every frame. 'delta' is the elapsed time since the previous frame.
+#func _process(delta):
+# pass
diff --git a/Node2D.tscn b/Node2D.tscn
index 612e27f..f7dfb2a 100644
--- a/Node2D.tscn
+++ b/Node2D.tscn
@@ -1,11 +1,19 @@
-[gd_scene load_steps=5 format=2]
+[gd_scene load_steps=6 format=2]
[ext_resource path="res://HUD.tscn" type="PackedScene" id=1]
[ext_resource path="res://Player.tscn" type="PackedScene" id=2]
[ext_resource path="res://Enemy0.tscn" type="PackedScene" id=3]
[ext_resource path="res://Bullet.tscn" type="PackedScene" id=4]
+[ext_resource path="res://Main.gd" type="Script" id=4]
-[node name="Node" type="Node2D"]
+[sub_resource type="Curve2D" id=1]
+_data = {
+"points": PoolVector2Array( 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1280, 0, 0, 0, 0, 0, 1280, 720, 0, 0, 0, 0, 0, 720, 0, 0, 0, 0, 0, 0 )
+}
+
+[node name="Main" type="Node2D"]
+script = ExtResource( 4 )
+enemy_scene = ExtResource( 3 )
[node name="KinematicBody2D" parent="." instance=ExtResource( 2 )]
position = Vector2( 544, 216 )
@@ -17,4 +25,12 @@ position = Vector2( 4, 9 )
[node name="HUD" parent="." instance=ExtResource( 1 )]
-[node name="RigidBody2D" parent="." instance=ExtResource( 3 )]
+[node name="EnemySpawn" type="Path2D" parent="."]
+curve = SubResource( 1 )
+
+[node name="EnemySpawnLocation" type="PathFollow2D" parent="EnemySpawn"]
+
+[node name="EnemySpawnTimer" type="Timer" parent="."]
+wait_time = 1.504
+
+[connection signal="timeout" from="EnemySpawnTimer" to="." method="_on_EnemySpawnTimer_timeout"]
diff --git a/Player.tscn b/Player.tscn
index dd8180b..e8cef48 100644
--- a/Player.tscn
+++ b/Player.tscn
@@ -6,7 +6,6 @@
[sub_resource type="CircleShape2D" id=1]
[node name="KinematicBody2D" type="KinematicBody2D"]
-position = Vector2( 299, 140 )
input_pickable = true
script = ExtResource( 1 )
diff --git a/project.godot b/project.godot
index 04d6f9c..a6eab52 100644
--- a/project.godot
+++ b/project.godot
@@ -14,6 +14,10 @@ config/name="TowerDefence"
run/main_scene="res://Node2D.tscn"
config/icon="res://icon.png"
+[autoload]
+
+Global="*res://Global.gd"
+
[display]
window/size/width=1280