a game about throwing hammers made for the github game off
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
extends Node
class_name Util


func instance_scene_on_main(scene: PackedScene, position: Vector2) -> Node:
  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))


static func sub(a: Array, b: Array) -> Array:
  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


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)]