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

@ -1,16 +1,24 @@
extends Node2D
onready var cull_edge = Vector2(5 * scale.x,0) #Edge to check culling, if this edge is offscreen, delete the arrow
export var speed = 240.0
# group to kill
var target_group = "enemy_hitbox"
# direction to fly
var direction = 1.0
#Edge to check culling, if this edge is offscreen, delete the arrow
onready var cull_edge = Vector2(5 * direction,0)
onready var player = get_parent().get_node("Player")
onready var initial_sector = Game.get_sector(player.global_position)
func _ready():
#Flip depending on player facing
scale.x = player.sprite.scale.x
#Flip depending on direction
scale.x = direction
func _physics_process(delta):
#Move in flip direction
position.x += 4 * scale.x
#Move in right direction
position.x += speed * direction * delta
#Delete when offscreen
if Game.get_sector(global_position + cull_edge) != initial_sector:
queue_free()
@ -22,10 +30,24 @@ func _exit_tree():
particles.global_position = global_position
particles.emitting = false
get_parent().add_child(particles)
particles.get_node("DeathTimer").start()
get_tree().create_timer(particles.lifetime, false).connect("timeout", particles, "queue_free")
#Wall Collision
func _on_Area2D_body_entered(body):
func _on_Hitbox_body_entered(body):
if body is TileMap or body is StaticBody2D:
queue_free()
# kill entity if in target group
func _on_Hitbox_area_entered(area):
# block if collided area is in "blocks_arrow" group
if area.is_in_group(target_group):
var target = area.get_parent()
# create block text and return if blocked
if area.is_in_group("blocks_arrow"):
var pos = target.global_position
Game.instance_node(Game.block_text, pos.x, pos.y, target.get_parent())
else:
# kill targeted node
target.die()
Game.arrows = max(0, Game.arrows - 1) # clamp arrows above 0
queue_free()