forked from team-sg/hero-mark-2
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"
34 lines
1 KiB
GDScript
34 lines
1 KiB
GDScript
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")
|
|
|
|
### 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_Hitbox_area_entered(area):
|
|
#Kill player
|
|
if area.is_in_group("player"):
|
|
area.get_parent().die()
|
|
|
|
func die():
|
|
var death_particles = DeathParticles.instance()
|
|
death_particles.global_position = global_position
|
|
death_particles.emitting = true
|
|
get_parent().add_child(death_particles)
|
|
|
|
Game.play_sound(Game.a_die, Game.ac_die)
|
|
Game.score += score_for_killing
|
|
queue_free()
|