This repository has been archived by the owner on Sep 13, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwordy.gd
201 lines (167 loc) · 6.64 KB
/
wordy.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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
extends Node2D
## When EXPORTING under resources include non resource/folders the_words.txt or game will crash
## as it can't locate the array do to not having the text file
@onready var line_edit = $LineEdit
var selected = false
var dragging_start_position = Vector2()
var guess_container = VBoxContainer.new() # Create a VBoxContainer to hold all guesses
var correct_word = "" # Selected correct word
var correct_words = [] # Array of correct words
var attempts = 0 # Number of attempts
@onready var attempts_taken = $RichTextLabel
var current_date = "" # Store the current date
var game_sounds = {}
@onready var fireworks = $fireworks
@onready var fireworks_mirror = $fireworks/mirrored
@onready var leaderboard = $LeaderBoard
@onready var LoFi_BGM = $AudioStreamPlayerBGM
@onready var PNTextEdit = $SquareWhite/PNTextEdit
var PNText = "res://Patch Notes/patch_notes.txt"
func _ready():
get_viewport().transparent_bg = true
# Load the array from a file
load_words_from_file("res://the_words.txt", correct_words)
# Select a random word from the array at the start of the game
if correct_words.size() > 0:
correct_word = correct_words[randi() % correct_words.size()]
guess_container.global_position.x = 125
guess_container.global_position.y = 20
# Load the stored date from the file
check_date()
game_sound_effects()
func game_sound_effects():
# Load and assign sounds by name
game_sounds["clapping"] = load("res://Sounds/clapping.mp3")
func _process(_delta):
if selected: # Dragging logic
var mouse_position = get_global_mouse_position()
var window_position = Vector2(DisplayServer.window_get_position())
DisplayServer.window_set_position(window_position + (mouse_position - dragging_start_position))
func _on_area_2d_input_event(_viewport, _event, _shape_idx):
if Input.is_action_just_pressed("left_click"):
selected = true
dragging_start_position = get_global_mouse_position()
func _input(event):
if event is InputEventMouseButton:
if event.button_index == MOUSE_BUTTON_LEFT and not event.pressed:
selected = false
func _on_area_2_dclose_input_event(_viewport, _event, _shape_idx):
if Input.is_action_just_pressed("left_click"):
get_tree().quit()
# Get the date as 00/00/0000
func get_date():
# Returning time/date stamp
var time = Time.get_datetime_dict_from_system()
current_date = "%d/%02d/%02d" % \
[time.month, time.day, time.year]
return current_date
# Caheck the date and lock play
func check_date():
var current_date_str = get_date()
var file = FileAccess.open("user://stored_date.txt", FileAccess.READ)
if file != null:
if file.get_error() == OK:
var saved_date_str = file.get_line()
file.close()
if current_date_str == saved_date_str:
line_edit.text = " Come back tomorrow!"
line_edit.editable = false # Disable editing
line_edit.focus_mode = false # Disable focus
line_edit.set_meta("mouse_filter", Control.MOUSE_FILTER_STOP) # Stop mouse interaction
return
else:
file.close()
else:
file = FileAccess.open("user://stored_date.txt", FileAccess.WRITE)
file.store_line(get_date())
file.close()
# load word array from text file
func load_words_from_file(filename, array):
var file = FileAccess.open(filename, FileAccess.READ)
if file != null:
while not file.eof_reached():
var line = file.get_line()
array.append(line.to_upper())
file.close()
else:
print("Error loading file")
# Text submisson and attempt setting
func _on_line_edit_text_submitted(text):
# Check if the current date has changed
var new_date = get_date()
if new_date != current_date:
attempts = 0 # Reset attempts
current_date = new_date # Update the current date
attempts += 1
line_edit.text = ""
line_edit.caret_column = line_edit.text.length()
line_edit.caret_blink = true
if attempts <= 6:
if text.length() > correct_word.length():
line_edit.text = "Words are five letters!"
attempts -= 1
line_edit.caret_column = line_edit.text.length()
line_edit.caret_blink = true
return
var input_array = text.to_upper().split("") # Convert input to uppercase
var button_container = HBoxContainer.new()
for i in range(input_array.size()):
var letter = input_array[i]
var button = create_button(letter, i)
button_container.add_child(button)
if letter == correct_word.to_upper()[i]: # Compare with uppercase correct word
button.modulate = Color.GREEN
elif correct_word.to_upper().find(letter) != -1:
button.modulate = Color.YELLOW
else:
button.modulate = Color.RED
guess_container.add_child(button_container)
if text.to_upper() == correct_word.to_upper(): # Check if the entire word is correct (uppercase)
line_edit.queue_free()
attempts_taken.visible = true # Temp richtextlabel to have a guess amounts win screen
attempts_taken.text = "It took you " + str(attempts) + " attempts!"
$AudioStreamPlayer.stream = game_sounds["clapping"]
$AudioStreamPlayer.play()
fireworks.visible = true
fireworks.play("stars")
fireworks_mirror.play("stars_mirror")
leaderboard.update_score(attempts)
# Save the current date here
var file = FileAccess.open("user://stored_date.txt", FileAccess.WRITE)
file.store_line(get_date())
file.close()
else:
if attempts == 6:
line_edit.text = "Correct answer: " + correct_word.to_upper()
leaderboard.update_score(attempts)
line_edit.editable = false # Disable editing
line_edit.focus_mode = false # Disable focus
line_edit.set_meta("mouse_filter", Control.MOUSE_FILTER_STOP) # Stop mouse interaction
# Save the current date here
var file = FileAccess.open("user://stored_date.txt", FileAccess.WRITE)
file.store_line(get_date())
file.close()
get_node("/root/Wordy").add_child(guess_container)
# button creation
func create_button(letter, i):
var sprite = Sprite2D.new()
var texture
if letter == correct_word.to_upper()[i]: # Correct letter
texture = load("res://Letters/" + letter + "_green.png")
elif correct_word.to_upper().find(letter) != -1: # Present in word, wrong spot
texture = load("res://Letters/" + letter + "_yellow.png")
else: # Wrong letter
texture = load("res://Letters/" + letter + "_red.png")
sprite.texture = texture
sprite.scale = Vector2(1, 1) # Adjust the scale as needed
# Calculate the position of the sprite
var x = (i * (sprite.texture.get_size().x + 3)) # Add 3 pixels of spacing
var y = (3 + (attempts * 30)) # Increase y position by 30 pixels for each attempt
sprite.position = Vector2(x, y) # Set the position of the sprite
return sprite
func _on_pn_button_pressed():
PNTextEdit.visible = !PNTextEdit.visible
var file = FileAccess.open(PNText, FileAccess.READ)
var patchnotes = file.get_as_text()
PNTextEdit.text = patchnotes
print("PN CLICK")