-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEnemies.gd
36 lines (29 loc) · 1.07 KB
/
Enemies.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
extends Node2D
const WeakEnemy = preload("res://WeakEnemy.tscn")
const MediumEnemy = preload("res://MediumEnemy.tscn")
const HardEnemy = preload("res://HardEnemy.tscn")
const CellEnemy = preload("res://CellEnemy.tscn")
# Called when the node enters the scene tree for the first time.
func _ready():
$WeakEnemyTimer.start()
$MediumEnemyTimer.start()
$HardEnemyTimer.start()
$CellEnemyTimer.start()
func spawnEnemy(Mob: PackedScene):
$MobPath/MobSpawnLocation.offset = randi()
var mob = Mob.instance()
add_child(mob)
var direction = $MobPath/MobSpawnLocation.rotation + PI / 2
mob.position = $MobPath/MobSpawnLocation.position
direction += rand_range(-PI / 8, PI / 8)
mob.rotation = direction
mob.linear_velocity = Vector2(rand_range(mob.min_speed, mob.max_speed), 0)
mob.linear_velocity = mob.linear_velocity.rotated(direction)
func _on_WeakEnemyTimer_timeout():
spawnEnemy(WeakEnemy)
func _on_MediumEnemyTimer_timeout():
spawnEnemy(MediumEnemy)
func _on_HardEnemyTimer_timeout():
spawnEnemy(HardEnemy)
func _on_CellEnemyTimer_timeout():
spawnEnemy(CellEnemy)