Skip to content

Commit

Permalink
Move projectiles to layer 2, add enemy mask 2
Browse files Browse the repository at this point in the history
This moves projectiles to a new collision layer, and adds that layer
to the mask for enemies.

This is to do two things: (1) Prevent lasers from colliding with
themselves ("Huge" and "Double" lasers can overlap), (2) allow enemies
to queue_free themselves, instead of leaving that burden on the projectile
  • Loading branch information
Checkroth committed Aug 19, 2024
1 parent f08db8e commit 82f3f7f
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 2 deletions.
3 changes: 3 additions & 0 deletions units/enemy.gd
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,6 @@ func _physics_process(delta):

func _on_visible_on_screen_notifier_2d_screen_exited():
queue_free()

func _on_area_entered(area):
queue_free()
4 changes: 3 additions & 1 deletion units/enemy.tscn
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[gd_scene load_steps=4 format=3 uid="uid://4fjgeuv7aun7"]
[gd_scene load_steps=4 format=3 uid="uid://bdsjg08y1h6yh"]

[ext_resource type="Script" path="res://units/enemy.gd" id="1_6h8a0"]
[ext_resource type="Texture2D" uid="uid://dqkvsqmwue64p" path="res://units/PNG_Parts&Spriter_Animation/Ship1/Ship1.png" id="1_ndkjl"]
Expand All @@ -13,11 +13,13 @@ script = ExtResource("1_6h8a0")
texture = ExtResource("1_ndkjl")

[node name="Area2D" type="Area2D" parent="."]
collision_mask = 3

[node name="CollisionShape2D" type="CollisionShape2D" parent="Area2D"]
position = Vector2(0, -0.75)
shape = SubResource("RectangleShape2D_mvxux")

[node name="VisibleOnScreenNotifier2D" type="VisibleOnScreenNotifier2D" parent="."]

[connection signal="area_entered" from="Area2D" to="." method="_on_area_entered"]
[connection signal="screen_exited" from="VisibleOnScreenNotifier2D" to="." method="_on_visible_on_screen_notifier_2d_screen_exited"]
1 change: 0 additions & 1 deletion units/projectile.gd
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ func _physics_process(delta):
func _on_area_entered(area):
# TODO: apply effects on enemy hit. For now just despawn.
queue_free()
area.owner.queue_free()

func _integrate_forces(delta):
scale = Vector2(100, 100)
1 change: 1 addition & 0 deletions units/projectile.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ radius = 4.0

[node name="Projectile" type="Area2D"]
position = Vector2(68, 1)
collision_layer = 2
script = ExtResource("1_t6pyo")

[node name="Sprite2D" type="Sprite2D" parent="."]
Expand Down

0 comments on commit 82f3f7f

Please sign in to comment.