aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorfreddie-a <57713959+freddie-a@users.noreply.github.com>2022-10-29 22:45:55 +0100
committerfreddie-a <57713959+freddie-a@users.noreply.github.com>2022-10-29 22:45:55 +0100
commit136c6918c7d9f3ebe12c4535c438a2c67f01c110 (patch)
tree66360dea71d9c02b2d2f8d864e6ee0448c7b6e0a
parenta4ac6fe79a37824f3f720f4a3c468172461f70d7 (diff)
Add bullet collisions
-rw-r--r--Bullet.gd7
-rw-r--r--Bullet.tscn7
-rw-r--r--Enemy0.tscn2
-rw-r--r--KinematicBody2D.gd2
4 files changed, 10 insertions, 8 deletions
diff --git a/Bullet.gd b/Bullet.gd
index b2058ba..9e64b08 100644
--- a/Bullet.gd
+++ b/Bullet.gd
@@ -13,7 +13,12 @@ func _physics_process(delta):
velocity = global_position.direction_to(target) * speed
shot = true
velocity = move_and_slide(velocity)
-
+ for i in get_slide_count():
+ var collision = get_slide_collision(i)
+ if collision.collider:
+ collision.collider.free()
+ if velocity == Vector2(0.0, 0.0):
+ queue_free()
diff --git a/Bullet.tscn b/Bullet.tscn
index d2f4c14..f79445f 100644
--- a/Bullet.tscn
+++ b/Bullet.tscn
@@ -3,17 +3,14 @@
[ext_resource path="res://Bullet.gd" type="Script" id=1]
[ext_resource path="res://icon.png" type="Texture" id=2]
-[sub_resource type="CapsuleShape2D" id=1]
-radius = 8.0
+[sub_resource type="RectangleShape2D" id=1]
+extents = Vector2( 31, 31 )
[node name="Bullet" type="KinematicBody2D"]
-position = Vector2( 648, 360 )
script = ExtResource( 1 )
[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
-position = Vector2( -1, 1 )
shape = SubResource( 1 )
-disabled = true
[node name="Sprite" type="Sprite" parent="."]
texture = ExtResource( 2 )
diff --git a/Enemy0.tscn b/Enemy0.tscn
index 306afd6..225f15c 100644
--- a/Enemy0.tscn
+++ b/Enemy0.tscn
@@ -3,7 +3,7 @@
[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"]
+[node name="Enemy" type="KinematicBody2D"]
script = ExtResource( 2 )
[node name="Sprite" type="Sprite" parent="."]
diff --git a/KinematicBody2D.gd b/KinematicBody2D.gd
index 4f2949c..96484f3 100644
--- a/KinematicBody2D.gd
+++ b/KinematicBody2D.gd
@@ -34,5 +34,5 @@ func _physics_process(delta):
get_owner().add_child(obj)
var bodies = get_overlapping_bodies()
for body in bodies:
- if body.get_name() != "Bullet":
+ if not "Bullet" in body.get_name():
emit_signal("hit", delta)