the damage system refactor!

killing is now done based on groups, the same way enemies already killed
the player.

these groups go on the entity's hitbox, not the entity itself.
enemies' hitboxes have all been put in "enemy_hitbox"

the arrow_projectile has a variable for the target group, so it could
easily be simply set to "player" for arrows shot by enemies

blocking is also done with groups. any hitbox with "blocks_arrow"
will block arrows, same with "blocks_sword" and "blocks_squash"
This commit is contained in:
Haze Weathers 2023-01-19 18:26:50 -05:00
parent 5a02d02ceb
commit a2974d8dd3
14 changed files with 102 additions and 66 deletions

View file

@ -30,7 +30,6 @@ extents = Vector2( 4, 4 )
[node name="Bat" type="Node2D" groups=["enemy"]]
script = ExtResource( 3 )
can_be_killed_by_sword = false
score_for_killing = 25
speed = 40
move_direction = 1
@ -42,9 +41,9 @@ frames = SubResource( 4 )
frame = 1
playing = true
[node name="Area2D" type="Area2D" parent="."]
[node name="Hitbox" type="Area2D" parent="." groups=["blocks_sword", "enemy_hitbox"]]
[node name="CollisionShape2D" type="CollisionShape2D" parent="Area2D"]
[node name="CollisionShape2D" type="CollisionShape2D" parent="Hitbox"]
shape = SubResource( 5 )
[connection signal="area_entered" from="Area2D" to="." method="_on_Area2D_area_entered"]
[connection signal="area_entered" from="Hitbox" to="." method="_on_Hitbox_area_entered"]

View file

@ -1,38 +1,27 @@
extends Node2D
###
### IMPORTANT: enemy's hitbox must be in the group "enemy_hitbox" to be killed
### it should also be named "Hitbox" for easier (2 click) signal connection
### as the reciever function has been renamed with that in mind
###
const DeathParticles = preload("res://objects/enemy/death_particles.tscn")
export var can_be_killed_by_sword = true
export var can_be_killed_by_arrow = true
export var can_be_squashed = true
### these variables have been replaced with groups to put on the hitbox
### - "blocks_arrow"
### - "blocks_sword"
### if an enemy's hitbox is not in those groups, it will be killed by them
#export var can_be_killed_by_sword = true
#export var can_be_killed_by_arrow = true
#export var can_be_squashed = true
export var score_for_killing = 0
func _on_Area2D_area_entered(area):
func _on_Hitbox_area_entered(area):
#Kill player
if area.is_in_group("player"):
area.get_parent().die()
#Die from sword
if area.is_in_group("sword"):
if can_be_killed_by_sword:
die()
else:
#Block text
Game.instance_node(Game.block_text,global_position.x,global_position.y,get_parent())
#Die from arrow
if area.is_in_group("arrow"):
if can_be_killed_by_arrow:
Game.arrows -= 1
area.get_parent().queue_free()
die()
else:
#Block text
Game.instance_node(Game.block_text,global_position.x,global_position.y,get_parent())
#Die from rock/ get squashed
if area.is_in_group("squash"):
Debug.print("squash")
var squasher = area.get_parent()
if squasher.global_position.y < global_position.y && squasher.velocity.y > 0:
die()
func die():
var death_particles = DeathParticles.instance()

View file

@ -13,7 +13,7 @@ export var flip_sprite = true
#Onreadys
onready var startpos = position
onready var sprite = $AnimatedSprite
onready var raycast = $Area2D/RayCast2D
onready var raycast = $Hitbox/RayCast2D
onready var timer = $Timer
var speed = 50

View file

