(like Flash and Unity)
extends GameExperiment
@export var doodad_scene : PackedScene
@onready var _items := $Items
func _ready() -> void:
for i in range(25):
var doodad = doodad_scene.instantiate()
_items.add_child(doodad)
extends ColorRect
func _ready() -> void:
var number = randf()
if number > 0.9:
color = Color.DARK_GREEN
elif number > 0.7:
color = Color.SADDLE_BROWN
else:
color = Color.TRANSPARENT
func get_layout() -> Array[Array]:
var layout_image := layout_texture.get_image()
var rows := []
for y in layout_texture.get_height():
var row := []
for x in layout_texture.get_width():
var type := types.none
var color := layout_image.get_pixel(x, y).to_html(false)
for t in types.values():
if not type_colors.has(t):
continue
if color == type_colors[t]:
type = t
row.append(type)
rows.append(row)
return rows
enum flip_axis {
none, x, y,
}
func flip_layout(layout: Array[Array], flip := flip_axis.none) -> Array[Array]:
var new_rows := []
for row in layout:
var new_row := []
for cell in row:
if flip == flip_axis.x:
new_row.push_front(cell)
else:
new_row.push_back(cell)
if flip == flip_axis.y:
new_rows.push_front(new_row)
else:
new_rows.push_back(new_row)
return new_rows
for row in layout:
for cell in row:
if tiles.has(cell):
_tiles.set_cell(
0, Vector2i(x, y), 0, tiles[cell]
)
if nodes.has(cell):
var new_node = nodes[cell].instantiate()
_nodes.add_child(new_node)
new_node.position = Vector2(x * 64, y * 64)
func get_words(generator : RandomNumberGenerator, number : int = 3) -> PackedStringArray:
var words := get_all_words()
var size := words.size()
var chosen := []
for i in range(3):
chosen.append(words[generator.randi() % size])
return PackedStringArray(chosen)
func get_all_words() -> PackedStringArray:
var file = File.new()
if file.file_exists("res://resources/objects.txt"):
file.open("res://resources/objects.txt", File.READ)
var content = file.get_as_text()
file.close()
return content.split("\n", false)
return PackedStringArray()
func get_hash_from_words(words : PackedStringArray) -> int:
var complete = ""
for word in words:
complete += word.trim_prefix(" ").trim_suffix(" ").to_lower()
return complete.hash()