aboutsummaryrefslogtreecommitdiff
path: root/client/gui/menus/main/background.gd
blob: 85ac258fa64754316cdf82b456e8bb650332786d (plain)
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
# Hurry Curry! - a game about cooking
# Copyright (C) 2025 Hurry Curry! contributors
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, version 3 of the License only.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program.  If not, see <https://www.gnu.org/licenses/>.
#
extends Node3D

const CRATES = ["tomato-crate", "bun-crate", "steak-crate", "cheese-crate", "lettuce-crate", "flour-crate", "coconut-crate"]
const TOOLS = ["stove", "stove", "stove", "sink", "cutting-board", "sink", "cutting-board", "rolling-board", "oven", "freezer", "deep-fryer", "rolling-board"]
const ITEMS = ["pot", "pan", "foodprocessor", "plate", "basket", "lettuce", "dirty-plate", "cheese", "nigiri"]

@onready var environment: WorldEnvironment = $Environment
@onready var map: Map = $Map

func _ready():
	if !Global.on_vulkan():
		environment.environment.tonemap_exposure = 0.25

	var tiles = {}
	var item_counters := []
	for x in range(-10, 11):
		for y in range(-10, 11):
			var w = exp(-sqrt(x * x + y * y) * 0.15)
			var k = randf() * w
			var tn = null
			if k > 0.25: tn = "floor"
			if k > 0.4: tn = choose(CRATES) if randf() > 0.3 else "counter"
			if k > 0.6: tn = choose(TOOLS)
			if k > 0.7: tn = "tree" if randf() > 0.4 else "grass"
			if tn != null:
				tiles[str(Vector2i(x,y))] = [tn,[x,y]]
				if tn == "counter" and randf() > 0.1 and k > 0.45:
					item_counters.push_back(Vector2i(x, y))
	var gt = func (cs):
		var t = tiles.get(str(Vector2i(cs[0],cs[1])))
		return null if t == null else t[0]
	for pk in tiles.keys():
		var x = tiles[pk][1][0]
		var y = tiles[pk][1][1]
		var t = gt.call([x,y])
		if t != null: map.set_tile(Vector2i(x,y), t, [[x,y-1],[x-1,y],[x,y+1],[x+1,y]].map(gt))

	map.flush()

	for v: Vector2i in item_counters:
		var t: Tile = map.get_tile_instance(v)
		var item := ItemFactory.produce(choose(ITEMS), t)
		add_child(item)
		item.position = t.item_base.global_position
		var rot := randf() * 2 * PI
		item.rotation.y = rot
		item.rotation_target = rot
		t.set_item(item)
func choose(a): return a[floor(a.size() * randf())]