joar
parent
facdb2487a
commit
d81f9cace8
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
|
@ -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)
|
||||
]
|
||||
}
|
||||
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]
|
||||
|
||||
|
|
|
@ -8,28 +8,27 @@ extends Node
|
|||
|
||||
|
||||
func _ready() -> void:
|
||||
player.game_manager = self
|
||||
game_ticker.start()
|
||||
player.game_manager = self
|
||||
|
||||
|
||||
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"):
|
||||
camera.print_config()
|
||||
if Input.is_action_just_pressed("force_game_tick"):
|
||||
player.game_tick()
|
||||
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"):
|
||||
camera.print_config()
|
||||
if Input.is_action_just_pressed("force_game_tick"):
|
||||
player.game_tick()
|
||||
|
||||
|
||||
func player_health_depleted():
|
||||
# TODO
|
||||
pass
|
||||
# TODO
|
||||
pass
|
||||
|
||||
|
||||
func _on_game_tick_timeout() -> void:
|
||||
var timer_on_game_tick_timeout: PerformanceTimer = PerformanceTimer.new()
|
||||
timer_on_game_tick_timeout.display_name = "_on_game_tick_timeout"
|
||||
player.game_tick()
|
||||
timer_on_game_tick_timeout.stop()
|
||||
var timer_on_game_tick_timeout: PerformanceTimer = PerformanceTimer.new()
|
||||
timer_on_game_tick_timeout.display_name = "_on_game_tick_timeout"
|
||||
player.game_tick()
|
||||
timer_on_game_tick_timeout.stop()
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
class_name PlayerManager
|
||||
extends Node
|
||||
|
||||
@onready var inventory_label = $CanvasLayer/VBoxContainer/InventoryLabel
|
||||
@export var food_damage: int = 1
|
||||
@export var temperature_damage: int = 1
|
||||
@export var temperature_endure: int = 50
|
||||
|
@ -21,108 +22,175 @@ var inventory_slot: Vector2i = tilemap_types.EMPTY
|
|||
|
||||
|
||||
func _ready() -> void:
|
||||
call_deferred("defer_ready")
|
||||
call_deferred("defer_ready")
|
||||
|
||||
|
||||
func defer_ready() -> void:
|
||||
behavior_tree.game_manager = game_manager
|
||||
update_board()
|
||||
|
||||
behavior_tree.game_manager = game_manager
|
||||
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_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_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
|
||||
|
||||
func update_board() -> void:
|
||||
game_manager.world.tilemap_player.clear_cells()
|
||||
game_manager.world.tilemap_player.set_cell(board_position, tilemap_types.PLAYER)
|
||||
game_manager.world.tilemap_player.clear_cells()
|
||||
game_manager.world.tilemap_player.set_cell(board_position, tilemap_types.PLAYER)
|
||||
|
||||
|
||||
# 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)
|
||||
|
||||
if inventory_slot != tilemap_types.EMPTY:
|
||||
# set the type of the item on the tilemap to the one in the inventory, switching them
|
||||
game_manager.world.tilemap_interactive.set_cell(tilemap_pos, inventory_slot)
|
||||
|
||||
inventory_slot = pick_up_item_type
|
||||
# Check if the inventory slot is empty
|
||||
if inventory_slot == tilemap_types.EMPTY:
|
||||
inventory_slot = pick_up_item_type
|
||||
game_manager.world.tilemap_interactive.clear_cell(tilemap_pos) # Clear the tilemap
|
||||
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
|
||||
|
||||
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:
|
||||
if len(path) > 1:
|
||||
var next_position: Vector2i = path[1]
|
||||
var direction: Vector2i = find_direction(board_position, next_position)
|
||||
move_player(direction)
|
||||
if len(path) > 1:
|
||||
var next_position: Vector2i = path[1]
|
||||
var direction: Vector2i = find_direction(board_position, next_position)
|
||||
move_player(direction)
|
||||
|
||||
|
||||
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
|
||||
print("Moved to:", board_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:
|
||||
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 tick_handle_temperature(cell_temperature: int):
|
||||
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:
|
||||
health -= food_damage
|
||||
if food <= 0:
|
||||
health -= food_damage
|
||||
|
||||
|
||||
|
||||
|
||||
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)
|
||||
if len(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
|
||||
tick_handle_temperature(cell_temperature)
|
||||
else:
|
||||
push_error("No player found on tilemap")
|
||||
var player_positon_array: Array[Vector2i] = game_manager.world.tilemap_player.get_cells_by_type(tilemap_types.PLAYER)
|
||||
if len(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
|
||||
tick_handle_temperature(cell_temperature)
|
||||
else:
|
||||
push_error("No player found on tilemap")
|
||||
|
||||
tick_handle_food()
|
||||
tick_handle_food()
|
||||
|
||||
if health < 0:
|
||||
game_manager.player_health_depleted()
|
||||
if health < 0:
|
||||
game_manager.player_health_depleted()
|
||||
|
||||
update_board()
|
||||
update_board()
|
||||
|
|
|
@ -8,24 +8,24 @@ var behavior_tree: Task = null
|
|||
|
||||
|
||||
func _ready() -> void:
|
||||
if get_child_count() == 0 or get_child_count() > 1:
|
||||
push_error("This controller needs exactly one Task child, got " + str(get_child_count()))
|
||||
if get_child_count() == 0 or get_child_count() > 1:
|
||||
push_error("This controller needs exactly one Task child, got " + str(get_child_count()))
|
||||
|
||||
var child: Node = get_child(0)
|
||||
if not (child is Task):
|
||||
push_error("Child is not a task: " + child.name)
|
||||
var child: Node = get_child(0)
|
||||
if not (child is Task):
|
||||
push_error("Child is not a task: " + child.name)
|
||||
|
||||
behavior_tree = child as Task
|
||||
behavior_tree = child as Task
|
||||
|
||||
|
||||
func populate_blackboard():
|
||||
blackboard["world"] = game_manager.world
|
||||
blackboard["player"] = game_manager.player
|
||||
blackboard["camera"] = game_manager.camera
|
||||
blackboard["world"] = game_manager.world
|
||||
blackboard["player"] = game_manager.player
|
||||
blackboard["camera"] = game_manager.camera
|
||||
|
||||
|
||||
func game_tick() -> void:
|
||||
print("game_tick:")
|
||||
populate_blackboard()
|
||||
behavior_tree.internal_run(blackboard)
|
||||
print(" ==> [active state=", blackboard["current_task"], "] [status=", behavior_tree.status, "]")
|
||||
print("game_tick:")
|
||||
populate_blackboard()
|
||||
behavior_tree.internal_run(blackboard)
|
||||
print(" ==> [active state=", blackboard["current_task"], "] [status=", behavior_tree.status, "]")
|
||||
|
|
|
@ -7,51 +7,51 @@ var tilemap_types: TileMapTileTypes = TileMapTileTypes.new()
|
|||
|
||||
|
||||
func _ready() -> void:
|
||||
for c in get_children():
|
||||
if not c is Task:
|
||||
push_error("Child is not a task: " + c.name + " in " + name)
|
||||
return
|
||||
for c in get_children():
|
||||
if not c is Task:
|
||||
push_error("Child is not a task: " + c.name + " in " + name)
|
||||
return
|
||||
|
||||
|
||||
func internal_run(p_blackboard: Dictionary) -> void:
|
||||
p_blackboard["current_task"] = self
|
||||
p_blackboard["current_task"] = self
|
||||
|
||||
if status == RUNNING:
|
||||
var running_child: Task = find_running_child()
|
||||
if running_child != null:
|
||||
running_child.internal_run(p_blackboard)
|
||||
status = running_child.status
|
||||
return
|
||||
else:
|
||||
run(p_blackboard)
|
||||
else:
|
||||
run(p_blackboard)
|
||||
|
||||
if status == RUNNING:
|
||||
var running_child: Task = find_running_child()
|
||||
if running_child != null:
|
||||
running_child.internal_run(p_blackboard)
|
||||
status = running_child.status
|
||||
return
|
||||
else:
|
||||
run(p_blackboard)
|
||||
else:
|
||||
run(p_blackboard)
|
||||
print(" - ", name, " ", status)
|
||||
|
||||
|
||||
func find_running_child() -> Task:
|
||||
for c in get_children():
|
||||
if c.status == RUNNING:
|
||||
return c
|
||||
return null
|
||||
for c in get_children():
|
||||
if c.status == RUNNING:
|
||||
return c
|
||||
return null
|
||||
|
||||
|
||||
func run_child(p_blackboard: Dictionary, p_child: Task) -> void:
|
||||
p_child.internal_run(p_blackboard)
|
||||
if p_child.status != RUNNING:
|
||||
status = RUNNING
|
||||
p_child.internal_run(p_blackboard)
|
||||
if p_child.status != RUNNING:
|
||||
status = RUNNING
|
||||
|
||||
|
||||
func run(p_blackboard: Dictionary) -> void:
|
||||
pass
|
||||
pass
|
||||
|
||||
|
||||
func cancel(p_blackboard: Dictionary):
|
||||
pass
|
||||
pass
|
||||
|
||||
|
||||
func get_first_child() -> Task:
|
||||
if get_child_count() == 0:
|
||||
push_error("Task does not have any children: " + name)
|
||||
return null
|
||||
return get_children()[0] as Task
|
||||
if get_child_count() == 0:
|
||||
push_error("Task does not have any children: " + name)
|
||||
return null
|
||||
return get_children()[0] as Task
|
||||
|
|
|
@ -2,10 +2,10 @@ class_name TaskSelector
|
|||
extends Task
|
||||
|
||||
func run(blackboard: Dictionary) -> void:
|
||||
for c in self.get_children():
|
||||
run_child(blackboard, c)
|
||||
if c.status != FAILURE:
|
||||
status = c.status
|
||||
return
|
||||
status = FAILURE
|
||||
for c in self.get_children():
|
||||
run_child(blackboard, c)
|
||||
if c.status != FAILURE:
|
||||
status = c.status
|
||||
return
|
||||
status = FAILURE
|
||||
|
||||
|
|
|
@ -6,76 +6,86 @@ var sid: int = 0
|
|||
|
||||
|
||||
func setup() -> void:
|
||||
pass
|
||||
pass
|
||||
|
||||
|
||||
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]:
|
||||
var tiles_with_custom_data: Array = []
|
||||
for coords in tilemap.get_used_cells():
|
||||
var tile_data: TileData = tilemap.get_cell_tile_data(coords)
|
||||
if tile_data.get_custom_data(field_name) == custom_data:
|
||||
tiles_with_custom_data.append(coords)
|
||||
return tiles_with_custom_data
|
||||
var tiles_with_custom_data: Array = []
|
||||
for coords in tilemap.get_used_cells():
|
||||
var tile_data: TileData = tilemap.get_cell_tile_data(coords)
|
||||
if tile_data.get_custom_data(field_name) == custom_data:
|
||||
tiles_with_custom_data.append(coords)
|
||||
return tiles_with_custom_data
|
||||
|
||||
|
||||
func get_custom_data(coords: Vector2i, field_name: String, default_value: Variant) -> Variant:
|
||||
var tile_data: TileData = tilemap.get_cell_tile_data(coords)
|
||||
if not tile_data:
|
||||
return default_value
|
||||
return tile_data.get_custom_data(field_name)
|
||||
var tile_data: TileData = tilemap.get_cell_tile_data(coords)
|
||||
if not tile_data:
|
||||
return default_value
|
||||
return tile_data.get_custom_data(field_name)
|
||||
|
||||
|
||||
func get_cells(positions: Array[Vector2i]) -> Array[TileData]:
|
||||
var tiles: Array = []
|
||||
for coords in positions:
|
||||
tiles.append(tilemap.get_cell_tile_data(coords))
|
||||
return tiles
|
||||
var tiles: Array = []
|
||||
for coords in positions:
|
||||
tiles.append(tilemap.get_cell_tile_data(coords))
|
||||
return tiles
|
||||
|
||||
|
||||
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:
|
||||
tilemap.set_cell(position, sid, atlas_coords)
|
||||
tilemap.set_cell(position, sid, atlas_coords)
|
||||
|
||||
|
||||
func clear_cell(position: Vector2i) -> void:
|
||||
tilemap.set_cell(position, -1)
|
||||
tilemap.set_cell(position, -1)
|
||||
|
||||
|
||||
func clear_cells() -> void:
|
||||
for coords in tilemap.get_used_cells():
|
||||
tilemap.set_cell(coords, -1)
|
||||
for coords in tilemap.get_used_cells():
|
||||
tilemap.set_cell(coords, -1)
|
||||
|
||||
|
||||
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:
|
||||
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:
|
||||
for x in range(start.x, end.x + 1):
|
||||
for y in range(start.y, end.y + 1):
|
||||
tilemap.set_cell(Vector2i(x, y), sid, atlas_coords)
|
||||
for x in range(start.x, end.x + 1):
|
||||
for y in range(start.y, end.y + 1):
|
||||
tilemap.set_cell(Vector2i(x, y), sid, atlas_coords)
|
||||
|
||||
|
||||
func fill_circle(center: Vector2i, radius: int, atlas_coords: Vector2i) -> void:
|
||||
for x in range(center.x - radius, center.x + radius + 1):
|
||||
for y in range(center.y - radius, center.y + radius + 1):
|
||||
if center.distance_to(Vector2i(x, y)) <= radius:
|
||||
tilemap.set_cell(Vector2i(x, y), sid, atlas_coords)
|
||||
for x in range(center.x - radius, center.x + radius + 1):
|
||||
for y in range(center.y - radius, center.y + radius + 1):
|
||||
if center.distance_to(Vector2i(x, y)) <= radius:
|
||||
tilemap.set_cell(Vector2i(x, y), sid, atlas_coords)
|
||||
|
||||
|
||||
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 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:
|
||||
tilemap.set_cell(Vector2i(x, y), sid, atlas_coords)
|
||||
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):
|
||||
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)
|
||||
|
|
|
@ -2,7 +2,9 @@ class_name TileMapTileTypes
|
|||
|
||||
# global values
|
||||
const EMPTY: Vector2i = Vector2i(-1, -1)
|
||||
#
|
||||
|
||||
#Items
|
||||
const ITEM_STICK: String = "Stick"
|
||||
# ground, sid = 0
|
||||
const GROUND_GRASS: Vector2i = Vector2i(0, 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_ROCK_1: Vector2i = Vector2i(2, 0)
|
||||
# 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
|
||||
const TEMPERATURE_NORMAL: Vector2i = Vector2i(-1, -1)
|
||||
const TEMPERATURE_COLD_1: Vector2i = Vector2i(0, 0)
|
||||
|
|
|
@ -8,6 +8,7 @@ var tilemap_player: TileMapLayerAccess = TileMapLayerAccess.new()
|
|||
var tilemap_temperature: TileMapLayerAccess = TileMapLayerAccess.new()
|
||||
#
|
||||
var tilemap_types: TileMapTileTypes = TileMapTileTypes.new()
|
||||
var interactive_tile_items: Dictionary = {}
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
|
@ -27,6 +28,7 @@ func _ready() -> void:
|
|||
tilemap_interactive.setup()
|
||||
tilemap_player.setup()
|
||||
tilemap_temperature.setup()
|
||||
print_tree_positions()
|
||||
|
||||
|
||||
# example usage
|
||||
|
@ -37,13 +39,17 @@ func _ready() -> void:
|
|||
# tilemap_ground.set_cell(Vector2i(0, 0), tilemap_types.GROUND_GRASS)
|
||||
# print(tilemap_ground.local_to_cell(get_local_mouse_position()))
|
||||
|
||||
func local_mouse_position() -> Vector2:
|
||||
return get_local_mouse_position()
|
||||
func print_tree_positions() -> void:
|
||||
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:
|
||||
return tilemap_ground.local_to_cell(get_local_mouse_position())
|
||||
|
||||
print("Gefundene Bäume:")
|
||||
for position in tree_positions:
|
||||
print("- Baum bei:", position)
|
||||
|
||||
func is_walkable(position: Vector2i) -> bool:
|
||||
var ground_tile_walkable: bool = tilemap_ground.get_custom_data(position, "walkable", false)
|
||||
|
|
Loading…
Reference in New Issue