extends Window var key @onready var data = Data.data.zones[key] @onready var image = Data.data.images[key] @onready var sprite_2d: Sprite2D = $Sprite2D const CREATURE = preload("res://src/Creature.tscn") var tiles = [] var newt = [] func _process(delta: float) -> void: if mode == Window.MODE_MINIMIZED: mode = Window.MODE_WINDOWED func _ready() -> void: var window_size = get_tree().root.get_window().size get_window().position = Vector2i(randi_range(250, window_size.x - 250 - 200), randi_range(250, window_size.y - 250 - 200)) + DisplayServer.screen_get_position(0) title = data.name sprite_2d.texture = image sprite_2d.position = Vector2(int(data.size[0]) * 12 / 2, int(data.size[1]) * 12 / 2) func attempt_place(key, position, tiles2): var creature_data = Data.data.creatures[key] var tile_size = Vector2(12, 12) var round_bound = round(position.x / tile_size.x) var lower_bound = round_bound - 1 var upper_bound = round_bound var lower_bound2 = round_bound var upper_bound2 = round_bound + 1 var bound_2 = round((position.x + 6) / tile_size.x) var round_bound_y = round(position.y / tile_size.y) var lower_bound_y = round_bound_y - 1 var upper_bound_y = round_bound_y var lower_bound_y2 = round_bound_y var upper_bound_y2 = round_bound_y + 1 var bound_2_y = round((position.y + 6) / tile_size.y) prints(position / tile_size.x) if lower_bound_y == upper_bound_y: upper_bound_y += 1 if lower_bound_y2 == upper_bound_y2: upper_bound_y2 += 1 var tile_x = round(position.x / tile_size.x) var tile_y = round(position.y / tile_size.y) var valid_x = false var bounds_x var bounds_y if creature_data.width == 1: valid_x = _check_tile(bound_2, 0) else: var check1 = _check_tile(lower_bound, 0) and _check_tile(upper_bound, 0) var check2 = _check_tile(lower_bound2, 0) and _check_tile(upper_bound2, 0) valid_x = check1 or check2 if check1: bounds_x = Vector2(lower_bound, upper_bound) if check2: bounds_x = Vector2(lower_bound2, upper_bound2) var valid_y = false if creature_data.height == 1: valid_y = _check_tile(bound_2_y, 1) else: var check1 = _check_tile(lower_bound_y, 1) and _check_tile(upper_bound_y, 1) var check2 = _check_tile(lower_bound_y2, 1) and _check_tile(upper_bound_y2, 1) valid_y = check1 or check2 if check1: bounds_y = Vector2(lower_bound_y, upper_bound_y) if check2: bounds_y = Vector2(lower_bound_y2, upper_bound_y2) if valid_x and valid_y: if _check_if_contains(creature_data, bound_2, bound_2_y, bounds_x, bounds_y, tiles2): return false var new_creature = CREATURE.instantiate() new_creature.key = key new_creature.position = Vector2((bound_2 - 0.5) if creature_data.width == 1 else bounds_x[1] - 1, (bound_2_y - 0.5) if creature_data.height == 1 else bounds_y[1] - 1) * 12 get_window().add_child(new_creature) new_creature.tiled = true new_creature.tiles = newt return true func remove_tiles(array): for element in array: tiles.erase(element) func _check_if_contains(data, bound1, bound1y, bounds2, bounds2y, tiles2): newt = [] var checks = [] if data.width == 1: if data.height == 1: checks.push_back(Vector2i(bound1, bound1y)) else: checks.push_back(Vector2i(bound1, bounds2y[0])) checks.push_back(Vector2i(bound1, bounds2y[1])) else: if data.height == 1: checks.push_back(Vector2i(bounds2[0], bound1y)) checks.push_back(Vector2i(bounds2[1], bound1y)) else: checks.push_back(Vector2i(bounds2[0], bounds2y[0])) checks.push_back(Vector2i(bounds2[1], bounds2y[0])) checks.push_back(Vector2i(bounds2[0], bounds2y[1])) checks.push_back(Vector2i(bounds2[1], bounds2y[1])) for check in checks: if tiles.has(check): if tiles2: if not tiles2.has(check): return true else: return true for check in checks: newt.push_back(check) tiles.push_back(check) return false func _check_tile(coords, dir): var placeable_min = 2 var placeable_max = int(data.size[dir]) - 1 if coords >= placeable_min and coords <= placeable_max: return true return false # #New Zones # #- Get More Customers #- Creatures drop resources more often #- Resources randomly spawn more often #- More wild creatures spawn #- Closing time is 10 minutes later #- More chance for creatures to drop a large amount at once #- Customers are willing to pay more #- Less chance of thieves #- Chance for rich customer