forked from Zanzigzan/ChaosHacks-2024
-
Notifications
You must be signed in to change notification settings - Fork 0
/
enemy.gd
39 lines (32 loc) · 820 Bytes
/
enemy.gd
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
31
32
33
34
35
36
37
38
39
class_name Enemy extends Area2D
#
@export var speed = 500
var is_wiggling = false
var wiggle_amount = .5 # Adjust for more or less wiggle
var wiggle_speed = 10 # Lower is faster, higher is slower
var wiggle_timer = 0
var crash = false
var random = randi()%3
var carType = 32 * random
func _ready():
$RandomSprite.region_rect = Rect2(carType, 0, 27, 52.3)
func _process(delta):
global_position.y += speed * delta
if is_wiggling:
wiggle_timer += 1
if wiggle_timer % wiggle_speed == 0:
rotation += wiggle_amount
wiggle_amount *= -1 # Change direction
if crash:
rotation += 0.1
func _on_body_entered(body):
if body is Player:
body.die()
die()
func set_wiggling(wiggling):
is_wiggling = wiggling
func die():
crash = true
$Crash.play()
await get_tree().create_timer(1).timeout
queue_free()