Fix GunShot deallocation

Now bullets are deallocated once they hit a wall
master
Davide Polonio 2021-01-10 15:24:23 +01:00
parent abe8d86124
commit cbe36a2e8d
3 changed files with 30 additions and 10 deletions

View File

@ -1,16 +1,25 @@
[gd_scene load_steps=6 format=2] [gd_scene load_steps=8 format=2]
[ext_resource path="res://assets/misc/SimpleGunShot.png" type="Texture" id=1] [ext_resource path="res://assets/misc/SimpleGunShot.png" type="Texture" id=1]
[ext_resource path="res://assets/misc/Hitbox.tscn" type="PackedScene" id=2] [ext_resource path="res://assets/misc/Hitbox.tscn" type="PackedScene" id=2]
[ext_resource path="res://src/misc/SimpleGunShot.gd" type="Script" id=3] [ext_resource path="res://src/misc/SimpleGunShot.gd" type="Script" id=3]
[ext_resource path="res://src/misc/SimpleGunShotHitbox.gd" type="Script" id=4] [ext_resource path="res://assets/misc/Hurtbox.tscn" type="PackedScene" id=5]
[sub_resource type="GDScript" id=3]
script/source = "extends Area2D
func _on_Hitbox_area_entered(area):
print(\"hit\")
queue_free() # remove myself
"
[sub_resource type="RectangleShape2D" id=1] [sub_resource type="RectangleShape2D" id=1]
extents = Vector2( 1.00781, 1.99957 ) extents = Vector2( 1.00781, 1.99957 )
[sub_resource type="RectangleShape2D" id=2]
extents = Vector2( 1, 2 )
[node name="SimpleGunShot" type="KinematicBody2D"] [node name="SimpleGunShot" type="KinematicBody2D"]
visible = false
collision_layer = 0
collision_mask = 20 collision_mask = 20
script = ExtResource( 3 ) script = ExtResource( 3 )
@ -18,10 +27,20 @@ script = ExtResource( 3 )
texture = ExtResource( 1 ) texture = ExtResource( 1 )
[node name="GunShotHitbox" parent="." instance=ExtResource( 2 )] [node name="GunShotHitbox" parent="." instance=ExtResource( 2 )]
script = ExtResource( 4 ) visible = false
collision_mask = 20
script = SubResource( 3 )
[node name="CollisionShape2D" parent="GunShotHitbox" index="0"] [node name="CollisionShape2D" parent="GunShotHitbox" index="0"]
shape = SubResource( 1 ) shape = SubResource( 1 )
[connection signal="area_entered" from="GunShotHitbox" to="GunShotHitbox" method="_on_Hitbox_area_entered"]
[node name="GunShotHurtbox" parent="." instance=ExtResource( 5 )]
collision_layer = 0
collision_mask = 4
[node name="CollisionShape2D2" type="CollisionShape2D" parent="GunShotHurtbox"]
shape = SubResource( 2 )
[connection signal="body_entered" from="GunShotHitbox" to="." method="_on_GunShotHitbox_body_entered"]
[connection signal="body_entered" from="GunShotHurtbox" to="." method="_on_Hurtbox_body_entered"]
[editable path="GunShotHitbox"] [editable path="GunShotHitbox"]

View File

@ -9,3 +9,8 @@ func _ready():
func _physics_process(delta): func _physics_process(delta):
move_and_collide(Vector2(0, SPEED * -1)) move_and_collide(Vector2(0, SPEED * -1))
# decrease enemy or player's life
func _on_GunShotHitbox_body_entered(body: Node):
# TODO body's hp
queue_free()

View File

@ -1,4 +0,0 @@
extends Area2D
func _on_Hitbox_area_entered(area):
queue_free()