diff --git a/scenes/Editor.gd b/scenes/Editor.gd index 59c9ddb..2885cfe 100644 --- a/scenes/Editor.gd +++ b/scenes/Editor.gd @@ -7,7 +7,6 @@ extends Node2D # UI elements onready var EditorUI = get_node("UI/Editor") -onready var TileTypes = get_node("UI/TileTypes") onready var NoneButton = get_node("UI/Editor/NoneButton") onready var IslandIndex = get_node("UI/Editor/IslandIndex") diff --git a/scenes/Game.tscn b/scenes/Game.tscn index 99ba38d..1ee3b1f 100644 --- a/scenes/Game.tscn +++ b/scenes/Game.tscn @@ -1,4 +1,4 @@ -[gd_scene load_steps=13 format=2] +[gd_scene load_steps=15 format=2] [ext_resource path="res://scenes/World.gd" type="Script" id=1] [ext_resource path="res://scenes/Grid.gd" type="Script" id=2] @@ -9,6 +9,7 @@ [ext_resource path="res://scenes/Editor.gd" type="Script" id=7] [ext_resource path="res://scenes/GridHighlight.gd" type="Script" id=8] [ext_resource path="res://assets/boat.svg" type="Texture" id=9] +[ext_resource path="res://scenes/IslandMapRenderer.gd" type="Script" id=10] [sub_resource type="DynamicFont" id=1] size = 27 @@ -20,6 +21,8 @@ default_font = SubResource( 1 ) [sub_resource type="ButtonGroup" id=3] resource_name = "TileTypeGroup" +[sub_resource type="World" id=4] + [node name="GameRoot" type="Node"] [node name="Editor" type="Node2D" parent="."] @@ -237,6 +240,39 @@ text = "0" align = 2 script = ExtResource( 4 ) +[node name="IslandMap" type="TextureRect" parent="World/UI"] +anchor_right = 1.0 +anchor_bottom = 1.0 +expand = true +stretch_mode = 7 +__meta__ = { +"_edit_use_anchors_": false +} + +[node name="VBoxContainer" type="VBoxContainer" parent="World/UI"] +anchor_left = 1.0 +anchor_right = 1.0 +anchor_bottom = 1.0 +margin_left = -115.0 +margin_top = 92.0 +custom_constants/separation = 21 +__meta__ = { +"_edit_use_anchors_": false +} + +[node name="MapButton" type="Button" parent="World/UI/VBoxContainer"] +margin_right = 115.0 +margin_bottom = 100.0 +rect_min_size = Vector2( 100, 100 ) +text = "Map" + +[node name="BirdyButton" type="Button" parent="World/UI/VBoxContainer"] +margin_top = 121.0 +margin_right = 115.0 +margin_bottom = 221.0 +rect_min_size = Vector2( 100, 100 ) +text = "Birdy" + [node name="PlayerChar" type="KinematicBody2D" parent="World"] script = ExtResource( 5 ) @@ -255,9 +291,21 @@ current = true scale = Vector2( 0.455, 0.455 ) texture = ExtResource( 9 ) +[node name="IslandMapRenderer" type="Viewport" parent="."] +size = Vector2( 300, 300 ) +own_world = true +world = SubResource( 4 ) +render_target_v_flip = true +render_target_clear_mode = 2 +render_target_update_mode = 1 +script = ExtResource( 10 ) + +[node name="Camera2D" type="Camera2D" parent="IslandMapRenderer"] + [connection signal="value_changed" from="Editor/UI/Editor/IslandIndex" to="Editor" method="_on_IslandIndex_value_changed"] [connection signal="pressed" from="Editor/UI/Editor/ClearWorldButton" to="Editor" method="_on_ClearWorldButton_pressed"] [connection signal="pressed" from="Editor/UI/Editor/LoadWorldButton" to="Editor" method="_on_LoadWorldButton_pressed"] [connection signal="pressed" from="Editor/UI/Editor/SaveWorldButton" to="Editor" method="_on_SaveWorldButton_pressed"] [connection signal="toggled" from="World/UI/TopContainer/EditIslandButton" to="Editor" method="_on_EditIslandButton_toggled"] [connection signal="pressed" from="World/UI/TopContainer/Button" to="World" method="_on_generate_button_pressed"] +[connection signal="pressed" from="World/UI/VBoxContainer/MapButton" to="World" method="_on_MapButton_pressed"] diff --git a/scenes/World.gd b/scenes/World.gd index c39e674..aa3a2b5 100644 --- a/scenes/World.gd +++ b/scenes/World.gd @@ -17,6 +17,9 @@ onready var PlayerChar = get_node("PlayerChar") onready var PlayerBoat = get_node("PlayerBoat") onready var FPSValueLabel = get_node("UI/TopContainer/FPSValue") +onready var IslandMap = get_node("UI/IslandMap") +onready var IslandMapRenderer = get_node("../IslandMapRenderer") + var Island = preload("Island.gd") var hex_grid_bbox = [[0,0], [10,10]] @@ -33,7 +36,8 @@ var player_navigation_path = [] var player_path_plan_start = null var player_path_plan_end = null var hex_line_path = [] - +var treasure_island = null +var treasure_map_rendered = false # # Godot Functions @@ -127,10 +131,39 @@ func check_island_location_valid(new_island): return true +func render_treasure_map(): + if treasure_map_rendered == false: + treasure_map_rendered = true + + IslandMapRenderer.render_target_update_mode = Viewport.UPDATE_ONCE + IslandMapRenderer.render_target_clear_mode = Viewport.CLEAR_MODE_ONLY_NEXT_FRAME + var camera = IslandMapRenderer.get_node("Camera2D") + camera.current = true + camera.zoom = Vector2.ONE * 10.0 + camera.offset = treasure_island.center_world_coord + var island = Island.new() + island.tiles = treasure_island.tiles.duplicate() + island.name = "island" + + for child in IslandMapRenderer.get_children(): + if child.name == "island": + print ("removing ", child) + IslandMapRenderer.remove_child(child) + child.queue_free() + break + + IslandMapRenderer.add_child(island) + + IslandMap.texture = IslandMapRenderer.get_texture() + + func generate(): PlayerChar.transform.origin = Vector2.ZERO PlayerChar.position = Vector2.ZERO PlayerChar.target = Vector2.ZERO + + treasure_island = null + treasure_map_rendered = false var rng = RandomNumberGenerator.new() rng.randomize() @@ -139,10 +172,11 @@ func generate(): var radius = 800 var num_islands = 10 + var island_index_offset = randi() % 10 for i in range (num_islands): var island = Island.new() - var island_index = i % 10 + var island_index = (i + island_index_offset) % 10 var file_name = "res://islands/pirate_game_island_" + str(island_index) + ".island" island.load_island(file_name) @@ -167,6 +201,11 @@ func generate(): print ("Placed after " + str(overlap_retry_num) + " retries.") Islands.add_child(island) + num_islands = Islands.get_child_count() + treasure_island = Islands.get_child(randi() % num_islands) + + render_treasure_map() + populate_ocean_nav_grid() @@ -404,3 +443,7 @@ func _unhandled_input(event): OffsetValueLabel.text = str(WorldCamera.offset) ZoomValueLabel.text = str(WorldCamera.zoom) + + +func _on_MapButton_pressed(): + IslandMap.visible = !IslandMap.visible