+8
-7
scripts/world/item_entity.gd
+8
-7
scripts/world/item_entity.gd
···
14
14
var item: Item
15
15
16
16
@onready var world: World = get_parent()
17
+
@onready var progress_bar: ProgressBar = $ProgressBar
17
18
18
19
func _ready():
19
20
texture = item.texture
···
32
33
position.y = move_toward(position.y, target_position.y, SPEED * delta * TILE_SIZE)
33
34
world.set_item(position, self)
34
35
return
35
-
36
+
36
37
update_process(delta)
37
38
38
39
var direction = world.custom_data(position, "direction")
···
49
50
func update_process(delta):
50
51
if not process_can_apply():
51
52
return
52
-
53
+
53
54
if current_process != null:
54
55
current_process.progress += delta
55
-
$ProgressBar.value = current_process.progress
56
+
progress_bar.value = current_process.progress
56
57
if current_process.progress >= current_process.process.time:
57
58
set_item(current_process.process.result)
58
59
current_process = null
59
-
$ProgressBar.visible = false
60
+
progress_bar.visible = false
60
61
return
61
-
62
+
62
63
for process in item.processes:
63
64
if world.custom_data(position, "process") == process.process:
64
65
var progress = ProcessProgress.new()
65
66
progress.process = process
66
-
$ProgressBar.visible = true
67
-
$ProgressBar.max_value = process.time
67
+
progress_bar.visible = true
68
+
progress_bar.max_value = process.time
68
69
current_process = progress
69
70
70
71
func process_can_apply():
+8
-11
scripts/world/player.gd
+8
-11
scripts/world/player.gd
···
2
2
3
3
const SPEED = 300.0
4
4
const ROTATION_SPEED = 20.0
5
+
var item: Item = null
6
+
5
7
@onready var world: World = get_parent()
8
+
@onready var marker = $Marker2D
6
9
7
10
func _physics_process(delta):
8
-
# Get the input direction and handle the movement/deceleration.
9
-
# As good practice, you should replace UI actions with custom gameplay actions.
10
11
var direction = Input.get_vector("move_left", "move_right", "move_up", "move_down")
11
12
if direction:
12
13
velocity.x = direction.x * SPEED
···
17
18
target_rotation = target_rotation + 2*PI
18
19
19
20
rotation = move_toward(rotation, target_rotation, delta * ROTATION_SPEED)
20
-
21
21
else:
22
22
velocity.x = move_toward(velocity.x, 0, SPEED)
23
23
velocity.y = move_toward(velocity.y, 0, SPEED)
···
30
30
31
31
move_and_slide()
32
32
33
-
34
-
var item: Item = null
35
-
36
33
func pickup():
37
-
var entity = world.get_item($Marker2D.global_position)
34
+
var entity = world.get_item(marker.global_position)
38
35
if entity != null:
39
36
self.item = entity.item
40
37
$Item.texture = entity.item.texture
41
-
world.remove_item($Marker2D.global_position)
38
+
world.remove_item(marker.global_position)
42
39
entity.queue_free()
43
40
44
41
var item_entity = preload("res://scenes/entities/item_entity.tscn")
45
42
46
43
func drop():
47
-
if world.get_item($Marker2D.global_position) != null:
44
+
if world.get_item(marker.global_position) != null:
48
45
return
49
-
if world.custom_data($Marker2D.global_position, "can_hold_item"):
46
+
if world.custom_data(marker.global_position, "can_hold_item"):
50
47
var item = item_entity.instantiate()
51
48
item.item = self.item
52
-
item.position = $Marker2D.global_position
49
+
item.position = marker.global_position
53
50
world.add_child(item)
54
51
world.set_item(item.position, item)
55
52
self.item = null
+27
-23
scripts/world/world.gd
+27
-23
scripts/world/world.gd
···
1
1
extends Node2D
2
2
class_name World
3
3
4
-
const width = 18
5
-
const height = 10
4
+
const WIDTH = 18
5
+
const HEIGHT = 10
6
6
const TILE_SIZE = 64
7
7
8
8
@onready var tilemap: TileMapLayer = $Appliances
···
14
14
var time_remaining: float
15
15
16
16
var item_queue: Array[Item] = []
17
-
var dishes: Array[ActiveDish] = []
17
+
var active_dishes: Array[ActiveDish] = []
18
18
@export var possible_dishes: Array[Dish]
19
19
20
20
const DISH_TIMEOUT = 30
···
26
26
@onready var coins_label: Label = ui_vertical.get_node("HBoxContainer/Coins")
27
27
28
28
func _ready():
29
-
for i in range(width * height):
29
+
for i in range(WIDTH * HEIGHT):
30
30
items.append(null)
31
31
32
32
var item_entity = preload("res://scenes/entities/item_entity.tscn")
···
42
42
set_item(item.position, item)
43
43
item_queue.pop_front()
44
44
45
-
var new_dishes = dishes.filter(func(dish): return process_dish(dish, delta))
46
-
dishes = new_dishes
45
+
active_dishes = active_dishes.filter(func(dish): return process_dish(dish, delta))
47
46
48
47
time_until_next_dish -= delta
49
48
if time_until_next_dish <= 0:
50
-
var dish: ActiveDish = ActiveDish.new()
51
-
dish.dish = possible_dishes.pick_random()
52
-
var indicator = dish_indicator.instantiate()
53
-
indicator.get_node("TextureRect").texture = dish.dish.required_item.texture
54
-
dish.time_remaining = DISH_TIMEOUT * 4
55
-
indicator.get_node("ProgressBar").max_value = dish.time_remaining
56
-
indicator.get_node("ProgressBar").value = dish.time_remaining
57
-
dish.node = indicator
58
-
ui_vertical.add_child(indicator)
59
-
item_queue.append_array(dish.dish.ingredients)
60
-
dishes.append(dish)
61
-
time_until_next_dish = DISH_TIMEOUT
49
+
queue_dish()
50
+
51
+
func queue_dish():
52
+
var dish: ActiveDish = ActiveDish.new()
53
+
dish.dish = possible_dishes.pick_random()
54
+
55
+
var indicator = dish_indicator.instantiate()
56
+
indicator.get_node("TextureRect").texture = dish.dish.required_item.texture
57
+
dish.time_remaining = DISH_TIMEOUT * 4
58
+
indicator.get_node("ProgressBar").max_value = dish.time_remaining
59
+
indicator.get_node("ProgressBar").value = dish.time_remaining
60
+
61
+
dish.node = indicator
62
+
ui_vertical.add_child(indicator)
63
+
item_queue.append_array(dish.dish.ingredients)
64
+
active_dishes.append(dish)
65
+
time_until_next_dish = DISH_TIMEOUT
62
66
63
67
func process_dish(dish: ActiveDish, delta):
64
68
if items[0] != null and items[0].item == dish.dish.required_item:
···
90
94
return data.get_custom_data(name)
91
95
92
96
static func position_to_index(position: Vector2) -> int:
93
-
return floor(position.x / TILE_SIZE) + floor(position.y / TILE_SIZE) * width
97
+
return floor(position.x / TILE_SIZE) + floor(position.y / TILE_SIZE) * WIDTH
94
98
95
-
func index_to_position(index: int) -> Vector2:
96
-
var x = index % width * TILE_SIZE + TILE_SIZE/2
97
-
var y = floor(index / width) * TILE_SIZE + TILE_SIZE/2
99
+
static func index_to_position(index: int) -> Vector2:
100
+
var x = index % WIDTH * TILE_SIZE + TILE_SIZE/2
101
+
var y = floor(index / WIDTH) * TILE_SIZE + TILE_SIZE/2
98
102
return Vector2(x, y)
99
103
100
104
func set_item(position: Vector2, item: ItemEntity):
···
110
114
return items[index]
111
115
112
116
func player_cursor() -> Vector2:
113
-
return get_node("Player/Marker2D").global_position
117
+
return $Player/Marker2D.global_position