Hammer.gd 650 B

12345678910111213141516171819202122232425
  1. class_name Hammer
  2. extends Node2D
  3. var velocity := Vector2(0, -200)
  4. var direction := -1
  5. func _ready() -> void:
  6. $Sprite.flip_h = direction == 1
  7. $Animations.speed_scale = -direction
  8. velocity.x = 120 * direction
  9. if Settings.file.audio.extra_sfx == 1:
  10. AudioManager.play_sfx("hammer_throw", global_position)
  11. func _physics_process(delta: float) -> void:
  12. global_position += velocity * delta
  13. velocity.y += (Global.entity_gravity / delta) * delta
  14. velocity.y = clamp(velocity.y, -INF, Global.entity_max_fall_speed)
  15. func flag_die() -> void:
  16. queue_free()
  17. func on_area_entered(area: Area2D) -> void:
  18. if area.owner is Player:
  19. area.owner.damage()