From d7049b43edcb9d7ba261af0b04485688a91ac4d9 Mon Sep 17 00:00:00 2001 From: Martin Felis Date: Sun, 23 Jan 2022 14:08:28 +0100 Subject: [PATCH] Coin Spawner tweaks, grid-free movement on island --- addons/gdhexgrid/icon.png.import | 6 ++-- assets/arrowback.svg.import | 1 + assets/arrowrepeat.svg.import | 1 + assets/pirate.svg | 57 +++++++++++++++++++++++++++++--- assets/pirate.svg.import | 1 + assets/title logo.png.import | 1 + assets/water.png.import | 1 + scenes/CoinSpawner.gd | 19 +++++++---- scenes/Game.tscn | 1 + scenes/World.gd | 16 ++++++--- 10 files changed, 85 insertions(+), 19 deletions(-) diff --git a/addons/gdhexgrid/icon.png.import b/addons/gdhexgrid/icon.png.import index 792998c..96cbf46 100644 --- a/addons/gdhexgrid/icon.png.import +++ b/addons/gdhexgrid/icon.png.import @@ -2,15 +2,15 @@ importer="texture" type="StreamTexture" -path="res://.import/icon.png-9e2c68854eff2ba15efab32e39b37c44.stex" +path="res://.import/icon.png-487276ed1e3a0c39cad0279d744ee560.stex" metadata={ "vram_texture": false } [deps] -source_file="res://addons/gdhexgrid/icon.png" -dest_files=[ "res://.import/icon.png-9e2c68854eff2ba15efab32e39b37c44.stex" ] +source_file="res://icon.png" +dest_files=[ "res://.import/icon.png-487276ed1e3a0c39cad0279d744ee560.stex" ] [params] diff --git a/assets/arrowback.svg.import b/assets/arrowback.svg.import index 119f0da..1fabfe6 100644 --- a/assets/arrowback.svg.import +++ b/assets/arrowback.svg.import @@ -28,6 +28,7 @@ process/fix_alpha_border=true process/premult_alpha=false process/HDR_as_SRGB=false process/invert_color=false +process/normal_map_invert_y=false stream=false size_limit=0 detect_3d=true diff --git a/assets/arrowrepeat.svg.import b/assets/arrowrepeat.svg.import index 232e121..e663e7c 100644 --- a/assets/arrowrepeat.svg.import +++ b/assets/arrowrepeat.svg.import @@ -28,6 +28,7 @@ process/fix_alpha_border=true process/premult_alpha=false process/HDR_as_SRGB=false process/invert_color=false +process/normal_map_invert_y=false stream=false size_limit=0 detect_3d=true diff --git a/assets/pirate.svg b/assets/pirate.svg index 9c800ed..800a0bb 100644 --- a/assets/pirate.svg +++ b/assets/pirate.svg @@ -25,9 +25,9 @@ borderopacity="1.0" inkscape:pageopacity="0.0" inkscape:pageshadow="2" - inkscape:zoom="0.7" + inkscape:zoom="1.979899" inkscape:cx="193.12383" - inkscape:cy="-78.795116" + inkscape:cy="128.13748" inkscape:document-units="mm" inkscape:current-layer="layer1" showgrid="false" @@ -49,7 +49,7 @@ image/svg+xml - + @@ -119,7 +119,7 @@ sodipodi:nodetypes="cc" /> + transform="matrix(0.7487091,0,0,0.7487091,22.011525,15.311364)"> + + + + + + diff --git a/assets/pirate.svg.import b/assets/pirate.svg.import index ff815a6..14925e2 100644 --- a/assets/pirate.svg.import +++ b/assets/pirate.svg.import @@ -28,6 +28,7 @@ process/fix_alpha_border=true process/premult_alpha=false process/HDR_as_SRGB=false process/invert_color=false +process/normal_map_invert_y=false stream=false size_limit=0 detect_3d=true diff --git a/assets/title logo.png.import b/assets/title logo.png.import index b2d57e8..d611035 100644 --- a/assets/title logo.png.import +++ b/assets/title logo.png.import @@ -28,6 +28,7 @@ process/fix_alpha_border=true process/premult_alpha=false process/HDR_as_SRGB=false process/invert_color=false +process/normal_map_invert_y=false stream=false size_limit=0 detect_3d=true diff --git a/assets/water.png.import b/assets/water.png.import index 6b5cd26..2b4867a 100644 --- a/assets/water.png.import +++ b/assets/water.png.import @@ -28,6 +28,7 @@ process/fix_alpha_border=true process/premult_alpha=false process/HDR_as_SRGB=false process/invert_color=false +process/normal_map_invert_y=false stream=false size_limit=0 detect_3d=true diff --git a/scenes/CoinSpawner.gd b/scenes/CoinSpawner.gd index ec06f76..bd69b69 100644 --- a/scenes/CoinSpawner.gd +++ b/scenes/CoinSpawner.gd @@ -5,7 +5,7 @@ onready var Coin = preload("./Coin.tscn") # Declare member variables here. Examples: # var a = 2 # var b = "text" -var coin_spread = 50 +var coin_spread = 100 # Called when the node enters the scene tree for the first time. func _ready(): @@ -17,19 +17,22 @@ func _ready(): #func _process(delta): # pass -func emit_coins (num, _position = null): +func create_coins (num, _position = null): + var result = [] for i in range (num): var coin = Coin.instance() coin.position = position if _position != null: coin.position = _position - - coin.velocity = Vector2 (rand_range(-coin_spread, coin_spread), rand_range (-coin_spread, coin_spread)) + + coin.velocity = Vector2 (2 * rand_range(-coin_spread, coin_spread), rand_range (-coin_spread, coin_spread)) coin.z_pos = 0 coin.z_vel = rand_range(300, 800) - add_child(coin) - + result.push_back(coin) + + return result + func _unhandled_input(event): if 'position' in event: @@ -37,4 +40,6 @@ func _unhandled_input(event): if event is InputEventMouseButton: if event.button_index == BUTTON_LEFT and event.pressed: - emit_coins(25, relative_pos) + var coins = create_coins(25, relative_pos) + for coin in coins: + add_child(coin) diff --git a/scenes/Game.tscn b/scenes/Game.tscn index 792776a..ea04c42 100644 --- a/scenes/Game.tscn +++ b/scenes/Game.tscn @@ -186,6 +186,7 @@ script = ExtResource( 2 ) z_index = -1 [node name="GridHighlight" type="Node2D" parent="World"] +visible = false script = ExtResource( 8 ) [node name="UI" type="CanvasLayer" parent="World"] diff --git a/scenes/World.gd b/scenes/World.gd index 0b1d02a..cb7e2a3 100644 --- a/scenes/World.gd +++ b/scenes/World.gd @@ -543,7 +543,10 @@ func update_navigation_target_island(start_world: Vector2, target_world: Vector2 player_navigation_path.append(target_world_coord) -func update_player_navigation_target(target_world: Vector2): +func update_player_navigation_target(mouse_pos: Vector2): + var target_tile = Globals.HexGrid.get_hex_center(Globals.ScreenToHex(mouse_pos, WorldCamera)) + var target_world = Globals.ScreenToWorld(mouse_pos, WorldCamera) + var start_world = PlayerChar.transform.origin player_navigation_path = [] @@ -553,14 +556,17 @@ func update_player_navigation_target(target_world: Vector2): var player_near_anchor = check_player_near_anchor() if current_island != null: - update_navigation_target_island(start_world, target_world) + update_navigation_target_island(start_world, target_tile) + if current_island.get_tile_by_world_coord(target_tile) != null: + player_navigation_path.append(target_world) if len(player_navigation_path) == 0 and player_near_anchor: start_world = Globals.HexToWorld(anchor_tile) 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_tile) + player_navigation_path.append(target_world) + var planning_duration_msec = OS.get_system_time_msecs() - start_timestamp if Globals.debug_nav: @@ -580,7 +586,7 @@ func handle_game_event(event): if event is InputEventMouseButton: # Move main character if event.pressed and event.button_index == BUTTON_LEFT: - update_player_navigation_target (Globals.HexGrid.get_hex_center(Globals.ScreenToHex(get_global_mouse_position(), WorldCamera))) + update_player_navigation_target (get_global_mouse_position()) return false