a game about throwing hammers made for the github game off
Diffstat (limited to 'autoloads/Utils.gd')
| -rw-r--r-- | autoloads/Utils.gd | 30 |
1 files changed, 21 insertions, 9 deletions
diff --git a/autoloads/Utils.gd b/autoloads/Utils.gd index a005032..0a07436 100644 --- a/autoloads/Utils.gd +++ b/autoloads/Utils.gd @@ -3,20 +3,32 @@ class_name Util func instance_scene_on_main(scene: PackedScene, position: Vector2) -> Node: - var main = get_tree().current_scene - var instance = scene.instantiate() - main.add_child(instance) - instance.global_position = position - return instance + var main := get_tree().current_scene + var instance := scene.instantiate() as Node2D + main.add_child(instance) + instance.global_position = position + return instance static func str_vec(vec: Vector2) -> String: - var map := {Vector2.UP: "up", Vector2.DOWN: "down", Vector2.LEFT: "left", Vector2.RIGHT: "right"} - return map.get(vec, str(vec)) + var map := {Vector2.UP: "up", Vector2.DOWN: "down", Vector2.LEFT: "left", Vector2.RIGHT: "right"} + return map.get(vec, str(vec)) static func sub(a: Array, b: Array) -> Array: - return a.filter(func(item) -> bool: return not item in b) + return a.filter(func(item) -> bool: return not item in b) + static func out_of_bounds(v: Vector2i, rect: Vector2i) -> bool: - return v.x > rect.x or v.y > rect.y or v.x < 0 or v.y < 0
\ No newline at end of file + return v.x > rect.x or v.y > rect.y or v.x < 0 or v.y < 0 + + +const hammer_path_fmt := "res://hammers/hammer_%s.tscn" +const hammers: Array[PackedScene] = [ + preload(hammer_path_fmt % "01"), + preload(hammer_path_fmt % "02"), + preload(hammer_path_fmt % "03"), +] + +func get_hammer() -> PackedScene: + return hammers[randi() % len(hammers)] |