@ -47,10 +47,10 @@ playing = true
position = Vector2( 4, 4 )
shape = SubResource( 8 )
[node name="Hitbox" type="Area2D" parent="."]
[node name="Hitbox" type="Area2D" parent="." groups=["enemy_hitbox"]]
position = Vector2( 4, 4 )
[node name="CollisionShape2D" type="CollisionShape2D" parent="Hitbox"]
shape = SubResource( 4 )
[connection signal="area_entered" from="Hitbox" to="." method="_on_Area2D_area_entered"]
[connection signal="area_entered" from="Hitbox" to="." method="_on_Hitbox_area_entered"]

View file

@ -40,11 +40,11 @@ position = Vector2( 1, 3 )
frames = SubResource( 4 )
playing = true
[node name="Area2D" type="Area2D" parent="."]
[node name="Hitbox" type="Area2D" parent="." groups=["enemy_hitbox"]]
position = Vector2( -4, 0 )
[node name="CollisionShape2D" type="CollisionShape2D" parent="Area2D"]
[node name="CollisionShape2D" type="CollisionShape2D" parent="Hitbox"]
position = Vector2( 4.5, 3.5 )
shape = SubResource( 5 )
[connection signal="area_entered" from="Area2D" to="." method="_on_Area2D_area_entered"]
[connection signal="area_entered" from="Hitbox" to="." method="_on_Hitbox_area_entered"]

View file

@ -41,13 +41,13 @@ frames = SubResource( 4 )
frame = 1
playing = true
[node name="Area2D" type="Area2D" parent="."]
[node name="Hitbox" type="Area2D" parent="." groups=["enemy_hitbox"]]
[node name="CollisionShape2D" type="CollisionShape2D" parent="Area2D"]
[node name="CollisionShape2D" type="CollisionShape2D" parent="Hitbox"]
position = Vector2( 4, 4 )
shape = SubResource( 5 )
[node name="RayCast2D" type="RayCast2D" parent="Area2D"]
[node name="RayCast2D" type="RayCast2D" parent="Hitbox"]
position = Vector2( 0, 4 )
enabled = true
cast_to = Vector2( 32, 0 )
@ -58,5 +58,5 @@ collide_with_areas = true
wait_time = 0.5
one_shot = true
[connection signal="area_entered" from="Area2D" to="." method="_on_Area2D_area_entered"]
[connection signal="area_entered" from="Hitbox" to="." method="_on_Hitbox_area_entered"]
[connection signal="timeout" from="Timer" to="." method="_on_Timer_timeout"]

View file

@ -35,13 +35,12 @@ score_for_killing = 15
[node name="AnimatedSprite" type="AnimatedSprite" parent="."]
material = SubResource( 1 )
frames = SubResource( 4 )
frame = 1
playing = true
[node name="Area2D" type="Area2D" parent="."]
[node name="Hitbox" type="Area2D" parent="." groups=["enemy_hitbox"]]
[node name="CollisionShape2D" type="CollisionShape2D" parent="Area2D"]
[node name="CollisionShape2D" type="CollisionShape2D" parent="Hitbox"]
position = Vector2( 0, 4 )
shape = SubResource( 5 )
[connection signal="area_entered" from="Area2D" to="." method="_on_Area2D_area_entered"]
[connection signal="area_entered" from="Hitbox" to="." method="_on_Hitbox_area_entered"]

View file

@ -28,12 +28,13 @@ script = ExtResource( 1 )
[node name="AnimatedSprite" type="AnimatedSprite" parent="."]
position = Vector2( 4, 12 )
frames = SubResource( 3 )
frame = 1
playing = true
[node name="Area2D" type="Area2D" parent="."]
[node name="Hitbox" type="Area2D" parent="." groups=["enemy_hitbox"]]
[node name="CollisionShape2D" type="CollisionShape2D" parent="Area2D"]
[node name="CollisionShape2D" type="CollisionShape2D" parent="Hitbox"]
position = Vector2( 4, 12 )
shape = SubResource( 4 )
[connection signal="area_entered" from="Area2D" to="." method="_on_Area2D_area_entered"]
[connection signal="area_entered" from="Hitbox" to="." method="_on_Hitbox_area_entered"]