Navigation acceptable

master
Martin Felis 2021-07-09 22:19:23 +02:00
parent 2fd955c362
commit 1e85465873
1 changed files with 11 additions and 4 deletions

View File

@ -56,7 +56,6 @@ func _process(_delta):
if len(player_navigation_path) > 0: if len(player_navigation_path) > 0:
PlayerChar.target = player_navigation_path[0] PlayerChar.target = player_navigation_path[0]
pass
func get_tile_type(world_coord: Vector2): func get_tile_type(world_coord: Vector2):
@ -83,7 +82,7 @@ func populate_ocean_grid():
for island in Islands.get_children(): for island in Islands.get_children():
for tile in island.tiles.keys(): for tile in island.tiles.keys():
var grid_coords = Globals.WorldToHex(tile + island.offset_world) var grid_coords = Globals.WorldToHex(tile + island.offset_world)
Globals.OceanGrid.add_obstacles(grid_coords) Globals.OceanGrid.add_obstacles(grid_coords, 5)
func check_island_location_valid(new_island): func check_island_location_valid(new_island):
@ -100,6 +99,9 @@ func check_island_location_valid(new_island):
func generate(): func generate():
PlayerChar.transform.origin = Vector2.ZERO
PlayerChar.position = Vector2.ZERO
var rng = RandomNumberGenerator.new() var rng = RandomNumberGenerator.new()
rng.randomize() rng.randomize()
@ -144,8 +146,13 @@ func update_player_navigation_target(target_world: Vector2):
var path = Globals.OceanGrid.find_path(start_coord, goal_coord) var path = Globals.OceanGrid.find_path(start_coord, goal_coord)
player_navigation_path = [] player_navigation_path = []
for p in path: for target in path:
player_navigation_path.append(Globals.HexToWorld(p.axial_coords)) var target_world_coord = Globals.HexToWorld(target.axial_coords)
var target_type = get_tile_type(target_world_coord)
if target_type == "Sand":
break
player_navigation_path.append(target_world_coord)
if len(player_navigation_path) > 1: if len(player_navigation_path) > 1:
PlayerChar.target = player_navigation_path[1] PlayerChar.target = player_navigation_path[1]