-
Notifications
You must be signed in to change notification settings - Fork 0
/
suvivers_game.gd
132 lines (115 loc) · 3.53 KB
/
suvivers_game.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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
extends Node2D
### clock test
#var sec2 : int
@onready var scoreLable := %Score
@onready var time = %Time
var sec : int = SceneSwitcher.time_sec
@onready var player = %player
@onready var level_id_text = get_node("/root/Game/level_text/%level_id_text")
var level : int
func _ready():
sec = SceneSwitcher.time_sec
var id = get_node("level_id").level_id
level = id
SceneSwitcher.level = id
level_id_text.text = str(id)
%GameOver.visible = false
SceneSwitcher.game_over = false
func _on_player_health_depleted():
%GameOver.visible = true
%player.health = 0
SceneSwitcher.game_over = true
if Input.is_action_just_pressed("enter"):
# restart the game
sec = 0
SceneSwitcher.time_sec = 0
restart_children()
SceneSwitcher.score = 0
SceneSwitcher.game_over = false
SceneSwitcher.shoot_speed = 1.0
%player.score = 0
%player.health = 100
%player/ProgressBar.value = 100
%GameOver.visible = false
func restart_children():
var children = get_children()
for child in children:
if child.has_method("restart"):
child.restart()
func spawn_mob():
var new_mob = preload("res://mob.tscn").instantiate()
%PathFollow2D.progress_ratio = randf()
new_mob.global_position = %PathFollow2D.global_position
add_child(new_mob)
func spawn_item():
var new_item = preload("res://item.tscn").instantiate()
%PathFollowItem.progress_ratio = randf()
new_item.global_position = %PathFollowItem.global_position
add_child(new_item)
func spawn_item_gun():
var new_item = preload("res://item_gun.tscn").instantiate()
%PathFollowItem.progress_ratio = randf()
new_item.global_position = %PathFollowItem.global_position
add_child(new_item)
func spawn_tree():
var new_tree = preload("res://pine_tree.tscn").instantiate()
%PathFollow2D.progress_ratio = randf()
new_tree.global_position = %PathFollow2D.global_position
add_child(new_tree)
func _on_timer_timeout():
scoreLable.text = str(SceneSwitcher.score)
spawn_mob()
spawn_tree()
var level_text = %level_text
level_text.visible = false
func _on_timer_item_timeout():
spawn_item()
spawn_item_gun()
func _on_clock_timer_timeout():
sec += 1
SceneSwitcher.time_sec += 1
time.text = digital_clock()
#func _process(_delta):
#sec2 += 1
#print(digital_clock_test(sec2))
#
#func digital_clock_test(sec2):
#if sec2 <= 9: # Antalet sekunder från start
#return str("00:0", + sec2)
#if sec2 <= 59:
#return str("00:", + sec2)
#if sec2 >= 60:
#var minut = sec2 / 60
#var secund = sec2 % 60
#if secund <= 9 and minut <= 9: # 09:09
#return str("0",+ minut, ":", "0", + secund)
#if minut <= 9: # 09:10
#return str("0",+ minut, ":", + secund)
#if minut >= 10 and secund <= 9: # 10:09
#return str(minut, ":", "0", + secund)
#if minut > 59: # 1:00:00 ->
#return str("Time limit... 01:00:00 ! Total: ", + sec2, " sec")
#else: # 10:10 -> 59:59 sec
#return str(minut, ":", + secund)
#else:
#return str("Time limit...", + sec2, " sec")
func digital_clock():
if sec <= 9: # Antalet sekunder från start
return str("00:0", + sec)
if sec <= 59:
return str("00:", + sec)
if sec >= 60:
var minut = sec / 60
var secund = sec % 60
if secund <= 9 and minut <= 9: # 09:09
return str("0",+ minut, ":", "0", + secund)
if minut <= 9: # 09:10
return str("0",+ minut, ":", + secund)
if minut >= 10 and secund <= 9: # 10:09
return str(minut, ":", "0", + secund)
if minut >= 60: # 1:00:00 ->
return str("Time limit... 01:00:00 ! Total: ", + sec, " sec")
else: # 10:10 -> 59:59 sec
return str(minut, ":", + secund)
else:
return str("Time limit...", + sec, " sec")