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

@ -9,7 +9,6 @@ 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:

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
@ -29,11 +30,25 @@ func defer_ready() -> void:
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
@ -52,10 +67,15 @@ func pick_up_item(tilemap_pos: Vector2i) -> void:
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:
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) game_manager.world.tilemap_interactive.set_cell(tilemap_pos, inventory_slot)
inventory_slot = pick_up_item_type inventory_slot = pick_up_item_type
@ -63,6 +83,7 @@ func pick_up_item(tilemap_pos: Vector2i) -> void:
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:
@ -75,9 +96,54 @@ 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
print("Moved to:", board_position)
update_board()
else: else:
push_warning("Player trying to move to non-walkable position, prevented ", new_position) 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)
@ -109,6 +175,8 @@ func tick_handle_food():
health -= food_damage health -= food_damage
func game_tick() -> void: func game_tick() -> void:
behavior_tree.game_tick() behavior_tree.game_tick()

View File

@ -26,7 +26,7 @@ func internal_run(p_blackboard: Dictionary) -> void:
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:

View File

@ -12,6 +12,16 @@ func setup() -> void:
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 = []

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)