pull/4/head
Luca 2025-01-08 14:59:29 +01:00
parent facdb2487a
commit d81f9cace8
12 changed files with 1857 additions and 175 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 433 B

File diff suppressed because it is too large Load Diff

File diff suppressed because one or more lines are too long

View File

@ -81,6 +81,26 @@ force_game_tick={
"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":-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)
] ]
} }
key_4={
"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":52,"key_label":0,"unicode":52,"location":0,"echo":false,"script":null)
]
}
key_7={
"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":55,"key_label":0,"unicode":55,"location":0,"echo":false,"script":null)
]
}
key_5={
"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":53,"key_label":0,"unicode":53,"location":0,"echo":false,"script":null)
]
}
key_6={
"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":54,"key_label":0,"unicode":54,"location":0,"echo":false,"script":null)
]
}
[rendering] [rendering]

View File

@ -8,28 +8,27 @@ extends Node
func _ready() -> void: func _ready() -> void:
player.game_manager = self player.game_manager = self
game_ticker.start()
func _process(delta: float) -> void: func _process(delta: float) -> void:
if Input.is_action_just_pressed("key_1"): if Input.is_action_just_pressed("key_1"):
camera.go_to_zooming(Vector2(517.469787597656, 289.846008300781), 1.771561) camera.go_to_zooming(Vector2(517.469787597656, 289.846008300781), 1.771561)
if Input.is_action_just_pressed("key_2"): if Input.is_action_just_pressed("key_2"):
camera.go_to_zooming(Vector2(789.883972167969, 450.102813720703), 0.56015348434448) camera.go_to_zooming(Vector2(789.883972167969, 450.102813720703), 0.56015348434448)
if Input.is_action_just_pressed("key_9"): if Input.is_action_just_pressed("key_9"):
camera.print_config() camera.print_config()
if Input.is_action_just_pressed("force_game_tick"): if Input.is_action_just_pressed("force_game_tick"):
player.game_tick() player.game_tick()
func player_health_depleted(): func player_health_depleted():
# TODO # TODO
pass pass
func _on_game_tick_timeout() -> void: func _on_game_tick_timeout() -> void:
var timer_on_game_tick_timeout: PerformanceTimer = PerformanceTimer.new() var timer_on_game_tick_timeout: PerformanceTimer = PerformanceTimer.new()
timer_on_game_tick_timeout.display_name = "_on_game_tick_timeout" timer_on_game_tick_timeout.display_name = "_on_game_tick_timeout"
player.game_tick() player.game_tick()
timer_on_game_tick_timeout.stop() timer_on_game_tick_timeout.stop()

View File

@ -1,6 +1,7 @@
class_name PlayerManager class_name PlayerManager
extends Node extends Node
@onready var inventory_label = $CanvasLayer/VBoxContainer/InventoryLabel
@export var food_damage: int = 1 @export var food_damage: int = 1
@export var temperature_damage: int = 1 @export var temperature_damage: int = 1
@export var temperature_endure: int = 50 @export var temperature_endure: int = 50
@ -21,108 +22,175 @@ var inventory_slot: Vector2i = tilemap_types.EMPTY
func _ready() -> void: func _ready() -> void:
call_deferred("defer_ready") call_deferred("defer_ready")
func defer_ready() -> void: func defer_ready() -> void:
behavior_tree.game_manager = game_manager behavior_tree.game_manager = game_manager
update_board() update_board()
func _process(delta: float) -> void: func _process(delta: float) -> void:
if Input.is_action_just_pressed("key_3"): 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) game_manager.camera.go_to_zooming(game_manager.world.tilemap_player.cell_to_local(board_position), 2)
if Input.is_action_just_pressed("key_4"):
move_to_nearest_tree()
move_to_nearest_bush()
move_to_chest()
move_to_campfire()
move_to_boatpart()
# if Input.is_action_just_pressed("key_5"):
# move_to_nearest_bush()
# # if Input.is_action_just_pressed("key_6"):
# # move_to_boatpart()
# if Input.is_action_just_pressed("key_7"):
# move_to_chest()
# # if Input.is_action_just_pressed("key_8"):
# # move_to_boat_building_place()
# if Input.is_action_just_pressed("key_6"):
# move_to_campfire()
# SECTION: board access/mangement # SECTION: board access/mangement
func update_board() -> void: func update_board() -> void:
game_manager.world.tilemap_player.clear_cells() game_manager.world.tilemap_player.clear_cells()
game_manager.world.tilemap_player.set_cell(board_position, tilemap_types.PLAYER) game_manager.world.tilemap_player.set_cell(board_position, tilemap_types.PLAYER)
# SECTION: inventory system # SECTION: inventory system
func pick_up_item(tilemap_pos: Vector2i) -> void: func pick_up_item(tilemap_pos: Vector2i) -> void:
var pick_up_cell: TileData = game_manager.world.tilemap_interactive.get_cell(tilemap_pos) var pick_up_cell: TileData = game_manager.world.tilemap_interactive.get_cell(tilemap_pos)
if not pick_up_cell: if not pick_up_cell:
push_warning("Player trying to pick up item that does not exist at ", tilemap_pos) push_warning("Player trying to pick up item that does not exist at ", tilemap_pos)
return 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)
if inventory_slot != tilemap_types.EMPTY: # Check if the inventory slot is empty
# set the type of the item on the tilemap to the one in the inventory, switching them if inventory_slot == tilemap_types.EMPTY:
game_manager.world.tilemap_interactive.set_cell(tilemap_pos, inventory_slot) inventory_slot = pick_up_item_type
game_manager.world.tilemap_interactive.clear_cell(tilemap_pos) # Clear the tilemap
inventory_slot = pick_up_item_type print("Picked up 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)
game_manager.world.tilemap_interactive.set_cell(tilemap_pos, inventory_slot)
inventory_slot = pick_up_item_type
# SECTION: player movement # SECTION: player movement
func walk_towards(position: Vector2i) -> void: func walk_towards(position: Vector2i) -> void:
walk_along(game_manager.world.find_path(board_position, position)) walk_along(game_manager.world.find_path(board_position, position))
print(game_manager.world.find_path(board_position, position))
func walk_along(path: Array[Vector2i]) -> void: func walk_along(path: Array[Vector2i]) -> void:
if len(path) > 1: if len(path) > 1:
var next_position: Vector2i = path[1] var next_position: Vector2i = path[1]
var direction: Vector2i = find_direction(board_position, next_position) var direction: Vector2i = find_direction(board_position, next_position)
move_player(direction) move_player(direction)
func move_player(direction: Vector2i) -> void: func move_player(direction: Vector2i) -> void:
var new_position: Vector2 = board_position + direction var new_position: Vector2 = board_position + direction
if game_manager.world.is_walkable(new_position): if game_manager.world.is_walkable(new_position):
board_position = new_position board_position = new_position
else: print("Moved to:", board_position)
push_warning("Player trying to move to non-walkable position, prevented ", new_position) update_board()
else:
push_warning("Player trying to move to non-walkable position, prevented ", new_position)
func move_to_nearest_tree():
move_to_nearest_object(game_manager.world.tilemap_types.OBJECT_I_TREE_1, "tree")
func move_to_nearest_bush():
move_to_nearest_object(game_manager.world.tilemap_types.OBJECT_I_BERRY_1, "bush")
func move_to_chest():
move_to_nearest_object(game_manager.world.tilemap_types.OBJECT_I_CHEST_1, "chest")
func move_to_boatpart():
move_to_nearest_object(game_manager.world.tilemap_types.OBJECT_I_BOATPART_1, "boat part")
# func move_to_boat_building_place():
# move_to_nearest_object(game_manager.world.tilemap_types.OBJECT_I_BOATPART_BUILDING_PLACE, "boatbuildingplace")
func move_to_campfire():
move_to_nearest_object(game_manager.world.tilemap_types.OBJECT_I_CAMPFIRE_1, "campfire")
func move_to_nearest_object(object_type: Vector2i, object_name: String) -> void:
# Aktuelle Spielerposition
var player_position: Vector2i = board_position
# Koordinaten aller Objekte des angegebenen Typs suchen
var object_positions: Array[Vector2i] = game_manager.world.tilemap_interactive.get_cells_by_type(object_type)
if object_positions.size() == 0:
push_warning("No " + object_name + " found!")
return
# Nächstes Objekt finden
var closest_object: Vector2i = object_positions[0]
var shortest_distance: float = player_position.distance_to(closest_object)
for position in object_positions:
var distance: float = player_position.distance_to(position)
if distance < shortest_distance:
closest_object = position
shortest_distance = distance
# Spieler bewegen
print("Moving to nearest " + object_name + " at:", closest_object)
walk_towards(closest_object)
func find_direction(pos_a: Vector2i, pos_b: Vector2i) -> Vector2i: func find_direction(pos_a: Vector2i, pos_b: Vector2i) -> Vector2i:
var direction: Vector2i = Vector2i(0, 0) var direction: Vector2i = Vector2i(0, 0)
if pos_a.x < pos_b.x: if pos_a.x < pos_b.x:
direction.x = 1 direction.x = 1
elif pos_a.x > pos_b.x: elif pos_a.x > pos_b.x:
direction.x = -1 direction.x = -1
if pos_a.y < pos_b.y: if pos_a.y < pos_b.y:
direction.y = 1 direction.y = 1
elif pos_a.y > pos_b.y: elif pos_a.y > pos_b.y:
direction.y = -1 direction.y = -1
return direction return direction
# SECTION: game tick # SECTION: game tick
func tick_handle_temperature(cell_temperature: int): func tick_handle_temperature(cell_temperature: int):
if cell_temperature == 0: if cell_temperature == 0:
temperature_timer = 0 temperature_timer = 0
elif temperature_timer > temperature_endure: elif temperature_timer > temperature_endure:
temperature_timer += cell_temperature temperature_timer += cell_temperature
health -= temperature_damage health -= temperature_damage
func tick_handle_food(): func tick_handle_food():
if food <= 0: if food <= 0:
health -= food_damage health -= food_damage
func game_tick() -> void: func game_tick() -> void:
behavior_tree.game_tick() behavior_tree.game_tick()
var player_positon_array: Array[Vector2i] = game_manager.world.tilemap_player.get_cells_by_type(tilemap_types.PLAYER) var player_positon_array: Array[Vector2i] = game_manager.world.tilemap_player.get_cells_by_type(tilemap_types.PLAYER)
if len(player_positon_array) > 0: if len(player_positon_array) > 0:
var player_positon: Vector2i = player_positon_array[0] var player_positon: Vector2i = player_positon_array[0]
var cell_temperature: int = game_manager.world.tilemap_temperature.get_custom_data(player_positon, "temperature", 0) as int var cell_temperature: int = game_manager.world.tilemap_temperature.get_custom_data(player_positon, "temperature", 0) as int
tick_handle_temperature(cell_temperature) tick_handle_temperature(cell_temperature)
else: else:
push_error("No player found on tilemap") push_error("No player found on tilemap")
tick_handle_food() tick_handle_food()
if health < 0: if health < 0:
game_manager.player_health_depleted() game_manager.player_health_depleted()
update_board() update_board()

View File

@ -8,24 +8,24 @@ var behavior_tree: Task = null
func _ready() -> void: func _ready() -> void:
if get_child_count() == 0 or get_child_count() > 1: if get_child_count() == 0 or get_child_count() > 1:
push_error("This controller needs exactly one Task child, got " + str(get_child_count())) push_error("This controller needs exactly one Task child, got " + str(get_child_count()))
var child: Node = get_child(0) var child: Node = get_child(0)
if not (child is Task): if not (child is Task):
push_error("Child is not a task: " + child.name) push_error("Child is not a task: " + child.name)
behavior_tree = child as Task behavior_tree = child as Task
func populate_blackboard(): func populate_blackboard():
blackboard["world"] = game_manager.world blackboard["world"] = game_manager.world
blackboard["player"] = game_manager.player blackboard["player"] = game_manager.player
blackboard["camera"] = game_manager.camera blackboard["camera"] = game_manager.camera
func game_tick() -> void: func game_tick() -> void:
print("game_tick:") print("game_tick:")
populate_blackboard() populate_blackboard()
behavior_tree.internal_run(blackboard) behavior_tree.internal_run(blackboard)
print(" ==> [active state=", blackboard["current_task"], "] [status=", behavior_tree.status, "]") print(" ==> [active state=", blackboard["current_task"], "] [status=", behavior_tree.status, "]")

View File

@ -7,51 +7,51 @@ var tilemap_types: TileMapTileTypes = TileMapTileTypes.new()
func _ready() -> void: func _ready() -> void:
for c in get_children(): for c in get_children():
if not c is Task: if not c is Task:
push_error("Child is not a task: " + c.name + " in " + name) push_error("Child is not a task: " + c.name + " in " + name)
return return
func internal_run(p_blackboard: Dictionary) -> void: func internal_run(p_blackboard: Dictionary) -> void:
p_blackboard["current_task"] = self p_blackboard["current_task"] = self
if status == RUNNING: if status == RUNNING:
var running_child: Task = find_running_child() var running_child: Task = find_running_child()
if running_child != null: if running_child != null:
running_child.internal_run(p_blackboard) running_child.internal_run(p_blackboard)
status = running_child.status status = running_child.status
return return
else: else:
run(p_blackboard) run(p_blackboard)
else: else:
run(p_blackboard) run(p_blackboard)
print(" - ", name, " ", status)
func find_running_child() -> Task: func find_running_child() -> Task:
for c in get_children(): for c in get_children():
if c.status == RUNNING: if c.status == RUNNING:
return c return c
return null return null
func run_child(p_blackboard: Dictionary, p_child: Task) -> void: func run_child(p_blackboard: Dictionary, p_child: Task) -> void:
p_child.internal_run(p_blackboard) p_child.internal_run(p_blackboard)
if p_child.status != RUNNING: if p_child.status != RUNNING:
status = RUNNING status = RUNNING
func run(p_blackboard: Dictionary) -> void: func run(p_blackboard: Dictionary) -> void:
pass pass
func cancel(p_blackboard: Dictionary): func cancel(p_blackboard: Dictionary):
pass pass
func get_first_child() -> Task: func get_first_child() -> Task:
if get_child_count() == 0: if get_child_count() == 0:
push_error("Task does not have any children: " + name) push_error("Task does not have any children: " + name)
return null return null
return get_children()[0] as Task return get_children()[0] as Task

View File

@ -2,10 +2,10 @@ class_name TaskSelector
extends Task extends Task
func run(blackboard: Dictionary) -> void: func run(blackboard: Dictionary) -> void:
for c in self.get_children(): for c in self.get_children():
run_child(blackboard, c) run_child(blackboard, c)
if c.status != FAILURE: if c.status != FAILURE:
status = c.status status = c.status
return return
status = FAILURE status = FAILURE

View File

@ -6,76 +6,86 @@ var sid: int = 0
func setup() -> void: func setup() -> void:
pass pass
func get_cells_by_type(atlas_coords: Vector2i) -> Array[Vector2i]: func get_cells_by_type(atlas_coords: Vector2i) -> Array[Vector2i]:
return tilemap.get_used_cells_by_id(sid, atlas_coords) return tilemap.get_used_cells_by_id(sid, atlas_coords)
func set_cell_custom_data(position: Vector2i, key: String, value: Variant) -> void:
var tile_data: TileData = tilemap.get_cell_tile_data(position)
if tile_data:
tile_data.set_custom_data(key, value)
func get_cell_custom_data(position: Vector2i, key: String, default_value: Variant) -> Variant:
var tile_data: TileData = tilemap.get_cell_tile_data(position)
if tile_data:
return tile_data.get_custom_data(key)
return default_value
func get_cells_by_custom_data(field_name: String, custom_data: Variant) -> Array[Vector2i]: func get_cells_by_custom_data(field_name: String, custom_data: Variant) -> Array[Vector2i]:
var tiles_with_custom_data: Array = [] var tiles_with_custom_data: Array = []
for coords in tilemap.get_used_cells(): for coords in tilemap.get_used_cells():
var tile_data: TileData = tilemap.get_cell_tile_data(coords) var tile_data: TileData = tilemap.get_cell_tile_data(coords)
if tile_data.get_custom_data(field_name) == custom_data: if tile_data.get_custom_data(field_name) == custom_data:
tiles_with_custom_data.append(coords) tiles_with_custom_data.append(coords)
return tiles_with_custom_data return tiles_with_custom_data
func get_custom_data(coords: Vector2i, field_name: String, default_value: Variant) -> Variant: func get_custom_data(coords: Vector2i, field_name: String, default_value: Variant) -> Variant:
var tile_data: TileData = tilemap.get_cell_tile_data(coords) var tile_data: TileData = tilemap.get_cell_tile_data(coords)
if not tile_data: if not tile_data:
return default_value return default_value
return tile_data.get_custom_data(field_name) return tile_data.get_custom_data(field_name)
func get_cells(positions: Array[Vector2i]) -> Array[TileData]: func get_cells(positions: Array[Vector2i]) -> Array[TileData]:
var tiles: Array = [] var tiles: Array = []
for coords in positions: for coords in positions:
tiles.append(tilemap.get_cell_tile_data(coords)) tiles.append(tilemap.get_cell_tile_data(coords))
return tiles return tiles
func get_cell(position: Vector2i) -> TileData: func get_cell(position: Vector2i) -> TileData:
return tilemap.get_cell_tile_data(position) return tilemap.get_cell_tile_data(position)
func set_cell(position: Vector2i, atlas_coords: Vector2i) -> void: func set_cell(position: Vector2i, atlas_coords: Vector2i) -> void:
tilemap.set_cell(position, sid, atlas_coords) tilemap.set_cell(position, sid, atlas_coords)
func clear_cell(position: Vector2i) -> void: func clear_cell(position: Vector2i) -> void:
tilemap.set_cell(position, -1) tilemap.set_cell(position, -1)
func clear_cells() -> void: func clear_cells() -> void:
for coords in tilemap.get_used_cells(): for coords in tilemap.get_used_cells():
tilemap.set_cell(coords, -1) tilemap.set_cell(coords, -1)
func local_to_cell(global_position: Vector2) -> Vector2i: func local_to_cell(global_position: Vector2) -> Vector2i:
return tilemap.local_to_map(global_position) return tilemap.local_to_map(global_position)
func cell_to_local(cell_position: Vector2i) -> Vector2: func cell_to_local(cell_position: Vector2i) -> Vector2:
return tilemap.map_to_local(cell_position) return tilemap.map_to_local(cell_position)
func fill_area(start: Vector2i, end: Vector2i, atlas_coords: Vector2i) -> void: func fill_area(start: Vector2i, end: Vector2i, atlas_coords: Vector2i) -> void:
for x in range(start.x, end.x + 1): for x in range(start.x, end.x + 1):
for y in range(start.y, end.y + 1): for y in range(start.y, end.y + 1):
tilemap.set_cell(Vector2i(x, y), sid, atlas_coords) tilemap.set_cell(Vector2i(x, y), sid, atlas_coords)
func fill_circle(center: Vector2i, radius: int, atlas_coords: Vector2i) -> void: func fill_circle(center: Vector2i, radius: int, atlas_coords: Vector2i) -> void:
for x in range(center.x - radius, center.x + radius + 1): for x in range(center.x - radius, center.x + radius + 1):
for y in range(center.y - radius, center.y + radius + 1): for y in range(center.y - radius, center.y + radius + 1):
if center.distance_to(Vector2i(x, y)) <= radius: if center.distance_to(Vector2i(x, y)) <= radius:
tilemap.set_cell(Vector2i(x, y), sid, atlas_coords) tilemap.set_cell(Vector2i(x, y), sid, atlas_coords)
func fill_ellipse(center: Vector2i, radius_x: int, radius_y: int, atlas_coords: Vector2i) -> void: func fill_ellipse(center: Vector2i, radius_x: int, radius_y: int, atlas_coords: Vector2i) -> void:
for x in range(center.x - radius_x, center.x + radius_x + 1): for x in range(center.x - radius_x, center.x + radius_x + 1):
for y in range(center.y - radius_y, center.y + radius_y + 1): for y in range(center.y - radius_y, center.y + radius_y + 1):
if (pow(x - center.x, 2) / pow(radius_x, 2) + pow(y - center.y, 2) / pow(radius_y, 2)) <= 1: if (pow(x - center.x, 2) / pow(radius_x, 2) + pow(y - center.y, 2) / pow(radius_y, 2)) <= 1:
tilemap.set_cell(Vector2i(x, y), sid, atlas_coords) tilemap.set_cell(Vector2i(x, y), sid, atlas_coords)

View File

@ -2,7 +2,9 @@ class_name TileMapTileTypes
# global values # global values
const EMPTY: Vector2i = Vector2i(-1, -1) const EMPTY: Vector2i = Vector2i(-1, -1)
#
#Items
const ITEM_STICK: String = "Stick"
# ground, sid = 0 # ground, sid = 0
const GROUND_GRASS: Vector2i = Vector2i(0, 0) const GROUND_GRASS: Vector2i = Vector2i(0, 0)
const GROUND_WATER_SHALLOW: Vector2i = Vector2i(1, 0) const GROUND_WATER_SHALLOW: Vector2i = Vector2i(1, 0)
@ -15,7 +17,15 @@ const OBJECT_NI_RANDOM_1: Vector2i = Vector2i(0, 0) # testing only, to be remove
const OBJECT_NI_RANDOM_2: Vector2i = Vector2i(1, 0) # testing only, to be removed const OBJECT_NI_RANDOM_2: Vector2i = Vector2i(1, 0) # testing only, to be removed
const OBJECT_NI_ROCK_1: Vector2i = Vector2i(2, 0) const OBJECT_NI_ROCK_1: Vector2i = Vector2i(2, 0)
# I = interactive # I = interactive
# const OBJECT_I_TREE_1: Vector2i = Vector2i(0, 1)
const OBJECT_I_CHEST_1: Vector2i = Vector2i(0, 2)
const OBJECT_I_BERRY_1: Vector2i = Vector2i(0, 3)
const OBJECT_I_CAMPFIRE_1: Vector2i = Vector2i(0, 4)
const OBJECT_I_BOATPART_1: Vector2i = Vector2i(0, 5)
const OBJECT_I_BOATPART_2: Vector2i = Vector2i(0, 6)
const OBJECT_I_BOATPART_3: Vector2i = Vector2i(0, 7)
#const OBJECT_I_BOATPART_BUILDING_PLACE: Vector2i = Vector2i(0, 8)
# temperature, sid = 2 # temperature, sid = 2
const TEMPERATURE_NORMAL: Vector2i = Vector2i(-1, -1) const TEMPERATURE_NORMAL: Vector2i = Vector2i(-1, -1)
const TEMPERATURE_COLD_1: Vector2i = Vector2i(0, 0) const TEMPERATURE_COLD_1: Vector2i = Vector2i(0, 0)

View File

@ -8,6 +8,7 @@ var tilemap_player: TileMapLayerAccess = TileMapLayerAccess.new()
var tilemap_temperature: TileMapLayerAccess = TileMapLayerAccess.new() var tilemap_temperature: TileMapLayerAccess = TileMapLayerAccess.new()
# #
var tilemap_types: TileMapTileTypes = TileMapTileTypes.new() var tilemap_types: TileMapTileTypes = TileMapTileTypes.new()
var interactive_tile_items: Dictionary = {}
func _ready() -> void: func _ready() -> void:
@ -27,6 +28,7 @@ func _ready() -> void:
tilemap_interactive.setup() tilemap_interactive.setup()
tilemap_player.setup() tilemap_player.setup()
tilemap_temperature.setup() tilemap_temperature.setup()
print_tree_positions()
# example usage # example usage
@ -37,13 +39,17 @@ func _ready() -> void:
# tilemap_ground.set_cell(Vector2i(0, 0), tilemap_types.GROUND_GRASS) # tilemap_ground.set_cell(Vector2i(0, 0), tilemap_types.GROUND_GRASS)
# print(tilemap_ground.local_to_cell(get_local_mouse_position())) # print(tilemap_ground.local_to_cell(get_local_mouse_position()))
func local_mouse_position() -> Vector2: func print_tree_positions() -> void:
return get_local_mouse_position() var tree_coords = tilemap_types.OBJECT_I_TREE_1 # Die Atlas-Koordinaten des Baums
var tree_positions = tilemap_interactive.get_cells_by_type(tree_coords)
if tree_positions.size() == 0:
print("Keine Bäume gefunden.")
return
func tilemap_mouse_position() -> Vector2i: print("Gefundene Bäume:")
return tilemap_ground.local_to_cell(get_local_mouse_position()) for position in tree_positions:
print("- Baum bei:", position)
func is_walkable(position: Vector2i) -> bool: func is_walkable(position: Vector2i) -> bool:
var ground_tile_walkable: bool = tilemap_ground.get_custom_data(position, "walkable", false) var ground_tile_walkable: bool = tilemap_ground.get_custom_data(position, "walkable", false)