Skip to content

Commit

Permalink
Merge pull request #3 from campenr/feature/damage-enemies
Browse files Browse the repository at this point in the history
feat: add basic logic to despawn enemies when hit by a projectile
  • Loading branch information
Checkroth authored Aug 19, 2024
2 parents 8297e02 + 2486958 commit 7055eab
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 2 deletions.
4 changes: 4 additions & 0 deletions project.godot
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ run/main_scene="res://levels/game.tscn"
config/features=PackedStringArray("4.3", "GL Compatibility")
config/icon="res://icon.svg"

[display]

window/size/always_on_top=true

[input]

up={
Expand Down
4 changes: 4 additions & 0 deletions units/enemy.gd
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,7 @@ const SPEED = 150

func _physics_process(delta):
position -= transform.x * SPEED * delta


func _on_visible_on_screen_notifier_2d_screen_exited():
queue_free()
8 changes: 6 additions & 2 deletions units/enemy.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
[ext_resource type="Texture2D" uid="uid://dqkvsqmwue64p" path="res://units/PNG_Parts&Spriter_Animation/Ship1/Ship1.png" id="1_ndkjl"]

[sub_resource type="RectangleShape2D" id="RectangleShape2D_mvxux"]
size = Vector2(53, 26)
size = Vector2(86, 45.5)

[node name="Enemy" type="Node2D"]
script = ExtResource("1_6h8a0")
Expand All @@ -15,5 +15,9 @@ texture = ExtResource("1_ndkjl")
[node name="Area2D" type="Area2D" parent="."]

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

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

[connection signal="screen_exited" from="VisibleOnScreenNotifier2D" to="." method="_on_visible_on_screen_notifier_2d_screen_exited"]
7 changes: 7 additions & 0 deletions units/projectile.gd
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,12 @@ extends Area2D

const SPEED = 750


func _physics_process(delta):
position += transform.x * SPEED * delta


func _on_area_entered(area):
# TODO: apply effects on enemy hit. For now just despawn.
queue_free()
area.owner.queue_free()
2 changes: 2 additions & 0 deletions units/projectile.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,5 @@ texture = ExtResource("2_lllwu")
[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
position = Vector2(5, 2)
shape = SubResource("CircleShape2D_60ldp")

[connection signal="area_entered" from="." to="." method="_on_area_entered"]

0 comments on commit 7055eab

Please sign in to comment.