-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathglobals.gd
More file actions
71 lines (53 loc) · 1.52 KB
/
globals.gd
File metadata and controls
71 lines (53 loc) · 1.52 KB
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
extends Node
var num_word = 0
var words = [[],[]]
var config
# Called when the node enters the scene tree for the first time.
func _ready() -> void:
load_config()
load_words(2)
load_words(3)
load_words(4)
load_words(5)
load_words(6)
load_words(7)
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(_delta: float) -> void:
pass
func load_words(num):
var file = "res://data/" + str(num) + ".txt"
var f = FileAccess.open(file, FileAccess.READ)
var data = f.get_as_text(true).split("\n")
var filtered_array = []
for string in data:
if string != "":
filtered_array.append(string.to_lower())
filtered_array.shuffle()
words.append(filtered_array)
func _next_word(level):
num_word = (num_word + 1) % len(words[level])
return words[level][num_word]
func next_word(level, letters):
var word = _next_word(level)
while letters.has(word[0]):
word = _next_word(level)
return word
func clear_config():
ConfigFile.new().save("user://teclanautas.cfg")
func save_config():
config.save("user://teclanautas.cfg")
func load_config():
# Load data from a file.
config = ConfigFile.new()
var err = config.load("user://teclanautas.cfg")
# If the file didn't load, ignore it.
if err != OK:
config = ConfigFile.new()
func move(item, target, speed, delta):
var distance = item.position.distance_to(target)
if (distance < 10):
item.position.x = target.x
item.position.y = target.y
else:
var direction = item.position.direction_to(target);
item.position += direction * speed * delta