Gameplay elements implemented
parent
c94209ba7b
commit
0ed4540bf0
|
@ -13,7 +13,7 @@ var OceanNavGrid = null
|
||||||
var IslandNavGrid = null
|
var IslandNavGrid = null
|
||||||
|
|
||||||
var hex_size = 128
|
var hex_size = 128
|
||||||
var debug_nav = true
|
var debug_nav = 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():
|
||||||
|
|
Binary file not shown.
After Width: | Height: | Size: 103 KiB |
|
@ -0,0 +1,34 @@
|
||||||
|
[remap]
|
||||||
|
|
||||||
|
importer="texture"
|
||||||
|
type="StreamTexture"
|
||||||
|
path="res://.import/Yeah.png-e875d971d004375e7d655e960f859fdd.stex"
|
||||||
|
metadata={
|
||||||
|
"vram_texture": false
|
||||||
|
}
|
||||||
|
|
||||||
|
[deps]
|
||||||
|
|
||||||
|
source_file="res://assets/Yeah.png"
|
||||||
|
dest_files=[ "res://.import/Yeah.png-e875d971d004375e7d655e960f859fdd.stex" ]
|
||||||
|
|
||||||
|
[params]
|
||||||
|
|
||||||
|
compress/mode=0
|
||||||
|
compress/lossy_quality=0.7
|
||||||
|
compress/hdr_mode=0
|
||||||
|
compress/bptc_ldr=0
|
||||||
|
compress/normal_map=0
|
||||||
|
flags/repeat=0
|
||||||
|
flags/filter=true
|
||||||
|
flags/mipmaps=false
|
||||||
|
flags/anisotropic=false
|
||||||
|
flags/srgb=2
|
||||||
|
process/fix_alpha_border=true
|
||||||
|
process/premult_alpha=false
|
||||||
|
process/HDR_as_SRGB=false
|
||||||
|
process/invert_color=false
|
||||||
|
stream=false
|
||||||
|
size_limit=0
|
||||||
|
detect_3d=true
|
||||||
|
svg/scale=1.0
|
|
@ -25,15 +25,15 @@
|
||||||
borderopacity="1.0"
|
borderopacity="1.0"
|
||||||
inkscape:pageopacity="0.0"
|
inkscape:pageopacity="0.0"
|
||||||
inkscape:pageshadow="2"
|
inkscape:pageshadow="2"
|
||||||
inkscape:zoom="2.8"
|
inkscape:zoom="0.98994949"
|
||||||
inkscape:cx="201.04361"
|
inkscape:cx="263.67284"
|
||||||
inkscape:cy="80.467705"
|
inkscape:cy="10.726653"
|
||||||
inkscape:document-units="mm"
|
inkscape:document-units="mm"
|
||||||
inkscape:current-layer="layer2"
|
inkscape:current-layer="layer2"
|
||||||
showgrid="false"
|
showgrid="false"
|
||||||
inkscape:window-width="1916"
|
inkscape:window-width="956"
|
||||||
inkscape:window-height="1041"
|
inkscape:window-height="1041"
|
||||||
inkscape:window-x="0"
|
inkscape:window-x="960"
|
||||||
inkscape:window-y="37"
|
inkscape:window-y="37"
|
||||||
inkscape:window-maximized="0"
|
inkscape:window-maximized="0"
|
||||||
fit-margin-top="0"
|
fit-margin-top="0"
|
||||||
|
@ -49,7 +49,7 @@
|
||||||
<dc:format>image/svg+xml</dc:format>
|
<dc:format>image/svg+xml</dc:format>
|
||||||
<dc:type
|
<dc:type
|
||||||
rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
|
rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
|
||||||
<dc:title></dc:title>
|
<dc:title />
|
||||||
</cc:Work>
|
</cc:Work>
|
||||||
</rdf:RDF>
|
</rdf:RDF>
|
||||||
</metadata>
|
</metadata>
|
||||||
|
|
Before Width: | Height: | Size: 7.4 KiB After Width: | Height: | Size: 7.4 KiB |
|
@ -0,0 +1,93 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||||
|
<!-- Created with Inkscape (http://www.inkscape.org/) -->
|
||||||
|
|
||||||
|
<svg
|
||||||
|
xmlns:dc="http://purl.org/dc/elements/1.1/"
|
||||||
|
xmlns:cc="http://creativecommons.org/ns#"
|
||||||
|
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
|
||||||
|
xmlns:svg="http://www.w3.org/2000/svg"
|
||||||
|
xmlns="http://www.w3.org/2000/svg"
|
||||||
|
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
|
||||||
|
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
|
||||||
|
width="67.73333mm"
|
||||||
|
height="67.73333mm"
|
||||||
|
viewBox="0 0 67.73333 67.73333"
|
||||||
|
version="1.1"
|
||||||
|
id="svg1420"
|
||||||
|
inkscape:version="0.92.5 (2060ec1f9f, 2020-04-08)"
|
||||||
|
sodipodi:docname="shovel.svg">
|
||||||
|
<defs
|
||||||
|
id="defs1414" />
|
||||||
|
<sodipodi:namedview
|
||||||
|
id="base"
|
||||||
|
pagecolor="#ffffff"
|
||||||
|
bordercolor="#666666"
|
||||||
|
borderopacity="1.0"
|
||||||
|
inkscape:pageopacity="0.0"
|
||||||
|
inkscape:pageshadow="2"
|
||||||
|
inkscape:zoom="0.98994949"
|
||||||
|
inkscape:cx="263.67284"
|
||||||
|
inkscape:cy="10.726653"
|
||||||
|
inkscape:document-units="mm"
|
||||||
|
inkscape:current-layer="layer2"
|
||||||
|
showgrid="false"
|
||||||
|
inkscape:window-width="956"
|
||||||
|
inkscape:window-height="1041"
|
||||||
|
inkscape:window-x="960"
|
||||||
|
inkscape:window-y="37"
|
||||||
|
inkscape:window-maximized="0"
|
||||||
|
fit-margin-top="0"
|
||||||
|
fit-margin-left="0"
|
||||||
|
fit-margin-right="0"
|
||||||
|
fit-margin-bottom="0"
|
||||||
|
showguides="false" />
|
||||||
|
<metadata
|
||||||
|
id="metadata1417">
|
||||||
|
<rdf:RDF>
|
||||||
|
<cc:Work
|
||||||
|
rdf:about="">
|
||||||
|
<dc:format>image/svg+xml</dc:format>
|
||||||
|
<dc:type
|
||||||
|
rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
|
||||||
|
<dc:title></dc:title>
|
||||||
|
</cc:Work>
|
||||||
|
</rdf:RDF>
|
||||||
|
</metadata>
|
||||||
|
<g
|
||||||
|
inkscape:label="Layer 1"
|
||||||
|
inkscape:groupmode="layer"
|
||||||
|
id="layer1"
|
||||||
|
transform="translate(-22.735567,-21.843752)">
|
||||||
|
<rect
|
||||||
|
style="fill:none;fill-opacity:1;stroke:none;stroke-width:1.16499996;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
|
||||||
|
id="rect2086"
|
||||||
|
width="67.73333"
|
||||||
|
height="67.73333"
|
||||||
|
x="22.735567"
|
||||||
|
y="21.843752" />
|
||||||
|
</g>
|
||||||
|
<g
|
||||||
|
inkscape:groupmode="layer"
|
||||||
|
id="layer2"
|
||||||
|
inkscape:label="Tool">
|
||||||
|
<g
|
||||||
|
id="g2112"
|
||||||
|
transform="rotate(39.624656,51.442591,37.959399)"
|
||||||
|
style="fill:#cccccc;stroke:#808080">
|
||||||
|
<rect
|
||||||
|
y="42.597912"
|
||||||
|
x="35.340771"
|
||||||
|
height="6.8035736"
|
||||||
|
width="28.442703"
|
||||||
|
id="rect2106"
|
||||||
|
style="fill:#cccccc;fill-opacity:1;stroke:#808080;stroke-width:2;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" />
|
||||||
|
<rect
|
||||||
|
y="38.81815"
|
||||||
|
x="54.52306"
|
||||||
|
height="14.2686"
|
||||||
|
width="17.103424"
|
||||||
|
id="rect2108"
|
||||||
|
style="fill:#cccccc;fill-opacity:1;stroke:#808080;stroke-width:2;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" />
|
||||||
|
</g>
|
||||||
|
</g>
|
||||||
|
</svg>
|
After Width: | Height: | Size: 2.9 KiB |
|
@ -0,0 +1,34 @@
|
||||||
|
[remap]
|
||||||
|
|
||||||
|
importer="texture"
|
||||||
|
type="StreamTexture"
|
||||||
|
path="res://.import/shovel.svg-008b29b052e7f004096ee9ed0e7f010d.stex"
|
||||||
|
metadata={
|
||||||
|
"vram_texture": false
|
||||||
|
}
|
||||||
|
|
||||||
|
[deps]
|
||||||
|
|
||||||
|
source_file="res://assets/shovel.svg"
|
||||||
|
dest_files=[ "res://.import/shovel.svg-008b29b052e7f004096ee9ed0e7f010d.stex" ]
|
||||||
|
|
||||||
|
[params]
|
||||||
|
|
||||||
|
compress/mode=0
|
||||||
|
compress/lossy_quality=0.7
|
||||||
|
compress/hdr_mode=0
|
||||||
|
compress/bptc_ldr=0
|
||||||
|
compress/normal_map=0
|
||||||
|
flags/repeat=0
|
||||||
|
flags/filter=true
|
||||||
|
flags/mipmaps=false
|
||||||
|
flags/anisotropic=false
|
||||||
|
flags/srgb=2
|
||||||
|
process/fix_alpha_border=true
|
||||||
|
process/premult_alpha=false
|
||||||
|
process/HDR_as_SRGB=false
|
||||||
|
process/invert_color=false
|
||||||
|
stream=false
|
||||||
|
size_limit=0
|
||||||
|
detect_3d=true
|
||||||
|
svg/scale=1.0
|
|
@ -1,4 +1,4 @@
|
||||||
[gd_scene load_steps=14 format=2]
|
[gd_scene load_steps=16 format=2]
|
||||||
|
|
||||||
[ext_resource path="res://scenes/World.gd" type="Script" id=1]
|
[ext_resource path="res://scenes/World.gd" type="Script" id=1]
|
||||||
[ext_resource path="res://scenes/Grid.gd" type="Script" id=2]
|
[ext_resource path="res://scenes/Grid.gd" type="Script" id=2]
|
||||||
|
@ -9,6 +9,8 @@
|
||||||
[ext_resource path="res://scenes/Editor.gd" type="Script" id=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://scenes/GridHighlight.gd" type="Script" id=8]
|
||||||
[ext_resource path="res://assets/boat.svg" type="Texture" id=9]
|
[ext_resource path="res://assets/boat.svg" type="Texture" id=9]
|
||||||
|
[ext_resource path="res://assets/shovel.svg" type="Texture" id=10]
|
||||||
|
[ext_resource path="res://assets/Yeah.png" type="Texture" id=11]
|
||||||
|
|
||||||
[sub_resource type="DynamicFont" id=1]
|
[sub_resource type="DynamicFont" id=1]
|
||||||
size = 27
|
size = 27
|
||||||
|
@ -273,15 +275,62 @@ margin_bottom = 221.0
|
||||||
rect_min_size = Vector2( 100, 100 )
|
rect_min_size = Vector2( 100, 100 )
|
||||||
text = "Birdy"
|
text = "Birdy"
|
||||||
|
|
||||||
|
[node name="DigButton" type="Button" parent="World/UI/VBoxContainer"]
|
||||||
|
margin_top = 242.0
|
||||||
|
margin_right = 115.0
|
||||||
|
margin_bottom = 342.0
|
||||||
|
rect_min_size = Vector2( 100, 100 )
|
||||||
|
text = "Dig"
|
||||||
|
|
||||||
|
[node name="SuccessMessage" type="Control" parent="World/UI"]
|
||||||
|
visible = false
|
||||||
|
anchor_left = 0.5
|
||||||
|
anchor_top = 0.5
|
||||||
|
anchor_right = 0.5
|
||||||
|
anchor_bottom = 0.5
|
||||||
|
margin_left = -20.0
|
||||||
|
margin_top = -20.0
|
||||||
|
margin_right = 20.0
|
||||||
|
margin_bottom = 20.0
|
||||||
|
rect_scale = Vector2( 0.5, 0.5 )
|
||||||
|
__meta__ = {
|
||||||
|
"_edit_use_anchors_": false
|
||||||
|
}
|
||||||
|
|
||||||
|
[node name="TextureRect" type="TextureRect" parent="World/UI/SuccessMessage"]
|
||||||
|
anchor_left = 0.5
|
||||||
|
anchor_top = 0.5
|
||||||
|
anchor_right = 0.5
|
||||||
|
anchor_bottom = 0.5
|
||||||
|
margin_left = -706.0
|
||||||
|
margin_top = -264.0
|
||||||
|
margin_right = 706.0
|
||||||
|
margin_bottom = 264.0
|
||||||
|
texture = ExtResource( 11 )
|
||||||
|
stretch_mode = 4
|
||||||
|
__meta__ = {
|
||||||
|
"_edit_use_anchors_": false
|
||||||
|
}
|
||||||
|
|
||||||
|
[node name="DigSites" type="Node2D" parent="World"]
|
||||||
|
|
||||||
[node name="PlayerChar" type="KinematicBody2D" parent="World"]
|
[node name="PlayerChar" type="KinematicBody2D" parent="World"]
|
||||||
script = ExtResource( 5 )
|
script = ExtResource( 5 )
|
||||||
|
|
||||||
[node name="pirate" type="Sprite" parent="World/PlayerChar"]
|
[node name="Pirate" type="Sprite" parent="World/PlayerChar"]
|
||||||
scale = Vector2( 0.45498, 0.45498 )
|
scale = Vector2( 0.45498, 0.45498 )
|
||||||
texture = ExtResource( 3 )
|
texture = ExtResource( 3 )
|
||||||
|
|
||||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="World/PlayerChar"]
|
[node name="CollisionShape2D" type="CollisionShape2D" parent="World/PlayerChar"]
|
||||||
|
|
||||||
|
[node name="Shovel" type="Sprite" parent="World/PlayerChar"]
|
||||||
|
visible = false
|
||||||
|
scale = Vector2( 0.455, 0.455 )
|
||||||
|
texture = ExtResource( 10 )
|
||||||
|
|
||||||
|
[node name="DigTimer" type="Timer" parent="World/PlayerChar"]
|
||||||
|
one_shot = true
|
||||||
|
|
||||||
[node name="Camera" type="Camera2D" parent="World"]
|
[node name="Camera" type="Camera2D" parent="World"]
|
||||||
current = true
|
current = true
|
||||||
|
|
||||||
|
@ -313,3 +362,4 @@ render_target_update_mode = 1
|
||||||
[connection signal="pressed" from="World/UI/TopContainer/Button" to="World" method="_on_generate_button_pressed"]
|
[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"]
|
[connection signal="pressed" from="World/UI/VBoxContainer/MapButton" to="World" method="_on_MapButton_pressed"]
|
||||||
[connection signal="pressed" from="World/UI/VBoxContainer/BirdyButton" to="World" method="_on_BirdyButton_pressed"]
|
[connection signal="pressed" from="World/UI/VBoxContainer/BirdyButton" to="World" method="_on_BirdyButton_pressed"]
|
||||||
|
[connection signal="pressed" from="World/UI/VBoxContainer/DigButton" to="World" method="_on_DigButton_pressed"]
|
||||||
|
|
|
@ -135,6 +135,11 @@ func get_tile_by_world_coord(world_coord: Vector2):
|
||||||
return null
|
return null
|
||||||
|
|
||||||
|
|
||||||
|
func is_point_on_treasure_site(world_coord: Vector2):
|
||||||
|
var local_coord = get_local_coord_by_world_coord(world_coord)
|
||||||
|
return treasure_local_coords != null and local_coord == treasure_local_coords
|
||||||
|
|
||||||
|
|
||||||
func is_point_on_landing_site(world_coord: Vector2):
|
func is_point_on_landing_site(world_coord: Vector2):
|
||||||
return (Globals.WorldToHex(world_coord) - Globals.WorldToHex(landing_site_world)).length_squared() < 1
|
return (Globals.WorldToHex(world_coord) - Globals.WorldToHex(landing_site_world)).length_squared() < 1
|
||||||
|
|
||||||
|
|
|
@ -6,6 +6,7 @@ onready var GridHighlight = get_node("GridHighlight")
|
||||||
onready var Editor = get_node("../Editor")
|
onready var Editor = get_node("../Editor")
|
||||||
|
|
||||||
onready var Islands = get_node("Islands")
|
onready var Islands = get_node("Islands")
|
||||||
|
onready var DigSites = get_node("DigSites")
|
||||||
onready var EditIslandButton = get_node("UI/TopContainer/EditIslandButton")
|
onready var EditIslandButton = get_node("UI/TopContainer/EditIslandButton")
|
||||||
onready var WorldCamera = get_node("Camera")
|
onready var WorldCamera = get_node("Camera")
|
||||||
onready var OffsetValueLabel = get_node("UI/TopContainer/OffsetValue")
|
onready var OffsetValueLabel = get_node("UI/TopContainer/OffsetValue")
|
||||||
|
@ -13,6 +14,7 @@ onready var ZoomValueLabel = get_node("UI/TopContainer/ZoomValue")
|
||||||
onready var HexCoordValueLabel = get_node("UI/TopContainer/HexCoordValue")
|
onready var HexCoordValueLabel = get_node("UI/TopContainer/HexCoordValue")
|
||||||
onready var WorldCoordValueLabel = get_node("UI/TopContainer/WorldCoordValue")
|
onready var WorldCoordValueLabel = get_node("UI/TopContainer/WorldCoordValue")
|
||||||
onready var TileTypeValueLabel = get_node("UI/TopContainer/TileTypeValue")
|
onready var TileTypeValueLabel = get_node("UI/TopContainer/TileTypeValue")
|
||||||
|
onready var SuccessMessage = get_node("UI/SuccessMessage")
|
||||||
onready var PlayerChar = get_node("PlayerChar")
|
onready var PlayerChar = get_node("PlayerChar")
|
||||||
onready var PlayerBoat = get_node("PlayerBoat")
|
onready var PlayerBoat = get_node("PlayerBoat")
|
||||||
onready var FPSValueLabel = get_node("UI/TopContainer/FPSValue")
|
onready var FPSValueLabel = get_node("UI/TopContainer/FPSValue")
|
||||||
|
@ -25,6 +27,9 @@ onready var BirdyTimer = get_node("Birdy/Timer")
|
||||||
var Island = preload("Island.gd")
|
var Island = preload("Island.gd")
|
||||||
var SpringDamper = preload("res://SpringDamper.gd")
|
var SpringDamper = preload("res://SpringDamper.gd")
|
||||||
|
|
||||||
|
var DigSiteSprite = preload("res://assets/digsite.svg")
|
||||||
|
var DigSiteTreasureSprite = preload("res://assets/treasuredigsite.svg")
|
||||||
|
|
||||||
var hex_grid_bbox = [[0,0], [10,10]]
|
var hex_grid_bbox = [[0,0], [10,10]]
|
||||||
|
|
||||||
var hex_hover = Vector2.ZERO
|
var hex_hover = Vector2.ZERO
|
||||||
|
@ -61,7 +66,9 @@ func _ready():
|
||||||
|
|
||||||
# Set player starting position
|
# Set player starting position
|
||||||
PlayerChar.position = Globals.HexGrid.get_hex_center(Vector2(0,0))
|
PlayerChar.position = Globals.HexGrid.get_hex_center(Vector2(0,0))
|
||||||
|
PlayerChar.connect("dig_stopped", self, "on_dig_stopped")
|
||||||
|
|
||||||
|
self.connect("treasure_found", self, "on_treasure_found")
|
||||||
|
|
||||||
func _process(delta):
|
func _process(delta):
|
||||||
if is_editor_active():
|
if is_editor_active():
|
||||||
|
@ -119,6 +126,12 @@ func clear_islands():
|
||||||
for island in Islands.get_children():
|
for island in Islands.get_children():
|
||||||
Islands.remove_child(island)
|
Islands.remove_child(island)
|
||||||
island.queue_free()
|
island.queue_free()
|
||||||
|
|
||||||
|
|
||||||
|
func clear_digsites():
|
||||||
|
for digsite in DigSites.get_children():
|
||||||
|
DigSites.remove_child(digsite)
|
||||||
|
digsite.queue_free()
|
||||||
|
|
||||||
|
|
||||||
func get_tile_type(world_coord: Vector2):
|
func get_tile_type(world_coord: Vector2):
|
||||||
|
@ -140,6 +153,14 @@ func add_island_at(file_name, offset_world: Vector2):
|
||||||
func is_editor_active():
|
func is_editor_active():
|
||||||
return Editor == null or not Editor.is_active()
|
return Editor == null or not Editor.is_active()
|
||||||
|
|
||||||
|
|
||||||
|
func check_player_on_treasure():
|
||||||
|
if current_island == null:
|
||||||
|
return false
|
||||||
|
|
||||||
|
return current_island.is_point_on_treasure_site(Globals.HexToWorld(PlayerChar.cur_tile))
|
||||||
|
|
||||||
|
|
||||||
func check_island_location_valid(new_island):
|
func check_island_location_valid(new_island):
|
||||||
var grid_origin_world_coord = Globals.HexToWorld(Vector2(0,0))
|
var grid_origin_world_coord = Globals.HexToWorld(Vector2(0,0))
|
||||||
if new_island.get_tile_by_world_coord(grid_origin_world_coord) != null:
|
if new_island.get_tile_by_world_coord(grid_origin_world_coord) != null:
|
||||||
|
@ -163,6 +184,9 @@ func place_treasure():
|
||||||
|
|
||||||
treasure_island.treasure_local_coords = grass_tiles[randi() % len(grass_tiles)]
|
treasure_island.treasure_local_coords = grass_tiles[randi() % len(grass_tiles)]
|
||||||
|
|
||||||
|
if Globals.debug_nav:
|
||||||
|
treasure_island.highlight_treasure = true
|
||||||
|
|
||||||
treasure_island.update()
|
treasure_island.update()
|
||||||
|
|
||||||
func render_treasure_map():
|
func render_treasure_map():
|
||||||
|
@ -190,26 +214,43 @@ func render_treasure_map():
|
||||||
IslandMap.texture = IslandMapRenderer.get_texture()
|
IslandMap.texture = IslandMapRenderer.get_texture()
|
||||||
|
|
||||||
|
|
||||||
func generate():
|
func reset():
|
||||||
PlayerChar.transform.origin = Vector2.ZERO
|
PlayerChar.transform.origin = Vector2.ZERO
|
||||||
PlayerChar.position = Vector2.ZERO
|
PlayerChar.position = Vector2.ZERO
|
||||||
PlayerChar.target = Vector2.ZERO
|
PlayerChar.target = Vector2.ZERO
|
||||||
|
|
||||||
|
hex_line_path = []
|
||||||
|
player_navigation_path = []
|
||||||
|
player_path_plan_start = null
|
||||||
|
player_path_plan_end = null
|
||||||
|
|
||||||
|
current_island = null
|
||||||
treasure_island = null
|
treasure_island = null
|
||||||
|
|
||||||
|
clear_islands()
|
||||||
|
clear_digsites()
|
||||||
|
|
||||||
|
SuccessMessage.visible = false
|
||||||
|
|
||||||
|
func generate():
|
||||||
|
reset()
|
||||||
|
|
||||||
var rng = RandomNumberGenerator.new()
|
var rng = RandomNumberGenerator.new()
|
||||||
rng.randomize()
|
rng.randomize()
|
||||||
|
randomize()
|
||||||
clear_islands()
|
|
||||||
|
|
||||||
var radius = 800
|
var radius = 800
|
||||||
var num_islands = 10
|
var num_islands = 4
|
||||||
var island_index_offset = randi() % 10
|
|
||||||
|
var island_files = []
|
||||||
|
for i in range (num_islands):
|
||||||
|
island_files.append("res://islands/pirate_game_island_" + str(i) + ".island")
|
||||||
|
island_files.shuffle()
|
||||||
|
|
||||||
for i in range (num_islands):
|
for i in range (num_islands):
|
||||||
var island = Island.new()
|
var island = Island.new()
|
||||||
var island_index = (i + island_index_offset) % 10
|
var file_name = island_files[i]
|
||||||
var file_name = "res://islands/pirate_game_island_" + str(island_index) + ".island"
|
|
||||||
island.load_island(file_name)
|
island.load_island(file_name)
|
||||||
|
|
||||||
var rand_coord = Vector2(rng.randi_range(-radius, radius), rng.randi_range(-radius, radius))
|
var rand_coord = Vector2(rng.randi_range(-radius, radius), rng.randi_range(-radius, radius))
|
||||||
|
@ -234,7 +275,7 @@ func generate():
|
||||||
Islands.add_child(island)
|
Islands.add_child(island)
|
||||||
|
|
||||||
num_islands = Islands.get_child_count()
|
num_islands = Islands.get_child_count()
|
||||||
treasure_island = Islands.get_child(randi() % num_islands)
|
treasure_island = Islands.get_child(rng.randi() % num_islands)
|
||||||
|
|
||||||
place_treasure()
|
place_treasure()
|
||||||
|
|
||||||
|
@ -291,6 +332,7 @@ func update_current_island():
|
||||||
|
|
||||||
func on_enter_island(island):
|
func on_enter_island(island):
|
||||||
print ("Entering island")
|
print ("Entering island")
|
||||||
|
PlayerChar.on_enter_island()
|
||||||
current_island = island
|
current_island = island
|
||||||
anchor_tile = PlayerChar.prev_tile
|
anchor_tile = PlayerChar.prev_tile
|
||||||
landing_tile = PlayerChar.cur_tile
|
landing_tile = PlayerChar.cur_tile
|
||||||
|
@ -303,11 +345,31 @@ func on_enter_island(island):
|
||||||
|
|
||||||
func on_leave_island(island):
|
func on_leave_island(island):
|
||||||
print ("Leaving island")
|
print ("Leaving island")
|
||||||
|
PlayerChar.on_leave_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()
|
||||||
|
|
||||||
|
|
||||||
|
func on_dig_stopped():
|
||||||
|
print ("Dig stopped!")
|
||||||
|
var dig_site = Sprite.new()
|
||||||
|
dig_site.transform.origin = Globals.HexToWorld(PlayerChar.cur_tile)
|
||||||
|
|
||||||
|
if check_player_on_treasure():
|
||||||
|
emit_signal("treasure_found")
|
||||||
|
on_treasure_found()
|
||||||
|
dig_site.texture = DigSiteTreasureSprite
|
||||||
|
else:
|
||||||
|
dig_site.texture = DigSiteSprite
|
||||||
|
|
||||||
|
DigSites.add_child(dig_site)
|
||||||
|
|
||||||
|
|
||||||
|
func on_treasure_found():
|
||||||
|
SuccessMessage.visible = true
|
||||||
|
|
||||||
|
|
||||||
func check_player_near_anchor():
|
func check_player_near_anchor():
|
||||||
if current_island == null:
|
if current_island == null:
|
||||||
return false
|
return false
|
||||||
|
@ -315,6 +377,7 @@ func check_player_near_anchor():
|
||||||
var anchor_world = Globals.HexToWorld(anchor_tile)
|
var anchor_world = Globals.HexToWorld(anchor_tile)
|
||||||
return (PlayerChar.position - anchor_world).length() < Globals.hex_size
|
return (PlayerChar.position - anchor_world).length() < Globals.hex_size
|
||||||
|
|
||||||
|
|
||||||
func update_navigation_target_ocean(start_world: Vector2, target_world: Vector2):
|
func update_navigation_target_ocean(start_world: Vector2, target_world: Vector2):
|
||||||
var start_coord = Globals.WorldToHex(start_world)
|
var start_coord = Globals.WorldToHex(start_world)
|
||||||
var goal_coord = Globals.WorldToHex(target_world)
|
var goal_coord = Globals.WorldToHex(target_world)
|
||||||
|
@ -326,12 +389,10 @@ func update_navigation_target_ocean(start_world: Vector2, target_world: Vector2)
|
||||||
var direct_path = Globals.WorldLineToHexTiles(start_world, target_world)
|
var direct_path = Globals.WorldLineToHexTiles(start_world, target_world)
|
||||||
|
|
||||||
if get_tile_type(start_world) != null and current_island != null and len(direct_path) > 1:
|
if get_tile_type(start_world) != null and current_island != null and len(direct_path) > 1:
|
||||||
print ("type 0: ", get_tile_type(direct_path[0]))
|
# print ("on landing site: ", current_island.is_point_on_landing_site (start_world))
|
||||||
print ("type 1: ", get_tile_type(direct_path[1]))
|
|
||||||
print ("on landing site: ", current_island.is_point_on_landing_site (start_world))
|
|
||||||
if current_island.is_point_on_landing_site (start_world):
|
if current_island.is_point_on_landing_site (start_world):
|
||||||
if get_tile_type(direct_path[1]) == null:
|
if get_tile_type(direct_path[1]) == null:
|
||||||
print ("starting from landing site")
|
# print ("starting from landing site")
|
||||||
direct_path.pop_front()
|
direct_path.pop_front()
|
||||||
start_coord = Globals.WorldToHex(direct_path.front())
|
start_coord = Globals.WorldToHex(direct_path.front())
|
||||||
else:
|
else:
|
||||||
|
@ -350,7 +411,7 @@ func update_navigation_target_ocean(start_world: Vector2, target_world: Vector2)
|
||||||
print ("Could not find path!")
|
print ("Could not find path!")
|
||||||
return
|
return
|
||||||
|
|
||||||
print ("Using ", Globals.WorldToHex(direct_path.back()), " instead of ", goal_coord, " as goal.")
|
# print ("Using ", Globals.WorldToHex(direct_path.back()), " instead of ", goal_coord, " as goal.")
|
||||||
goal_coord = Globals.WorldToHex(direct_path.back())
|
goal_coord = Globals.WorldToHex(direct_path.back())
|
||||||
island_landing_site_world = last_removed
|
island_landing_site_world = last_removed
|
||||||
|
|
||||||
|
@ -375,12 +436,10 @@ func update_navigation_target_ocean(start_world: Vector2, target_world: Vector2)
|
||||||
|
|
||||||
|
|
||||||
func update_navigation_target_island(start_world: Vector2, target_world: Vector2):
|
func update_navigation_target_island(start_world: Vector2, target_world: Vector2):
|
||||||
print ("Navigating Island")
|
|
||||||
var start_coord = Globals.WorldToHex(start_world)
|
var start_coord = Globals.WorldToHex(start_world)
|
||||||
var goal_coord = Globals.WorldToHex(target_world)
|
var goal_coord = Globals.WorldToHex(target_world)
|
||||||
|
|
||||||
var path = Globals.IslandNavGrid.find_path(start_coord, goal_coord)
|
var path = Globals.IslandNavGrid.find_path(start_coord, goal_coord)
|
||||||
print ("Path length: ", len(path))
|
|
||||||
for target in path.slice(0,-1):
|
for target in path.slice(0,-1):
|
||||||
var target_world_coord = Globals.HexToWorld(target.axial_coords)
|
var target_world_coord = Globals.HexToWorld(target.axial_coords)
|
||||||
var target_type = get_tile_type(target_world_coord)
|
var target_type = get_tile_type(target_world_coord)
|
||||||
|
@ -396,7 +455,6 @@ func update_player_navigation_target(target_world: Vector2):
|
||||||
var start_timestamp = OS.get_system_time_msecs()
|
var start_timestamp = OS.get_system_time_msecs()
|
||||||
|
|
||||||
var player_near_anchor = check_player_near_anchor()
|
var player_near_anchor = check_player_near_anchor()
|
||||||
print ("Player near anchor: ", player_near_anchor)
|
|
||||||
|
|
||||||
if current_island != null:
|
if current_island != null:
|
||||||
update_navigation_target_island(start_world, target_world)
|
update_navigation_target_island(start_world, target_world)
|
||||||
|
@ -408,7 +466,6 @@ func update_player_navigation_target(target_world: Vector2):
|
||||||
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
|
||||||
print ("Planning took ", round(planning_duration_msec), "ms.")
|
|
||||||
|
|
||||||
update()
|
update()
|
||||||
|
|
||||||
|
@ -489,3 +546,8 @@ func _on_BirdyButton_pressed():
|
||||||
BirdyTimer.one_shot = true
|
BirdyTimer.one_shot = true
|
||||||
BirdyTimer.start(birdy_duration)
|
BirdyTimer.start(birdy_duration)
|
||||||
|
|
||||||
|
|
||||||
|
func _on_DigButton_pressed():
|
||||||
|
print ("dig pressed")
|
||||||
|
if PlayerChar.state == PlayerChar.State.Walking:
|
||||||
|
PlayerChar.on_dig_start()
|
||||||
|
|
|
@ -2,13 +2,29 @@ extends KinematicBody2D
|
||||||
|
|
||||||
export (int) var speed = 200
|
export (int) var speed = 200
|
||||||
|
|
||||||
|
enum State {
|
||||||
|
Sailing,
|
||||||
|
Walking,
|
||||||
|
Digging
|
||||||
|
}
|
||||||
|
|
||||||
|
signal dig_stopped
|
||||||
|
|
||||||
|
onready var Shovel = get_node("Shovel")
|
||||||
|
onready var DigTimer = get_node("DigTimer")
|
||||||
|
|
||||||
var velocity = Vector2()
|
var velocity = Vector2()
|
||||||
var target = Vector2()
|
var target = Vector2()
|
||||||
var prev_tile = null # Hex coords of previous tile
|
var prev_tile = null # Hex coords of previous tile
|
||||||
var cur_tile = null # Hex coords of current tile
|
var cur_tile = null # Hex coords of current tile
|
||||||
|
var state = State.Sailing
|
||||||
|
|
||||||
func get_input():
|
func get_input():
|
||||||
velocity = Vector2()
|
velocity = Vector2()
|
||||||
|
|
||||||
|
if state == State.Digging:
|
||||||
|
return
|
||||||
|
|
||||||
if Input.is_action_pressed("walk_right"):
|
if Input.is_action_pressed("walk_right"):
|
||||||
velocity.x += 1
|
velocity.x += 1
|
||||||
if Input.is_action_pressed("walk_left"):
|
if Input.is_action_pressed("walk_left"):
|
||||||
|
@ -29,13 +45,30 @@ func _physics_process(_delta):
|
||||||
if tile != cur_tile:
|
if tile != cur_tile:
|
||||||
prev_tile = cur_tile
|
prev_tile = cur_tile
|
||||||
cur_tile = tile
|
cur_tile = tile
|
||||||
|
|
||||||
|
Shovel.visible = state == State.Digging
|
||||||
|
|
||||||
|
|
||||||
# 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():
|
||||||
position = Vector2(0,0)
|
position = Vector2(0,0)
|
||||||
|
DigTimer.connect("timeout", self, "on_dig_stop")
|
||||||
|
|
||||||
|
|
||||||
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
func on_enter_island():
|
||||||
#func _process(delta):
|
state = State.Walking
|
||||||
# pass
|
|
||||||
|
|
||||||
|
func on_leave_island():
|
||||||
|
state = State.Sailing
|
||||||
|
|
||||||
|
|
||||||
|
func on_dig_start():
|
||||||
|
print ("Start digging")
|
||||||
|
state = State.Digging
|
||||||
|
DigTimer.start(1.0)
|
||||||
|
|
||||||
|
|
||||||
|
func on_dig_stop():
|
||||||
|
state = State.Walking
|
||||||
|
emit_signal ("dig_stopped")
|
||||||
|
|
Loading…
Reference in New Issue