summaryrefslogtreecommitdiff
path: root/Enemies/flying_enemy.gd
blob: 701affc2f9a362fbf2f9e0dcc246a6fada681cd1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
extends Enemy


@export var angular_speed = 3.0
var alpha = 0

enum MovementType {
	UP_DOWN,
	FORWARD,
}
@export var movement_type: MovementType = MovementType.UP_DOWN


func _physics_process(delta: float) -> void:
	$AnimatedSprite2D.play()
	
	if movement_type == MovementType.UP_DOWN:
		velocity.y = sin(alpha) * 32
	elif movement_type == MovementType.FORWARD:
		velocity.x = direction * speed
		velocity.y = sin(alpha) * 16
	
	alpha += delta * angular_speed
	
	move_and_slide()
	if get_last_slide_collision():
		if $RayLeft.is_colliding():
			direction = 1
		elif $RayRight.is_colliding():
			direction = -1