-
Notifications
You must be signed in to change notification settings - Fork 1
/
MonsterSpawner.gd
76 lines (61 loc) · 1.82 KB
/
MonsterSpawner.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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
extends Node2D
var active = true
var spawn_time = 10.0
var spawn_random = 0.1
var spawn_timer = 0.0
var total_time = 0.0
export var initial_time = 10.0
export var spawn_delay = 0.0
export var spawn_speedup = 0.25
var min_spawn_time = 4.0
const DOG = preload("res://scenes/MonsterDog.tscn")
const BIGDOG = preload("res://scenes/MonsterBigDog.tscn")
const RACCOON = preload("res://scenes/MonsterRaccoon.tscn")
const BIGRACCOON = preload("res://scenes/MonsterBigRaccoon.tscn")
const BIGBOSS = preload("res://scenes/MonsterBigBoss.tscn")
var rac_spawn_rate = 5
var big_dog_spawn_rate = 9
var big_rac_spawn_rate = 15
var spawn_index = 0
var boss_spawned = false
var boss_spawn_time = 215
# Called when the node enters the scene tree for the first time.
func _ready():
spawn_time = initial_time
if GameState.difficulty == "normal":
rac_spawn_rate += 1
big_dog_spawn_rate += 1
big_rac_spawn_rate += 1
spawn_speedup -= 0.05
min_spawn_time += 1.0
func _spawn(type):
var new_monster = type.instance()
new_monster.position = position
if spawn_time > min_spawn_time:
spawn_time -= spawn_speedup
else:
spawn_time = min_spawn_time
get_parent().add_child(new_monster)
func _spawn_monster():
var new_monster = null
spawn_index += 1
if spawn_index % big_rac_spawn_rate == 0:
_spawn(BIGRACCOON)
if spawn_index % big_dog_spawn_rate == 0:
_spawn(BIGDOG)
if spawn_index % rac_spawn_rate == 0:
_spawn(RACCOON)
_spawn(DOG)
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta):
if active:
if not boss_spawned and get_parent().time_asleep >= boss_spawn_time:
_spawn(BIGBOSS)
boss_spawned = true
if spawn_delay > 0.0:
spawn_delay -= delta
else:
spawn_timer -= delta
if spawn_timer <= 0.0:
spawn_timer += spawn_time + rand_range(0.0, spawn_random)
_spawn_monster()