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:
parent
5a02d02ceb
commit
a2974d8dd3
14 changed files with 102 additions and 66 deletions
|
@ -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()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue