Easier bording of boat, fixed island_1

master
Martin Felis 2021-07-18 22:28:18 +02:00
parent f93b1bf02a
commit d9a2d936ba
7 changed files with 56 additions and 41 deletions

View File

@ -6,27 +6,22 @@ const GRID_SIZE=float(64.0)
const GRID_COLOR="#000000" const GRID_COLOR="#000000"
const SHOVEL_DURATION=1 const SHOVEL_DURATION=1
onready var HexGrid = preload("res://addons/gdhexgrid/HexGrid.gd").new()
onready var HexCell = preload("res://addons/gdhexgrid/HexCell.gd").new()
onready var OceanNavGrid = preload("res://addons/gdhexgrid/HexGrid.gd").new()
onready var IslandNavGrid = preload("res://addons/gdhexgrid/HexGrid.gd").new()
var DebugLabel = null var DebugLabel = null
var HexGrid = null
var HexCell = null
var OceanNavGrid = null
var IslandNavGrid = null
var hex_size = 128 var hex_size = 128
var debug_nav = false var debug_nav = false
var draw_grid = false
# Called when the node enters the scene tree for the first time. # Called when the node enters the scene tree for the first time.
func _ready(): func _ready():
HexGrid = preload("res://addons/gdhexgrid/HexGrid.gd").new()
HexGrid.hex_scale = Vector2(hex_size, hex_size) HexGrid.hex_scale = Vector2(hex_size, hex_size)
OceanNavGrid = preload("res://addons/gdhexgrid/HexGrid.gd").new()
OceanNavGrid.hex_scale = Vector2(hex_size, hex_size) OceanNavGrid.hex_scale = Vector2(hex_size, hex_size)
IslandNavGrid = preload("res://addons/gdhexgrid/HexGrid.gd").new()
IslandNavGrid.hex_scale = Vector2(hex_size, hex_size) IslandNavGrid.hex_scale = Vector2(hex_size, hex_size)
HexCell = preload("res://addons/gdhexgrid/HexCell.gd").new()
HexTileDrawer.hex_scale = Vector2(hex_size, hex_size) HexTileDrawer.hex_scale = Vector2(hex_size, hex_size)

View File

@ -225,7 +225,7 @@ permissions/write_user_dictionary=false
[preset.2] [preset.2]
name="Linux/X11" name="Pirate Treasure Hunt"
platform="Linux/X11" platform="Linux/X11"
runnable=true runnable=true
custom_features="" custom_features=""

View File

