forked from team-sg/hero-mark-2
42 lines
1.2 KiB
GDScript
42 lines
1.2 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")
|
|
|
|
signal died()
|
|
|
|
### 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
|
|
export var blood = true
|
|
|
|
var death_sound = Audio.a_die
|
|
var death_blood_offset = Vector2.ZERO
|
|
|
|
func _on_Hitbox_area_entered(area):
|
|
#Kill player
|
|
if area.is_in_group("player"):
|
|
area.get_parent().die()
|
|
|
|
func die():
|
|
if blood:
|
|
var death_particles = DeathParticles.instance()
|
|
death_particles.global_position = global_position + death_blood_offset
|
|
death_particles.emitting = true
|
|
get_parent().add_child(death_particles)
|
|
|
|
Audio.play_sound(death_sound, Audio.ac_die)
|
|
Game.score += score_for_killing
|
|
emit_signal("died")
|
|
queue_free()
|