Player gun, bullet and its collisiions. Refactor.

This commit is contained in:
Felipe M 2021-01-30 20:57:48 +01:00
parent 0dd3f24030
commit ffb7c8bf99
Signed by: fmartingr
GPG key ID: 716BC147715E716F
28 changed files with 562 additions and 131 deletions

View file

@ -0,0 +1,16 @@
[gd_scene load_steps=3 format=2]
[ext_resource path="res://Assets/World/Brick.png" type="Texture" id=1]
[sub_resource type="RectangleShape2D" id=1]
extents = Vector2( 8, 8 )
[node name="Brick" type="StaticBody2D"]
[node name="Sprite" type="Sprite" parent="."]
texture = ExtResource( 1 )
centered = false
[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
position = Vector2( 8, 8 )
shape = SubResource( 1 )

View file

@ -0,0 +1,9 @@
extends Area2D
# Deal damage
export (int) var damage = 1
func _on_Hitbox_area_entered(hurtbox):
hurtbox.emit_signal("hit", damage)

View file

@ -0,0 +1,11 @@
[gd_scene load_steps=2 format=2]
[ext_resource path="res://Scenes/Objects/Hitbox.gd" type="Script" id=1]
[node name="Hitbox" type="Area2D"]
collision_layer = 0
collision_mask = 0
script = ExtResource( 1 )
[node name="Collider" type="CollisionShape2D" parent="."]
[connection signal="area_entered" from="." to="." method="_on_Hitbox_area_entered"]

View file

@ -0,0 +1,5 @@
extends Area2D
# Receives damage
signal hit(damage)

View file

@ -0,0 +1,10 @@
[gd_scene load_steps=2 format=2]
[ext_resource path="res://Scenes/Objects/Hurtbox.gd" type="Script" id=1]
[node name="Hurtbox" type="Area2D"]
collision_layer = 0
collision_mask = 0
script = ExtResource( 1 )
[node name="Collider" type="CollisionShape2D" parent="."]

View file

@ -0,0 +1,20 @@
extends Node2D
var velocity = Vector2.ZERO
func _process(delta):
position += velocity * delta
func _on_VisibilityNotifier2D_viewport_exited(_viewport):
queue_free()
func _on_Hitbox_body_entered(_body):
# When we collide with the world
queue_free()
func _on_Hitbox_area_entered(_area):
# When we collide with an enemy (a hurtbox)
queue_free()

View file

@ -0,0 +1,20 @@
[gd_scene load_steps=3 format=2]
[ext_resource path="res://Scenes/Objects/Proyectile.gd" type="Script" id=1]
[ext_resource path="res://Scenes/Objects/Hitbox.tscn" type="PackedScene" id=2]
[node name="Proyectile" type="Node2D"]
script = ExtResource( 1 )
[node name="Sprite" type="Sprite" parent="."]
[node name="VisibilityNotifier2D" type="VisibilityNotifier2D" parent="."]
rect = Rect2( -4, -4, 8, 8 )
[node name="AnimationPlayer" type="AnimationPlayer" parent="."]
[node name="Hitbox" parent="." instance=ExtResource( 2 )]
collision_mask = 2
[connection signal="viewport_exited" from="VisibilityNotifier2D" to="." method="_on_VisibilityNotifier2D_viewport_exited"]
[connection signal="area_entered" from="Hitbox" to="." method="_on_Hitbox_area_entered"]
[connection signal="body_entered" from="Hitbox" to="." method="_on_Hitbox_body_entered"]