@ -1 +1 @@
{"(-480, -55.425629)":"Sand","(-480, 55.425613)":"Sand","(-480, 166.276855)":"Sand","(-480, 498.830627)":"Sand","(-384, -110.851242)":"Sand","(-384, 0)":"Grass","(-384, 110.85125)":"Grass","(-384, 221.702499)":"Sand","(-384, 332.553741)":"Sand","(-384, 443.404999)":"Sand","(-384, 554.256226)":"Sand","(-288, -55.425629)":"Sand","(-288, 55.425621)":"Grass","(-288, 166.276871)":"Grass","(-288, 277.128113)":"Grass","(-288, 387.97937)":"Grass","(-288, 498.830627)":"Grass","(-288, 609.681885)":"Sand","(-192, -110.85125)":"Sand","(-192, 0)":"Grass","(-192, 110.85125)":"Grass","(-192, 221.702499)":"Grass","(-192, 332.553741)":"Grass","(-192, 443.404999)":"Grass","(-192, 554.256226)":"Sand","(-96, -55.425625)":"Sand","(-96, 55.425625)":"Grass","(-96, 166.276871)":"Grass","(-96, 277.128113)":"Grass","(-96, 387.97937)":"Grass","(-96, 498.830627)":"Sand","(0, 110.85125)":"Sand","(0, 221.702499)":"Grass","(0, 332.553741)":"Grass","(0, 443.404999)":"Sand","(96, 166.276871)":"Sand","(96, 277.128113)":"Grass","(96, 387.97937)":"Sand","(192, 110.85125)":"Sand","(192, 221.702484)":"Grass","(192, 332.553741)":"Sand","(288, 166.276871)":"Sand","(288, 277.128113)":"Grass","(288, 387.97937)":"Sand","(384, 110.851242)":"Sand","(384, 221.702499)":"Grass","(384, 332.553711)":"Sand","(480, -55.425613)":"Sand","(480, 55.425629)":"Sand","(480, 166.276886)":"Grass","(480, 277.128113)":"Grass","(480, 387.97937)":"Sand","(576, 0)":"Sand","(576, 110.851257)":"Sand","(576, 221.702484)":"Sand","(576, 332.553741)":"Sand"} {"(-480, -55.425629)":"Sand","(-480, 55.425613)":"Sand","(-480, 166.276855)":"Sand","(-480, 498.830627)":"Sand","(-384, -110.851242)":"Sand","(-384, 0)":"Grass","(-384, 110.85125)":"Grass","(-384, 221.702499)":"Sand","(-384, 332.553741)":"Sand","(-384, 443.404999)":"Sand","(-384, 554.256226)":"Sand","(-288, -55.425629)":"Sand","(-288, 55.425621)":"Grass","(-288, 166.276871)":"Grass","(-288, 277.128113)":"Grass","(-288, 387.97937)":"Grass","(-288, 498.830627)":"Grass","(-288, 609.681885)":"Sand","(-192, -110.85125)":"Sand","(-192, 0)":"Grass","(-192, 110.85125)":"Grass","(-192, 221.702499)":"Grass","(-192, 332.553741)":"Grass","(-192, 443.404999)":"Grass","(-192, 554.256226)":"Sand","(-96, -55.425625)":"Sand","(-96, 55.425625)":"Grass","(-96, 166.276871)":"Grass","(-96, 277.128113)":"Grass","(-96, 387.97937)":"Grass","(-96, 498.830627)":"Sand","(0, 0)":"Sand","(0, 110.85125)":"Sand","(0, 221.702499)":"Grass","(0, 332.553741)":"Grass","(0, 443.404999)":"Sand","(96, 166.276871)":"Sand","(96, 277.128113)":"Grass","(96, 387.97937)":"Sand","(192, 110.85125)":"Sand","(192, 221.702484)":"Grass","(192, 332.553741)":"Sand","(288, 166.276871)":"Sand","(288, 277.128113)":"Grass","(288, 387.97937)":"Sand","(384, 110.851242)":"Sand","(384, 221.702499)":"Grass","(384, 332.553711)":"Sand","(480, 55.425629)":"Sand","(480, 166.276886)":"Grass","(480, 277.128113)":"Grass","(480, 387.97937)":"Sand","(576, 0)":"Sand","(576, 110.851257)":"Sand","(576, 221.702484)":"Sand","(576, 332.553741)":"Sand"}

View File

