Basic belts working
This commit is contained in:
+52
-2
@@ -201,7 +201,7 @@ func place_item(item: PackedScene):
|
||||
print("Placing object")
|
||||
var new_item = item.instantiate()
|
||||
new_item.global_position = tile_layer.map_to_local(spawn_pos)
|
||||
new_item.add_to_group("Placed_objects")
|
||||
new_item.add_to_group("placed_objects")
|
||||
add_child(new_item)
|
||||
register_object_at_coordinate(
|
||||
spawn_pos,
|
||||
@@ -212,11 +212,13 @@ func place_item(item: PackedScene):
|
||||
# Custom setup needed
|
||||
if item == EXTRACTOR_SCENE:
|
||||
new_item.setup(object_at_coords['value'])
|
||||
elif item == BELT_SCENE:
|
||||
new_item.setup(spawn_pos, 0)
|
||||
else:
|
||||
print("No custom setup for %s" % item)
|
||||
|
||||
func delete_item(target_pos: Vector2i):
|
||||
var targets = get_tree().get_nodes_in_group("Placed_objects")
|
||||
var targets = get_tree().get_nodes_in_group("placed_objects")
|
||||
for item in targets:
|
||||
print("Trying to match delete at: " + str(tile_layer.local_to_map(item.global_position)[0]) + ", " + str(tile_layer.local_to_map(item.global_position)[1]))
|
||||
if tile_layer.local_to_map(item.global_position) == target_pos:
|
||||
@@ -255,3 +257,51 @@ func _on_adder_button_pressed() -> void:
|
||||
|
||||
func _on_delete_button_pressed() -> void:
|
||||
set_preview_mode(Mode.DELETE, DELETE_SCENE)
|
||||
|
||||
# Run the extractor update
|
||||
func _on_extractor_timer_timeout() -> void:
|
||||
var targets = get_tree().get_nodes_in_group("placed_objects")
|
||||
var production_coords: Array
|
||||
for target in targets:
|
||||
# Check if we are an extractor:
|
||||
if target.scene_file_path == 'res://extractor.tscn':
|
||||
position = tile_layer.local_to_map(target.global_position)
|
||||
print("Extractor produced a %s at %s, %s" % [target.value(), position[0], position[1]])
|
||||
# Make a list of positions where we need to try to produce:
|
||||
for x in range(-1, 2):
|
||||
for y in range(-1, 2):
|
||||
production_coords.append([Vector2(position[0] + x, position[1] + y), target.value()])
|
||||
|
||||
# Now loop through and see if there are empty conveyer belts in the correct positions
|
||||
for target in targets:
|
||||
# Check if this is a belt:
|
||||
if target.scene_file_path == 'res://belt.tscn' and target.empty:
|
||||
position = tile_layer.local_to_map(target.global_position)
|
||||
for prod in production_coords:
|
||||
if position == prod[0]:
|
||||
print("Extractor produced %s onto a belt!" %prod[1])
|
||||
target.collect(prod[1])
|
||||
|
||||
|
||||
func _on_belt_timer_timeout() -> void:
|
||||
#print('belt tick')
|
||||
# Gather the belts:
|
||||
var targets = get_tree().get_nodes_in_group("placed_objects")
|
||||
var next_belt_coords: Array
|
||||
var belts: Array
|
||||
for target in targets:
|
||||
# Check if this is a belt:
|
||||
if target.scene_file_path == 'res://belt.tscn':
|
||||
belts.append(target)
|
||||
if !target.empty:
|
||||
var result = target.move()
|
||||
if result != null:
|
||||
# Try to move the number to the next belt
|
||||
print("value fell off of belt")
|
||||
next_belt_coords.append(result)
|
||||
for belt in belts:
|
||||
for itm in next_belt_coords:
|
||||
position = tile_layer.local_to_map(belt.global_position)
|
||||
print("(%s, %s), (%s, %s)" %[position[0], position[1], itm[0][0], itm[0][1]])
|
||||
if position == itm[0]:
|
||||
belt.collect(itm[1])
|
||||
|
||||
Reference in New Issue
Block a user