Added identification of current island

master
Martin Felis 2021-07-10 14:57:18 +02:00
parent a5035f81fa
commit 7aa4b2d4b9
3 changed files with 43 additions and 12 deletions

View File

@ -29,6 +29,7 @@ script = ExtResource( 1 )
script = ExtResource( 2 )
[node name="Islands" type="Node2D" parent="World"]
z_index = -1
[node name="GridHighlight" type="Node2D" parent="World"]
script = ExtResource( 8 )

View File

@ -7,6 +7,7 @@ var center_world_coord = Vector2.ZERO
var tile_local_coords = []
var rect_local = Rect2()
var radius_world = 0.0
var is_active = false
# Called when the node enters the scene tree for the first time.
func _ready():
@ -136,8 +137,8 @@ func _draw():
var transform = get_transform()
draw_set_transform(transform.origin + offset_world, transform.get_rotation(), transform.get_scale())
# draw_rect(rect_local, Color.red, false)
# draw_bsphere()
if is_active:
draw_rect(rect_local, Color.red, false)
var default_font = Control.new().get_font("font")
draw_string(default_font, Vector2(0, 0), name + str(" ") + str(offset_world))

View File

@ -55,6 +55,12 @@ func _process(_delta):
if len(player_navigation_path) > 0:
PlayerChar.target = player_navigation_path[0]
update_current_island()
if current_island:
PlayerBoat.visible = false
else:
PlayerBoat.visible = true
func draw_hex_path (path: Array, color: Color):
var path_len = len(path)
@ -67,9 +73,10 @@ func draw_hex_path (path: Array, color: Color):
draw_circle(cur_point, 5, color)
last_point = cur_point
func _draw():
draw_hex_path (player_navigation_path, "#f200f2")
draw_hex_path (hex_line_path, "#00f2f2")
draw_hex_path (player_navigation_path, "#f200f2")
#
@ -169,7 +176,26 @@ func populate_ocean_grid():
for island in Islands.get_children():
for tile in island.tiles.keys():
var grid_coords = Globals.WorldToHex(tile + island.offset_world)
Globals.OceanGrid.add_obstacles(grid_coords, 0)
Globals.OceanGrid.add_obstacles(grid_coords, 15)
func update_current_island():
var islands = Islands.get_children()
var last_current_island = current_island
current_island = null
for island in islands:
if island.get_tile_by_world_coord(PlayerChar.position) != null:
current_island = island
break
if last_current_island != current_island:
if last_current_island != null:
last_current_island.is_active = false
last_current_island.update()
if current_island != null:
current_island.is_active = true
current_island.update()
func update_player_navigation_target(target_world: Vector2):
@ -181,27 +207,30 @@ func update_player_navigation_target(target_world: Vector2):
if get_tile_type(target_world) != null:
var direct_path = Globals.WorldLineToHexTiles(target_world, start_world)
var last_removed = null
while len(direct_path) > 0 and get_tile_type(direct_path[0]) != null:
last_removed = direct_path[0]
direct_path.remove(0)
if len(direct_path) == 0:
print ("Could not find path!")
return
print ("Using ", direct_path[0], " instead of ", goal_coord, " as goal.")
goal_coord = Globals.WorldToHex(direct_path[0])
print ("Using ", Globals.WorldToHex(direct_path[0]), " instead of ", goal_coord, " as goal.")
goal_coord = Globals.WorldToHex(last_removed)
var path = Globals.OceanGrid.find_path(start_coord, goal_coord)
for target in path:
for target in path.slice(1,-1):
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:
PlayerChar.target = player_navigation_path[1]
if target_type == "Sand":
break
if len(player_navigation_path) > 0:
PlayerChar.target = player_navigation_path[0]
update()