123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051 |
- class_name Chicken
- extends KinematicBody2D
- export var walk_linear_speed = 100
- export var run_boost = 4
- var velocity = Vector2.ZERO
- func attack(from: Vector2, angle: float):
- position = from
- velocity = Vector2(walk_linear_speed, 0).rotated(angle)
- $AnimatedSprite.play("walk")
- _update_sprite_direction()
- func _physics_process(delta):
- var collision = move_and_collide(velocity * delta)
- _collide_and_react(collision)
- func _on_VisibilityNotifier2D_screen_exited():
- _die()
- func _on_Spawner_reset():
- _die()
- func _die():
- queue_free()
- func _collide_and_react(collision: KinematicCollision2D) -> void:
- if collision == null:
- return
- var collider = collision.get_collider()
- if collider is KinematicBody2D and (collider as Node).is_in_group("chicken") :
- _turn_away()
- func _turn_away() -> void:
- velocity.x = -velocity.x
- _update_sprite_direction()
- func _update_sprite_direction() -> void:
- $AnimatedSprite.flip_h = velocity.x < 0.0
|