@ -144,7 +144,7 @@ text = "Generate World"
visible = false visible = false
margin_left = 117.0 margin_left = 117.0
margin_right = 234.0 margin_right = 234.0
margin_bottom = 40.0 margin_bottom = 64.0
text = "Editor" text = "Editor"
[node name="Offset" type="Label" parent="World/UI/TopContainer"] [node name="Offset" type="Label" parent="World/UI/TopContainer"]
@ -187,34 +187,34 @@ __meta__ = {
[node name="HexCoord" type="Label" parent="World/UI/TopContainer"] [node name="HexCoord" type="Label" parent="World/UI/TopContainer"]
visible = false visible = false
margin_left = 238.0 margin_left = 117.0
margin_top = 13.0 margin_top = 25.0
margin_right = 312.0 margin_right = 191.0
margin_bottom = 27.0 margin_bottom = 39.0
text = " HexCoord: " text = " HexCoord: "
[node name="HexCoordValue" type="Label" parent="World/UI/TopContainer"] [node name="HexCoordValue" type="Label" parent="World/UI/TopContainer"]
visible = false visible = false
margin_left = 238.0 margin_left = 117.0
margin_top = 13.0 margin_top = 25.0
margin_right = 266.0 margin_right = 145.0
margin_bottom = 27.0 margin_bottom = 39.0
text = "(0,0)" text = "(0,0)"
[node name="WorldCoord" type="Label" parent="World/UI/TopContainer"] [node name="WorldCoord" type="Label" parent="World/UI/TopContainer"]
visible = false visible = false
margin_left = 238.0 margin_left = 117.0
margin_top = 13.0 margin_top = 25.0
margin_right = 321.0 margin_right = 200.0
margin_bottom = 27.0 margin_bottom = 39.0
text = "WorldCoord: " text = "WorldCoord: "
[node name="WorldCoordValue" type="Label" parent="World/UI/TopContainer"] [node name="WorldCoordValue" type="Label" parent="World/UI/TopContainer"]
visible = false visible = false
margin_left = 238.0 margin_left = 117.0
margin_top = 13.0 margin_top = 25.0
margin_right = 266.0 margin_right = 145.0
margin_bottom = 27.0 margin_bottom = 39.0
text = "(0,0)" text = "(0,0)"
[node name="TileType" type="Label" parent="World/UI/TopContainer"] [node name="TileType" type="Label" parent="World/UI/TopContainer"]

View File

@ -41,6 +41,9 @@ func _process(_delta):
func _draw(): func _draw():
if !Globals.draw_grid:
return
view_grid_corners = calc_grid_view_rect() view_grid_corners = calc_grid_view_rect()
last_grid_corners = view_grid_corners last_grid_corners = view_grid_corners

View File

@ -9,7 +9,6 @@ var radius_world = 0.0
var is_active = false var is_active = false
var landing_site_local_coord = null var landing_site_local_coord = null
var landing_site_world = null var landing_site_world = null
var ship_anchor_world = null
var obstacles_local_coords = {} var obstacles_local_coords = {}
var treasure_local_coords = null var treasure_local_coords = null
@ -176,9 +175,3 @@ func _draw():
if Globals.debug_nav and is_active: if Globals.debug_nav and is_active:
draw_rect(rect_local, Color.red, false) draw_rect(rect_local, Color.red, false)
draw_set_transform_matrix(transform)
for coord in obstacles_local_coords.keys():
draw_set_transform(coord + offset_world, 0, Vector2.ONE)
draw_polygon(HexTileDrawer.HexPoints, HexTileDrawer.create_color_array("#922"))

View File

@ -120,6 +120,17 @@ func _draw():
if player_path_plan_start != null and player_path_plan_end != null: if player_path_plan_start != null and player_path_plan_end != null:
draw_circle (player_path_plan_start, 12, "#2288f2") draw_circle (player_path_plan_start, 12, "#2288f2")
draw_circle (player_path_plan_end, 12, "#2288f2") draw_circle (player_path_plan_end, 12, "#2288f2")
var obstacles = []
if current_island != null:
obstacles = Globals.IslandNavGrid.get_obstacles()
else:
obstacles = Globals.OceanNavGrid.get_obstacles()
for coords in obstacles:
draw_set_transform(Globals.HexToWorld(coords), 0, Vector2.ONE)
draw_polygon(HexTileDrawer.HexPoints, HexTileDrawer.create_color_array("#929"))
# #
# World Modification/Query # World Modification/Query
@ -191,6 +202,7 @@ func place_treasure():
treasure_island.update() treasure_island.update()
func render_treasure_map(): func render_treasure_map():
IslandMapRenderer.render_target_update_mode = Viewport.UPDATE_ONCE IslandMapRenderer.render_target_update_mode = Viewport.UPDATE_ONCE
IslandMapRenderer.render_target_clear_mode = Viewport.CLEAR_MODE_ONLY_NEXT_FRAME IslandMapRenderer.render_target_clear_mode = Viewport.CLEAR_MODE_ONLY_NEXT_FRAME
@ -308,9 +320,15 @@ func populate_island_nav_grid():
if current_island == null: if current_island == null:
print ("Error: cannot populate island nav grid: no island") print ("Error: cannot populate island nav grid: no island")
return return
var landing_site_coords = Globals.WorldToHex(current_island.landing_site_world)
for tile in current_island.obstacles_local_coords.keys(): for tile in current_island.obstacles_local_coords.keys():
var grid_coords = Globals.WorldToHex(tile + current_island.offset_world) var grid_coords = Globals.WorldToHex(tile + current_island.offset_world)
# Allow navigation to the anchor tile
if (grid_coords - anchor_tile).length() < 0.1:
continue
Globals.IslandNavGrid.add_obstacles(grid_coords, 0) Globals.IslandNavGrid.add_obstacles(grid_coords, 0)
@ -343,6 +361,9 @@ func on_enter_island(island):
island.is_active = true island.is_active = true
populate_island_nav_grid() populate_island_nav_grid()
island.update() island.update()
if Globals.debug_nav:
update()
func on_leave_island(island): func on_leave_island(island):
@ -351,6 +372,9 @@ func on_leave_island(island):
island.is_active = false island.is_active = false
island.landing_site_local_coord = null island.landing_site_local_coord = null
island.update() island.update()
if Globals.debug_nav:
update()
func on_dig_stopped(): func on_dig_stopped():
@ -467,10 +491,10 @@ func update_player_navigation_target(target_world: Vector2):
if current_island == null or (len(player_navigation_path) == 0 and player_near_anchor): if current_island == null or (len(player_navigation_path) == 0 and player_near_anchor):
update_navigation_target_ocean(start_world, target_world) update_navigation_target_ocean(start_world, target_world)
var planning_duration_msec = OS.get_system_time_msecs() - start_timestamp var planning_duration_msec = OS.get_system_time_msecs() - start_timestamp
update()
if Globals.debug_nav:
update()
# #
# Input & Events # Input & Events