From d9a2d936bafe7ef850489166f1d99df30aeb79a8 Mon Sep 17 00:00:00 2001 From: Martin Felis Date: Sun, 18 Jul 2021 22:28:18 +0200 Subject: [PATCH] Easier bording of boat, fixed island_1 --- Globals.gd | 17 +++++---------- export_presets.cfg | 2 +- islands/pirate_game_island_1.island | 2 +- scenes/Game.tscn | 34 ++++++++++++++--------------- scenes/Grid.gd | 3 +++ scenes/Island.gd | 7 ------ scenes/World.gd | 32 +++++++++++++++++++++++---- 7 files changed, 56 insertions(+), 41 deletions(-) diff --git a/Globals.gd b/Globals.gd index 0562347..2fca6cc 100644 --- a/Globals.gd +++ b/Globals.gd @@ -6,27 +6,22 @@ const GRID_SIZE=float(64.0) const GRID_COLOR="#000000" 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 HexGrid = null -var HexCell = null -var OceanNavGrid = null -var IslandNavGrid = null var hex_size = 128 var debug_nav = false +var draw_grid = false # Called when the node enters the scene tree for the first time. func _ready(): - HexGrid = preload("res://addons/gdhexgrid/HexGrid.gd").new() HexGrid.hex_scale = Vector2(hex_size, hex_size) - - OceanNavGrid = preload("res://addons/gdhexgrid/HexGrid.gd").new() OceanNavGrid.hex_scale = Vector2(hex_size, hex_size) - - IslandNavGrid = preload("res://addons/gdhexgrid/HexGrid.gd").new() IslandNavGrid.hex_scale = Vector2(hex_size, hex_size) - - HexCell = preload("res://addons/gdhexgrid/HexCell.gd").new() HexTileDrawer.hex_scale = Vector2(hex_size, hex_size) diff --git a/export_presets.cfg b/export_presets.cfg index c8b4417..551c491 100644 --- a/export_presets.cfg +++ b/export_presets.cfg @@ -225,7 +225,7 @@ permissions/write_user_dictionary=false [preset.2] -name="Linux/X11" +name="Pirate Treasure Hunt" platform="Linux/X11" runnable=true custom_features="" diff --git a/islands/pirate_game_island_1.island b/islands/pirate_game_island_1.island index e2362b5..81ae23c 100644 --- a/islands/pirate_game_island_1.island +++ b/islands/pirate_game_island_1.island @@ -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"} diff --git a/scenes/Game.tscn b/scenes/Game.tscn index de57add..b416739 100644 --- a/scenes/Game.tscn +++ b/scenes/Game.tscn @@ -144,7 +144,7 @@ text = "Generate World" visible = false margin_left = 117.0 margin_right = 234.0 -margin_bottom = 40.0 +margin_bottom = 64.0 text = "Editor" [node name="Offset" type="Label" parent="World/UI/TopContainer"] @@ -187,34 +187,34 @@ __meta__ = { [node name="HexCoord" type="Label" parent="World/UI/TopContainer"] visible = false -margin_left = 238.0 -margin_top = 13.0 -margin_right = 312.0 -margin_bottom = 27.0 +margin_left = 117.0 +margin_top = 25.0 +margin_right = 191.0 +margin_bottom = 39.0 text = " HexCoord: " [node name="HexCoordValue" type="Label" parent="World/UI/TopContainer"] visible = false -margin_left = 238.0 -margin_top = 13.0 -margin_right = 266.0 -margin_bottom = 27.0 +margin_left = 117.0 +margin_top = 25.0 +margin_right = 145.0 +margin_bottom = 39.0 text = "(0,0)" [node name="WorldCoord" type="Label" parent="World/UI/TopContainer"] visible = false -margin_left = 238.0 -margin_top = 13.0 -margin_right = 321.0 -margin_bottom = 27.0 +margin_left = 117.0 +margin_top = 25.0 +margin_right = 200.0 +margin_bottom = 39.0 text = "WorldCoord: " [node name="WorldCoordValue" type="Label" parent="World/UI/TopContainer"] visible = false -margin_left = 238.0 -margin_top = 13.0 -margin_right = 266.0 -margin_bottom = 27.0 +margin_left = 117.0 +margin_top = 25.0 +margin_right = 145.0 +margin_bottom = 39.0 text = "(0,0)" [node name="TileType" type="Label" parent="World/UI/TopContainer"] diff --git a/scenes/Grid.gd b/scenes/Grid.gd index 6c64af5..d2364f7 100644 --- a/scenes/Grid.gd +++ b/scenes/Grid.gd @@ -41,6 +41,9 @@ func _process(_delta): func _draw(): + if !Globals.draw_grid: + return + view_grid_corners = calc_grid_view_rect() last_grid_corners = view_grid_corners diff --git a/scenes/Island.gd b/scenes/Island.gd index 377a08a..fd2f372 100644 --- a/scenes/Island.gd +++ b/scenes/Island.gd @@ -9,7 +9,6 @@ var radius_world = 0.0 var is_active = false var landing_site_local_coord = null var landing_site_world = null -var ship_anchor_world = null var obstacles_local_coords = {} var treasure_local_coords = null @@ -176,9 +175,3 @@ func _draw(): if Globals.debug_nav and is_active: 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")) - diff --git a/scenes/World.gd b/scenes/World.gd index 8f40d8e..f6b32a4 100644 --- a/scenes/World.gd +++ b/scenes/World.gd @@ -120,6 +120,17 @@ func _draw(): 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_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 @@ -191,6 +202,7 @@ func place_treasure(): treasure_island.update() + func render_treasure_map(): IslandMapRenderer.render_target_update_mode = Viewport.UPDATE_ONCE IslandMapRenderer.render_target_clear_mode = Viewport.CLEAR_MODE_ONLY_NEXT_FRAME @@ -308,9 +320,15 @@ func populate_island_nav_grid(): if current_island == null: print ("Error: cannot populate island nav grid: no island") return - + + var landing_site_coords = Globals.WorldToHex(current_island.landing_site_world) for tile in current_island.obstacles_local_coords.keys(): 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) @@ -343,6 +361,9 @@ func on_enter_island(island): island.is_active = true populate_island_nav_grid() island.update() + + if Globals.debug_nav: + update() func on_leave_island(island): @@ -351,6 +372,9 @@ func on_leave_island(island): island.is_active = false island.landing_site_local_coord = null island.update() + + if Globals.debug_nav: + update() 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): update_navigation_target_ocean(start_world, target_world) - var planning_duration_msec = OS.get_system_time_msecs() - start_timestamp - - update() + var planning_duration_msec = OS.get_system_time_msecs() - start_timestamp + if Globals.debug_nav: + update() # # Input & Events