hero-mark-2/objects/enemy/enemy.gd

45 lines
1.3 KiB
GDScript

extends Node2D
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
export var score_for_killing = 0
func _on_Area2D_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()
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()