37 lines
992 B
GDScript
37 lines
992 B
GDScript
extends Node2D
|
|
|
|
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():
|
|
Game.score += score_for_killing
|
|
queue_free()
|