31 lines
727 B
GDScript
31 lines
727 B
GDScript
class_name Hitbox extends Area2D
|
|
|
|
var from_player = true
|
|
signal onhit;
|
|
var hitplayer = false
|
|
|
|
#func _process(delta: float) -> void:
|
|
#EventBus.cut_grass_at.emit(global_position, 14)
|
|
|
|
func _ready() -> void:
|
|
body_entered.connect(_on_body_entered)
|
|
|
|
func _on_body_entered(body: Node) -> void:
|
|
print(body)
|
|
if body is Enemy and from_player:
|
|
var bname := str(body.name)
|
|
body.damage()
|
|
onhit.emit()
|
|
body.knockback()
|
|
EventBus.debug_print.emit("Hit: " + bname)
|
|
|
|
if body is Player and not from_player and not hitplayer:
|
|
var bname := str(body.name)
|
|
hitplayer = true
|
|
body.damage()
|
|
onhit.emit()
|
|
EventBus.debug_print.emit("Hit: " + bname)
|
|
|
|
EventBus.debug_print.emit(str(body))
|
|
if body is StaticBody2D:
|
|
onhit.emit()
|