diff --git a/.vscode/settings.json b/.vscode/settings.json deleted file mode 100644 index 0f8fbe7..0000000 --- a/.vscode/settings.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "godotTools.editorPath.godot4": "g:\\Godot\\Godot_v4.3-stable_win64_console.exe" -} \ No newline at end of file diff --git a/project/assets/images/Intro.png b/project/assets/images/Intro.png new file mode 100644 index 0000000..699ba7b Binary files /dev/null and b/project/assets/images/Intro.png differ diff --git a/project/assets/images/Intro.png.import b/project/assets/images/Intro.png.import new file mode 100644 index 0000000..483b4f5 --- /dev/null +++ b/project/assets/images/Intro.png.import @@ -0,0 +1,34 @@ +[remap] + +importer="texture" +type="CompressedTexture2D" +uid="uid://di16cmfomo60u" +path="res://.godot/imported/Intro.png-ef37c38298536b7c161e4863253f3325.ctex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://assets/images/Intro.png" +dest_files=["res://.godot/imported/Intro.png-ef37c38298536b7c161e4863253f3325.ctex"] + +[params] + +compress/mode=0 +compress/high_quality=false +compress/lossy_quality=0.7 +compress/hdr_compression=1 +compress/normal_map=0 +compress/channel_pack=0 +mipmaps/generate=false +mipmaps/limit=-1 +roughness/mode=0 +roughness/src_normal="" +process/fix_alpha_border=true +process/premult_alpha=false +process/normal_map_invert_y=false +process/hdr_as_srgb=false +process/hdr_clamp_exposure=false +process/size_limit=0 +detect_3d/compress_to=1 diff --git a/project/main-scenes/island.tscn b/project/main-scenes/island.tscn index fa63fb1..e7cf058 100644 --- a/project/main-scenes/island.tscn +++ b/project/main-scenes/island.tscn @@ -1,10 +1,11 @@ -[gd_scene load_steps=45 format=4 uid="uid://b88asko1ugyd2"] +[gd_scene load_steps=46 format=4 uid="uid://b88asko1ugyd2"] [ext_resource type="Script" path="res://scripts/global/GameManager.gd" id="1_eeg2d"] [ext_resource type="Script" path="res://scripts/tilemap/World.gd" id="1_k0rw8"] [ext_resource type="TileSet" uid="uid://bi836ygcmyvhb" path="res://assets/tilemap/tileset.tres" id="1_vlccq"] [ext_resource type="Script" path="res://scripts/global/CameraController.gd" id="2_k51iv"] [ext_resource type="Material" uid="uid://ckg3be082ny3h" path="res://assets/shader/shader_vignette.tres" id="3_7waul"] +[ext_resource type="Texture2D" uid="uid://di16cmfomo60u" path="res://assets/images/Intro.png" id="3_oufrl"] [ext_resource type="Script" path="res://scripts/player/PlayerManager.gd" id="4_1xqo1"] [ext_resource type="Texture2D" uid="uid://1ae5agveqddp" path="res://icon.svg" id="4_o8ona"] [ext_resource type="Script" path="res://scripts/visualization/BehaviorTreeVisualizer.gd" id="5_ecfvx"] @@ -68,6 +69,7 @@ size_flags_horizontal = 4 [node name="TopLeftContainer" type="MarginContainer" parent="Camera2D/CanvasLayer"] offset_right = 204.0 offset_bottom = 122.0 +scale = Vector2(1.3, 1.3) theme_override_constants/margin_left = 5 theme_override_constants/margin_top = 5 @@ -202,6 +204,7 @@ anchor_bottom = 1.0 offset_top = -5.0 grow_horizontal = 2 grow_vertical = 0 +size_flags_vertical = 8 theme_override_constants/margin_left = 5 theme_override_constants/margin_bottom = 5 @@ -213,8 +216,9 @@ size_flags_vertical = 8 [node name="TreeVisualizer" type="Window" parent="Camera2D/CanvasLayer"] unique_name_in_owner = true -position = Vector2i(35, 405) +position = Vector2i(0, 36) size = Vector2i(1075, 225) +visible = false script = ExtResource("5_ecfvx") [node name="GraphEdit" type="GraphEdit" parent="Camera2D/CanvasLayer/TreeVisualizer"] @@ -226,13 +230,18 @@ grow_horizontal = 2 grow_vertical = 2 size_flags_horizontal = 3 size_flags_vertical = 3 -scroll_offset = Vector2(-100, -100) show_menu = false show_zoom_buttons = false show_grid_buttons = false show_minimap_button = false show_arrange_button = false +[node name="IntroImage" type="Sprite2D" parent="Camera2D"] +visible = false +z_index = 1 +scale = Vector2(0.347656, 0.373264) +texture = ExtResource("3_oufrl") + [node name="Tileset" type="Node2D" parent="."] script = ExtResource("1_k0rw8") diff --git a/project/project.godot b/project/project.godot index 7dcc456..c6ea3e3 100644 --- a/project/project.godot +++ b/project/project.godot @@ -78,12 +78,12 @@ key_9={ } force_game_tick={ "deadzone": 0.5, -"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":70,"key_label":0,"unicode":102,"location":0,"echo":false,"script":null) +"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":84,"key_label":0,"unicode":0,"location":0,"echo":false,"script":null) ] } force_game_tick_fast={ "deadzone": 0.5, -"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":71,"key_label":0,"unicode":103,"location":0,"echo":false,"script":null) +"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":70,"key_label":0,"unicode":0,"location":0,"echo":false,"script":null) ] } key_4={ @@ -106,6 +106,11 @@ key_6={ "events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":54,"key_label":0,"unicode":54,"location":0,"echo":false,"script":null) ] } +auto_tick={ +"deadzone": 0.5, +"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":32,"key_label":0,"unicode":32,"location":0,"echo":false,"script":null) +] +} [rendering] diff --git a/project/scripts/global/EventsTracker.gd b/project/scripts/global/EventsTracker.gd index e3ce58f..51f72d6 100644 --- a/project/scripts/global/EventsTracker.gd +++ b/project/scripts/global/EventsTracker.gd @@ -22,7 +22,7 @@ enum Event { }; # static var events: Array[TrackedEvent] = [] -static var max_events: int = 20 +static var max_events: int = 14 static var callbacks: Array[Callable] = [] @@ -79,9 +79,9 @@ static func populate_visual_log_create_label(event: TrackedEvent, container: Con elif event_id == Event.GAME_STATE_WIN: text = "Game won" elif event_id == Event.NEW_EXPLORATION_GOAL: - text = "New exploration goal " + str(params["goal"]) + text = "New goal " + str(params["goal"]) elif event_id == Event.EXPLORATION_GOAL_REACHED: - text = "Exploration goal reached " + str(params["goal"]) + text = "Goal reached" elif event_id == Event.TEMPERATURE_COLD: text = "Temperature is cold: -" + str(params["temperature"]) elif event_id == Event.TIME_SUNDOWN: @@ -91,6 +91,7 @@ static func populate_visual_log_create_label(event: TrackedEvent, container: Con var event_label: Label = Label.new() event_label.text = text + event_label.add_theme_font_size_override("font_size", 24 * game_manager.calculate_scale(Vector2(1200, 1200)).y) event_label.add_theme_color_override("font_color", Color(0, 0, 0)) var event_container: HBoxContainer = HBoxContainer.new() @@ -101,6 +102,8 @@ static func populate_visual_log_create_label(event: TrackedEvent, container: Con if item_texture: var item_texture_rect: TextureRect = TextureRect.new() item_texture_rect.texture = item_texture + item_texture_rect.set_expand_mode(TextureRect.EXPAND_FIT_WIDTH) + item_texture_rect.set_stretch_mode(TextureRect.STRETCH_KEEP_ASPECT_CENTERED) event_container.add_child(item_texture_rect) container.add_child(event_container) diff --git a/project/scripts/global/GameManager.gd b/project/scripts/global/GameManager.gd index a3c9a5f..919bef7 100644 --- a/project/scripts/global/GameManager.gd +++ b/project/scripts/global/GameManager.gd @@ -17,6 +17,11 @@ var tilemap_navigation: TilemapNavigation = TilemapNavigation.new() @onready var tree_visualizer: BehaviorTreeVisualizer = %TreeVisualizer +# +var waiting_for_input: bool = true + +@onready var intro_image: Sprite2D = $Camera2D/IntroImage + func _ready() -> void: tilemap_navigation.world = world @@ -28,32 +33,51 @@ func _ready() -> void: update_bars() call_deferred("defer_ready") + func defer_ready() -> void: tree_visualizer.behavior_tree = player.behavior_tree tree_visualizer.build_tree() + intro_image.visible = true + await wait_for_key_press() + get_tree().create_tween().tween_method(set_intro_opacity, 1.0, 0.0, 1.0) + # game_ticker.start() - func _process(delta: float) -> void: - if Input.is_action_just_pressed("key_1"): - camera.go_to_zooming(Vector2(517.469787597656, 289.846008300781), 1.771561) - if Input.is_action_just_pressed("key_2"): - camera.go_to_zooming(Vector2(789.883972167969, 450.102813720703), 0.56015348434448) - if Input.is_action_just_pressed("key_9"): - world.camp_manager.campfire_light() - world.camp_manager.sleep_effect() - world.camp_manager.campfire_extinguish() if Input.is_action_just_pressed("force_game_tick"): Task.print_behavior_tree_evaluation = true _on_game_tick_timeout() Task.print_behavior_tree_evaluation = false if Input.is_action_pressed("force_game_tick_fast"): _on_game_tick_timeout() - if Input.is_action_just_pressed("key_6"): + if Input.is_action_just_pressed("key_2"): toggle_temperature_layer() + camera.print_config() + if Input.is_action_just_pressed("auto_tick"): + if game_ticker.is_stopped(): + game_ticker.start() + else: + game_ticker.stop() + if intro_image.is_visible(): + intro_image.set_scale(calculate_scale(intro_image.texture.get_size())) + + +func calculate_scale(image_size: Vector2) -> Vector2: + var viewport_size: Vector2 = world.get_viewport_rect().size + var scale: float = viewport_size.x / image_size.x + return Vector2(scale, scale) + + +# SECTION: intro + +func set_intro_opacity(opacity: float) -> void: + intro_image.set_modulate(Color(1, 1, 1, opacity)) + + +# SECTION: game tick func player_health_depleted(): # TODO @@ -76,9 +100,40 @@ func _on_game_tick_timeout() -> void: update_bars() handle_result_game_state(player.behavior_tree.blackboard) + if not game_ticker.is_stopped(): + camera_follow_player() + timer_on_game_tick_timeout.stop() +func camera_follow_player() -> void: + var player_position: Vector2 = world.tilemap_player.cell_to_local(player.board_position) + var targeted_position = null + + if player.behavior_tree.blackboard.has("path"): + var path: Array = player.behavior_tree.blackboard["path"] + if path.size() > 0: + targeted_position = world.tilemap_player.cell_to_local(path[path.size() - 1]) + + if not targeted_position: + camera.go_to(player_position) + return + + var avg_position = (player_position + targeted_position) / 2 + var distance: float = player_position.distance_to(targeted_position) + if distance < 200: + camera.go_to_zooming(avg_position, distance_to_zoom_level(200)) + else: + var zoom_level: float = distance_to_zoom_level(distance) + camera.go_to_zooming(avg_position, zoom_level) + + +func distance_to_zoom_level(distance: float) -> float: + var a: float = 862.08 + var b: float = 274.13 + return a / (distance + b) + + func handle_result_game_state(blackboard: Dictionary) -> void: if blackboard.has("game_state_win"): EventsTracker.track(EventsTracker.Event.GAME_STATE_WIN) @@ -112,3 +167,14 @@ func update_bars() -> void: func toggle_temperature_layer() -> void: world.tilemap_temperature.tilemap.visible = not world.tilemap_temperature.tilemap.visible + + +func wait_for_key_press(): + waiting_for_input = true + while waiting_for_input: + await get_tree().process_frame + + +func _input(event): + if event is InputEventKey and event.pressed: + waiting_for_input = false diff --git a/project/scripts/player/PlayerManager.gd b/project/scripts/player/PlayerManager.gd index ba5f9b5..7b28695 100644 --- a/project/scripts/player/PlayerManager.gd +++ b/project/scripts/player/PlayerManager.gd @@ -20,10 +20,10 @@ var game_manager: GameManager = null var last_board_position: Vector2i = Vector2i(0, 0) var board_position: Vector2i = Vector2i(0, 0): - set(value): - last_board_position = board_position - board_position = value - update_board() + set(value): + last_board_position = board_position + board_position = value + update_board() @onready var behavior_tree: BehaviorTree = $BehaviorTree @@ -34,212 +34,212 @@ var temperature_timer: int = 0 var health: int = max_health var inventory_slot: Vector2i = tilemap_types.EMPTY: - set(value): - inventory_slot = value - update_board() + set(value): + inventory_slot = value + update_board() var player_memory: Dictionary = {} func _ready() -> void: - call_deferred("defer_ready") + call_deferred("defer_ready") func defer_ready() -> void: - behavior_tree.game_manager = game_manager - var player_start_position: Array[Vector2i] = game_manager.world.tilemap_player.get_cells_by_type(tilemap_types.PLAYER_DOWN) - if len(player_start_position) > 0: - board_position = player_start_position[0] - else: - push_error("No player start position found on tilemap") - update_board() + behavior_tree.game_manager = game_manager + var player_start_position: Array[Vector2i] = game_manager.world.tilemap_player.get_cells_by_type(tilemap_types.PLAYER_DOWN) + if len(player_start_position) > 0: + board_position = player_start_position[0] + else: + push_error("No player start position found on tilemap") + update_board() func _process(delta: float) -> void: - if Input.is_action_just_pressed("key_3"): - game_manager.camera.go_to_zooming(game_manager.world.tilemap_player.cell_to_local(board_position), 2) - if Input.is_action_just_pressed("key_5"): - pick_up_item(Vector2i(5, 8)) - pick_up_item(Vector2i(9, 9)) - if Input.is_action_just_pressed("key_4"): - var nearest: Vector2i = find_nearest_object([game_manager.world.tilemap_types.OBJECT_I_TREE_FULL]) - # nearest.x = nearest.x - 1 - walk_towards(nearest) + if Input.is_action_just_pressed("key_1"): + game_manager.camera.go_to_zooming(game_manager.world.tilemap_player.cell_to_local(board_position), 2) + if Input.is_action_just_pressed("key_5"): + pick_up_item(Vector2i(5, 8)) + pick_up_item(Vector2i(9, 9)) + if Input.is_action_just_pressed("key_4"): + var nearest: Vector2i = find_nearest_object([game_manager.world.tilemap_types.OBJECT_I_TREE_FULL]) + # nearest.x = nearest.x - 1 + walk_towards(nearest) # SECTION: board access/mangement func update_board() -> void: - game_manager.world.tilemap_player.clear_cells() - # decide what direction the player is facing tilemap_types.PLAYER_DOWN, ... - var direction: Vector2i = find_direction(last_board_position, board_position) - game_manager.world.tilemap_player.set_cell(board_position, tilemap_types.player_sprite_from_direction(direction)) + game_manager.world.tilemap_player.clear_cells() + # decide what direction the player is facing tilemap_types.PLAYER_DOWN, ... + var direction: Vector2i = find_direction(last_board_position, board_position) + game_manager.world.tilemap_player.set_cell(board_position, tilemap_types.player_sprite_from_direction(direction)) - if inventory_slot and inventory_slot != tilemap_types.EMPTY: - %InventoryContentRect.texture = game_manager.world.tilemap_interactive.get_cell_texture(inventory_slot) - else: - %InventoryContentRect.texture = null + if inventory_slot and inventory_slot != tilemap_types.EMPTY: + %InventoryContentRect.texture = game_manager.world.tilemap_interactive.get_cell_texture(inventory_slot) + else: + %InventoryContentRect.texture = null # SECTION: inventory system func pick_up_item(tilemap_pos: Vector2i) -> void: - var pick_up_cell: TileData = game_manager.world.tilemap_interactive.get_cell(tilemap_pos) - if not pick_up_cell: - push_warning("Player trying to pick up item that does not exist at ", tilemap_pos) - return + var pick_up_cell: TileData = game_manager.world.tilemap_interactive.get_cell(tilemap_pos) + if not pick_up_cell: + push_warning("Player trying to pick up item that does not exist at ", tilemap_pos) + return - var pick_up_item_type: Vector2i = game_manager.world.tilemap_interactive.tilemap.get_cell_atlas_coords(tilemap_pos) + var pick_up_item_type: Vector2i = game_manager.world.tilemap_interactive.tilemap.get_cell_atlas_coords(tilemap_pos) - # check if inventory contains item that needs to be transformed on dropping - # this should never be the case, as the pick up item operation should already reflect this transformation - var tile_drop_item: Vector2i = inventory_slot - if tile_drop_item == tilemap_types.OBJECT_I_FILLED_BUSH: - tile_drop_item = tilemap_types.OBJECT_I_BERRY - elif tile_drop_item == tilemap_types.OBJECT_I_TREE_FULL: - tile_drop_item = tilemap_types.OBJECT_I_STICK + # check if inventory contains item that needs to be transformed on dropping + # this should never be the case, as the pick up item operation should already reflect this transformation + var tile_drop_item: Vector2i = inventory_slot + if tile_drop_item == tilemap_types.OBJECT_I_FILLED_BUSH: + tile_drop_item = tilemap_types.OBJECT_I_BERRY + elif tile_drop_item == tilemap_types.OBJECT_I_TREE_FULL: + tile_drop_item = tilemap_types.OBJECT_I_STICK - # check if tile will transform into another tile upon pickup - var tile_after_pickup_transform = null - if pick_up_item_type == tilemap_types.OBJECT_I_FILLED_BUSH: - tile_after_pickup_transform = tilemap_types.OBJECT_I_EMPTY_BUSH - pick_up_item_type = tilemap_types.OBJECT_I_BERRY - elif pick_up_item_type == tilemap_types.OBJECT_I_TREE_FULL: - tile_after_pickup_transform = tilemap_types.OBJECT_I_TREE_CUT - pick_up_item_type = tilemap_types.OBJECT_I_STICK + # check if tile will transform into another tile upon pickup + var tile_after_pickup_transform = null + if pick_up_item_type == tilemap_types.OBJECT_I_FILLED_BUSH: + tile_after_pickup_transform = tilemap_types.OBJECT_I_EMPTY_BUSH + pick_up_item_type = tilemap_types.OBJECT_I_BERRY + elif pick_up_item_type == tilemap_types.OBJECT_I_TREE_FULL: + tile_after_pickup_transform = tilemap_types.OBJECT_I_TREE_CUT + pick_up_item_type = tilemap_types.OBJECT_I_STICK - # check if the inventory slot is empty - if inventory_slot == tilemap_types.EMPTY: - inventory_slot = pick_up_item_type - if tile_after_pickup_transform: - game_manager.world.tilemap_interactive.set_cell(tilemap_pos, tile_after_pickup_transform) - else: - game_manager.world.tilemap_interactive.clear_cell(tilemap_pos) - print("Picked up item: ", pick_up_item_type) - EventsTracker.track(EventsTracker.Event.PLAYER_PICKED_UP_ITEM, {"item": pick_up_item_type}) + # check if the inventory slot is empty + if inventory_slot == tilemap_types.EMPTY: + inventory_slot = pick_up_item_type + if tile_after_pickup_transform: + game_manager.world.tilemap_interactive.set_cell(tilemap_pos, tile_after_pickup_transform) + else: + game_manager.world.tilemap_interactive.clear_cell(tilemap_pos) + print("Picked up item: ", pick_up_item_type) + EventsTracker.track(EventsTracker.Event.PLAYER_PICKED_UP_ITEM, {"item": pick_up_item_type}) - else: - # inventory is full, swap the item - print("Inventory is full. Swapping item: ", inventory_slot, " with item: ", pick_up_item_type) - EventsTracker.track(EventsTracker.Event.PLAYER_DROPPED_ITEM, {"item": inventory_slot}) - EventsTracker.track(EventsTracker.Event.PLAYER_PICKED_UP_ITEM, {"item": pick_up_item_type}) - if tile_after_pickup_transform: - game_manager.world.tilemap_interactive.set_cell(tilemap_pos, tile_after_pickup_transform) - var drop_location: Vector2i = game_manager.world.find_item_drop_location(tilemap_pos) - if drop_location != tilemap_types.EMPTY: - game_manager.world.tilemap_interactive.set_cell(drop_location, tile_drop_item) - else: - push_warning("Could not find valid drop position for ", inventory_slot) - else: - game_manager.world.tilemap_interactive.set_cell(tilemap_pos, tile_drop_item) - inventory_slot = pick_up_item_type + else: + # inventory is full, swap the item + print("Inventory is full. Swapping item: ", inventory_slot, " with item: ", pick_up_item_type) + EventsTracker.track(EventsTracker.Event.PLAYER_DROPPED_ITEM, {"item": inventory_slot}) + EventsTracker.track(EventsTracker.Event.PLAYER_PICKED_UP_ITEM, {"item": pick_up_item_type}) + if tile_after_pickup_transform: + game_manager.world.tilemap_interactive.set_cell(tilemap_pos, tile_after_pickup_transform) + var drop_location: Vector2i = game_manager.world.find_item_drop_location(tilemap_pos) + if drop_location != tilemap_types.EMPTY: + game_manager.world.tilemap_interactive.set_cell(drop_location, tile_drop_item) + else: + push_warning("Could not find valid drop position for ", inventory_slot) + else: + game_manager.world.tilemap_interactive.set_cell(tilemap_pos, tile_drop_item) + inventory_slot = pick_up_item_type # SECTION: player movement func walk_towards(position: Vector2i) -> void: - var path: Array[Vector2i] = game_manager.tilemap_navigation.find_path(board_position, position) - walk_along(path) + var path: Array[Vector2i] = game_manager.tilemap_navigation.find_path(board_position, position) + walk_along(path) func walk_along(path: Array[Vector2i]) -> void: - if len(path) > 1: + if len(path) > 1: - var next_position: Vector2i - if path.has(board_position): - var current_index: int = path.find(board_position) - if current_index < path.size() - 1: - next_position = path[current_index + 1] - else: - next_position = path[1] - else: - next_position = path[1] + var next_position: Vector2i + if path.has(board_position): + var current_index: int = path.find(board_position) + if current_index < path.size() - 1: + next_position = path[current_index + 1] + else: + next_position = path[1] + else: + next_position = path[1] - var direction: Vector2i = find_direction(board_position, next_position) - move_player(direction) - game_manager.tilemap_navigation.chosen_path = path - else: - push_warning("walk_along path is empty") + var direction: Vector2i = find_direction(board_position, next_position) + move_player(direction) + game_manager.tilemap_navigation.chosen_path = path + else: + push_warning("walk_along path is empty") func move_player(direction: Vector2i) -> void: - var new_position: Vector2 = board_position + direction - if game_manager.world.is_walkable(new_position): - board_position = new_position - else: - push_warning("Player trying to move to non-walkable position, prevented ", new_position) + var new_position: Vector2 = board_position + direction + if game_manager.world.is_walkable(new_position): + board_position = new_position + else: + push_warning("Player trying to move to non-walkable position, prevented ", new_position) func find_nearest_object(object_collection: Array[Vector2i]) -> Vector2i: - var object_positions: Array[Vector2i] = [] + var object_positions: Array[Vector2i] = [] - for obj in object_collection: - object_positions.append_array(game_manager.world.tilemap_interactive.get_cells_by_type(obj)) + for obj in object_collection: + object_positions.append_array(game_manager.world.tilemap_interactive.get_cells_by_type(obj)) - if object_positions.size() == 0: - push_warning("No " + str(object_collection) + " found!") - return tilemap_types.NO_TILE_FOUND + if object_positions.size() == 0: + push_warning("No " + str(object_collection) + " found!") + return tilemap_types.NO_TILE_FOUND - var closest_object: Vector2i = tilemap_types.NO_TILE_FOUND - var shortest_distance: float = 99999999 + var closest_object: Vector2i = tilemap_types.NO_TILE_FOUND + var shortest_distance: float = 99999999 - for position in object_positions: - var distance: float = game_manager.tilemap_navigation.manhattan_distance(board_position, position) - if closest_object == tilemap_types.NO_TILE_FOUND or distance < shortest_distance: - closest_object = position - shortest_distance = distance + for position in object_positions: + var distance: float = game_manager.tilemap_navigation.manhattan_distance(board_position, position) + if closest_object == tilemap_types.NO_TILE_FOUND or distance < shortest_distance: + closest_object = position + shortest_distance = distance - print("Find nearest " + str(object_collection) + " at:", closest_object) - return closest_object + print("Find nearest " + str(object_collection) + " at:", closest_object) + return closest_object func find_direction(pos_a: Vector2i, pos_b: Vector2i) -> Vector2i: - var direction: Vector2i = Vector2i(0, 0) - if pos_a.x < pos_b.x: - direction.x = 1 - elif pos_a.x > pos_b.x: - direction.x = -1 + var direction: Vector2i = Vector2i(0, 0) + if pos_a.x < pos_b.x: + direction.x = 1 + elif pos_a.x > pos_b.x: + direction.x = -1 - if pos_a.y < pos_b.y: - direction.y = 1 - elif pos_a.y > pos_b.y: - direction.y = -1 + if pos_a.y < pos_b.y: + direction.y = 1 + elif pos_a.y > pos_b.y: + direction.y = -1 - return direction + return direction # SECTION: game tick func get_current_temperature() -> int: - return game_manager.world.tilemap_temperature.get_custom_data(board_position, "temperature", 0) as int + return game_manager.world.tilemap_temperature.get_custom_data(board_position, "temperature", 0) as int func tick_handle_temperature(cell_temperature: int) -> void: - if temperature_buff_timer > 0: - temperature_buff_timer -= 1 - return + if temperature_buff_timer > 0: + temperature_buff_timer -= 1 + return - if cell_temperature == 0: - temperature_timer = 0 - elif temperature_timer > temperature_endure: - temperature_timer += cell_temperature - health -= temperature_damage + if cell_temperature == 0: + temperature_timer = 0 + elif temperature_timer > temperature_endure: + temperature_timer += cell_temperature + health -= temperature_damage func tick_handle_food(): - if food > 0: - food -= 1 - if food <= 0: - health -= food_damage + if food > 0: + food -= 1 + if food <= 0: + health -= food_damage func game_tick() -> void: - behavior_tree.game_tick() - StepVisualization.add_circle_tileset(board_position, view_distance / 1.2, StepVisualization.CircleType.PLAYER_VIEW) + behavior_tree.game_tick() + StepVisualization.add_circle_tileset(board_position, view_distance / 1.2, StepVisualization.CircleType.PLAYER_VIEW) - tick_handle_temperature(get_current_temperature()) - tick_handle_food() + tick_handle_temperature(get_current_temperature()) + tick_handle_food() - if health < 0: - game_manager.player_health_depleted() + if health < 0: + game_manager.player_health_depleted() - update_board() + update_board()