PirateTreasureHunt/scenes/World.gd

642 lines
18 KiB
GDScript
Raw Normal View History

extends Node2D
2021-06-28 21:51:09 +02:00
onready var Grid = get_node("Grid")
onready var GridHighlight = get_node("GridHighlight")
2021-07-14 20:11:20 +02:00
onready var Editor = get_node("../Editor")
2021-06-28 21:51:09 +02:00
onready var Islands = get_node("Islands")
2021-07-16 12:07:11 +02:00
onready var DigSites = get_node("DigSites")
2021-06-19 23:14:01 +02:00
onready var EditIslandButton = get_node("UI/TopContainer/EditIslandButton")
onready var WorldCamera = get_node("Camera")
onready var OffsetValueLabel = get_node("UI/TopContainer/OffsetValue")
onready var ZoomValueLabel = get_node("UI/TopContainer/ZoomValue")
onready var HexCoordValueLabel = get_node("UI/TopContainer/HexCoordValue")
onready var WorldCoordValueLabel = get_node("UI/TopContainer/WorldCoordValue")
2021-07-09 18:16:21 +02:00
onready var TileTypeValueLabel = get_node("UI/TopContainer/TileTypeValue")
2021-07-16 12:07:11 +02:00
onready var SuccessMessage = get_node("UI/SuccessMessage")
2021-06-17 23:03:45 +02:00
onready var PlayerChar = get_node("PlayerChar")
2021-07-09 14:17:25 +02:00
onready var PlayerBoat = get_node("PlayerBoat")
2021-06-17 23:07:57 +02:00
onready var FPSValueLabel = get_node("UI/TopContainer/FPSValue")
2021-07-14 21:38:35 +02:00
onready var IslandMap = get_node("UI/IslandMap")
onready var IslandMapRenderer = get_node("../IslandMapRenderer")
2021-07-20 22:44:13 +02:00
onready var MapButton = get_node("UI/VBoxContainer/MapButton")
onready var BirdyButton = get_node("UI/VBoxContainer/BirdyButton")
onready var DigButton = get_node("UI/VBoxContainer/DigButton")
2021-07-14 21:58:07 +02:00
onready var BirdyTimer = get_node("Birdy/Timer")
2021-06-27 12:26:44 +02:00
var Island = preload("Island.gd")
2021-07-14 21:58:07 +02:00
var SpringDamper = preload("res://SpringDamper.gd")
2021-07-16 12:07:11 +02:00
var DigSiteSprite = preload("res://assets/digsite.svg")
var DigSiteTreasureSprite = preload("res://assets/treasuredigsite.svg")
2021-06-17 23:03:45 +02:00
var hex_grid_bbox = [[0,0], [10,10]]
var hex_hover = Vector2.ZERO
var is_dragging = false
var drag_start = null
2021-06-17 23:03:45 +02:00
var target = Vector2()
2021-06-19 23:14:01 +02:00
var tile_data = {}
var current_island = null
2021-07-11 16:09:04 +02:00
var anchor_tile = null
var landing_tile = null
2021-07-09 18:16:21 +02:00
var player_navigation_path = []
2021-07-11 16:09:04 +02:00
var player_path_plan_start = null
var player_path_plan_end = null
2021-07-10 14:18:47 +02:00
var hex_line_path = []
2021-07-14 21:38:35 +02:00
var treasure_island = null
var treasure_map_rendered = false
2021-07-20 22:44:13 +02:00
var bird_flying = false
2021-07-14 21:58:07 +02:00
var birdy_spring = null
var birdy_spring_x = Vector2.ONE
var birdy_spring_v = Vector2.ZERO
var birdy_spring_xt = Vector2.ONE
var birdy_duration = 4.0
2021-07-20 22:44:13 +02:00
signal world_generation_triggered
signal wrong_digsite
2021-07-18 17:16:26 +02:00
signal treasure_found
2021-07-20 22:44:13 +02:00
signal bird_flight_start
signal bird_flight_end
signal map_opened
signal map_closed
2021-07-18 17:16:26 +02:00
2021-07-10 11:24:04 +02:00
#
# Godot Functions
#
2021-06-28 21:51:09 +02:00
func _ready():
Grid.view_camera = WorldCamera
GridHighlight.view_camera = WorldCamera
2021-06-17 23:07:57 +02:00
2021-07-14 21:58:07 +02:00
birdy_spring = SpringDamper.new(2, 0.99, 0.5)
generate()
2021-06-28 21:51:09 +02:00
# Set player starting position
PlayerChar.position = Globals.HexGrid.get_hex_center(Vector2(0,0))
2021-07-16 12:07:11 +02:00
PlayerChar.connect("dig_stopped", self, "on_dig_stopped")
self.connect("treasure_found", self, "on_treasure_found")
2021-07-20 22:44:13 +02:00
self.connect("bird_flight_start", self, "on_bird_flight_started")
self.connect("bird_flight_end", self, "on_bird_flight_ended")
self.connect("map_opened", self, "on_map_opened")
self.connect("map_closed", self, "on_map_closed")
2021-06-17 23:07:57 +02:00
2021-07-14 21:58:07 +02:00
func _process(delta):
2021-07-14 22:03:02 +02:00
if is_editor_active():
2021-07-14 20:11:20 +02:00
WorldCamera.offset = PlayerChar.position
2021-07-14 22:03:02 +02:00
WorldCamera.zoom = birdy_spring_x
2021-07-09 18:16:21 +02:00
if len(player_navigation_path) > 1:
var player_coord = Globals.WorldToHexCenter(PlayerChar.transform.origin)
if (player_coord - player_navigation_path[0]).length_squared() < 0.1:
player_navigation_path.remove(0)
if len(player_navigation_path) > 0:
PlayerChar.target = player_navigation_path[0]
2021-07-10 14:57:18 +02:00
update_current_island()
2021-07-11 16:09:04 +02:00
2021-07-10 14:57:18 +02:00
if current_island:
2021-07-11 16:09:04 +02:00
PlayerBoat.transform.origin = Globals.HexToWorld(anchor_tile)
2021-07-10 14:57:18 +02:00
else:
2021-07-11 16:09:04 +02:00
PlayerBoat.transform.origin = PlayerChar.transform.origin
2021-07-14 21:58:07 +02:00
var res = birdy_spring.calc(birdy_spring_x, birdy_spring_v, birdy_spring_xt, delta)
birdy_spring_x = res[0]
birdy_spring_v = res[1]
if BirdyTimer.time_left == 0:
birdy_spring_xt = Vector2.ONE
2021-07-09 14:17:25 +02:00
2021-07-20 22:44:13 +02:00
if birdy_spring_x.x > 1.2:
if bird_flying == false:
bird_flying = true
emit_signal("bird_flight_start")
elif birdy_spring_x.x < 1.1:
if bird_flying == true:
bird_flying = false
emit_signal("bird_flight_end")
2021-07-09 14:17:25 +02:00
2021-07-10 14:18:47 +02:00
func draw_hex_path (path: Array, color: Color):
var path_len = len(path)
if path_len > 0:
var last_point = path[0]
draw_circle(last_point, 5, color)
for i in range (1, path_len):
var cur_point = path[i]
draw_line (last_point, cur_point, color)
draw_circle(cur_point, 5, color)
2021-07-10 11:24:04 +02:00
last_point = cur_point
2021-07-10 14:57:18 +02:00
2021-07-10 14:18:47 +02:00
func _draw():
2021-07-11 16:09:04 +02:00
if Globals.debug_nav:
draw_hex_path (hex_line_path, "#00f2f2")
draw_hex_path (player_navigation_path, "#f200f2")
2021-07-10 14:18:47 +02:00
2021-07-11 16:09:04 +02:00
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")
2021-07-18 22:28:18 +02:00
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"))
2021-07-10 11:24:04 +02:00
#
# World Modification/Query
#
func clear_islands():
for island in Islands.get_children():
Islands.remove_child(island)
island.queue_free()
2021-07-16 12:07:11 +02:00
func clear_digsites():
for digsite in DigSites.get_children():
DigSites.remove_child(digsite)
digsite.queue_free()
2021-07-10 11:24:04 +02:00
2021-07-09 18:16:21 +02:00
func get_tile_type(world_coord: Vector2):
for island in Islands.get_children():
var tile = island.get_tile_by_world_coord(world_coord)
if tile != null:
return tile
return null
2021-07-09 14:17:25 +02:00
func add_island_at(file_name, offset_world: Vector2):
var island = Island.new()
island.load_island(file_name)
2021-07-20 22:44:13 +02:00
island.set_offset_world(offset_world)
2021-07-09 14:17:25 +02:00
Islands.add_child(island)
2021-07-14 22:03:02 +02:00
func is_editor_active():
return Editor == null or not Editor.is_active()
2021-07-16 12:07:11 +02:00
func check_player_on_treasure():
if current_island == null:
return false
return current_island.is_point_on_treasure_site(Globals.HexToWorld(PlayerChar.cur_tile))
2021-07-09 21:57:11 +02:00
func check_island_location_valid(new_island):
var grid_origin_world_coord = Globals.HexToWorld(Vector2(0,0))
if new_island.get_tile_by_world_coord(grid_origin_world_coord) != null:
return false
var islands = Islands.get_children()
for island in islands:
if island.check_overlap(new_island):
return false
return true
2021-07-10 11:24:04 +02:00
2021-07-09 21:57:11 +02:00
2021-07-16 10:38:57 +02:00
func place_treasure():
assert (treasure_island != null)
var island_tile_coords = treasure_island.tiles.keys()
var grass_tiles = []
for coord in island_tile_coords:
if treasure_island.tiles[coord] == "Grass":
grass_tiles.append(coord)
treasure_island.treasure_local_coords = grass_tiles[randi() % len(grass_tiles)]
2021-07-16 12:07:11 +02:00
if Globals.debug_nav:
treasure_island.highlight_treasure = true
2021-07-16 10:38:57 +02:00
treasure_island.update()
2021-07-18 22:28:18 +02:00
2021-07-14 21:38:35 +02:00
func render_treasure_map():
2021-07-16 10:38:57 +02:00
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.treasure_local_coords = treasure_island.treasure_local_coords
island.highlight_treasure = true
island.name = "island"
for child in IslandMapRenderer.get_children():
if child.name == "island":
print ("removing ", child)
IslandMapRenderer.remove_child(child)
child.queue_free()
break
2021-07-14 21:38:35 +02:00
2021-07-16 10:38:57 +02:00
IslandMapRenderer.add_child(island)
2021-07-14 21:38:35 +02:00
IslandMap.texture = IslandMapRenderer.get_texture()
2021-07-16 12:07:11 +02:00
func reset():
2021-07-09 22:19:23 +02:00
PlayerChar.transform.origin = Vector2.ZERO
PlayerChar.position = Vector2.ZERO
PlayerChar.target = Vector2.ZERO
2021-07-14 21:38:35 +02:00
2021-07-16 12:07:11 +02:00
hex_line_path = []
player_navigation_path = []
player_path_plan_start = null
player_path_plan_end = null
current_island = null
2021-07-14 21:38:35 +02:00
treasure_island = null
2021-07-09 22:19:23 +02:00
2021-07-16 12:07:11 +02:00
clear_islands()
clear_digsites()
SuccessMessage.visible = false
func generate():
reset()
var rng = RandomNumberGenerator.new()
rng.randomize()
2021-07-16 12:07:11 +02:00
randomize()
2021-07-09 14:17:25 +02:00
2021-07-09 21:57:11 +02:00
var radius = 800
2021-07-16 12:07:11 +02:00
var num_islands = 4
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):
var island = Island.new()
2021-07-16 12:07:11 +02:00
var file_name = island_files[i]
island.load_island(file_name)
2021-07-09 14:17:25 +02:00
var rand_coord = Vector2(rng.randi_range(-radius, radius), rng.randi_range(-radius, radius))
2021-07-20 22:44:13 +02:00
island.set_offset_world(Globals.WorldToHexCenter(rand_coord))
2021-07-09 14:17:25 +02:00
2021-07-09 18:16:21 +02:00
var location_valid = check_island_location_valid(island)
2021-07-09 14:17:25 +02:00
var overlap_retry_num = 0
var overlap_retry_max = 10
2021-07-09 21:57:11 +02:00
while !location_valid and overlap_retry_num < overlap_retry_max:
2021-07-09 14:17:25 +02:00
if overlap_retry_num % 4 == 0:
2021-07-09 21:57:11 +02:00
radius = radius + 200
2021-07-09 14:17:25 +02:00
overlap_retry_num = overlap_retry_num + 1
rand_coord = Vector2(rng.randi_range(-radius, radius), rng.randi_range(-radius, radius))
2021-07-20 22:44:13 +02:00
island.set_offset_world(Globals.WorldToHexCenter(rand_coord))
2021-07-09 18:16:21 +02:00
location_valid = check_island_location_valid(island)
2021-07-09 21:57:11 +02:00
if !location_valid:
print ("Could not place island! steps: " + str(overlap_retry_num))
else:
2021-07-09 14:17:25 +02:00
print ("Placed after " + str(overlap_retry_num) + " retries.")
Islands.add_child(island)
2021-07-11 16:09:04 +02:00
2021-07-14 21:38:35 +02:00
num_islands = Islands.get_child_count()
2021-07-16 12:07:11 +02:00
treasure_island = Islands.get_child(rng.randi() % num_islands)
2021-07-14 21:38:35 +02:00
2021-07-16 10:38:57 +02:00
place_treasure()
2021-07-14 21:38:35 +02:00
render_treasure_map()
2021-07-11 16:09:04 +02:00
populate_ocean_nav_grid()
2021-07-09 14:17:25 +02:00
2021-07-10 11:24:04 +02:00
#
# Navigation
#
2021-07-11 16:09:04 +02:00
func populate_ocean_nav_grid():
var obstacles = Globals.OceanNavGrid.get_obstacles()
Globals.OceanNavGrid.remove_obstacles(obstacles.keys())
Globals.OceanNavGrid.set_bounds(Vector2.ONE * -500, Vector2.ONE * 500)
2021-07-10 11:24:04 +02:00
for island in Islands.get_children():
for tile in island.tiles.keys():
var grid_coords = Globals.WorldToHex(tile + island.offset_world)
2021-07-11 16:09:04 +02:00
Globals.OceanNavGrid.add_obstacles(grid_coords, 0)
func populate_island_nav_grid():
var obstacles = Globals.IslandNavGrid.get_obstacles()
Globals.IslandNavGrid.remove_obstacles(obstacles.keys())
Globals.IslandNavGrid.set_bounds(Vector2.ONE * -500, Vector2.ONE * 500)
if current_island == null:
print ("Error: cannot populate island nav grid: no island")
return
2021-07-18 22:28:18 +02:00
var landing_site_coords = Globals.WorldToHex(current_island.landing_site_world)
2021-07-11 16:09:04 +02:00
for tile in current_island.obstacles_local_coords.keys():
var grid_coords = Globals.WorldToHex(tile + current_island.offset_world)
2021-07-18 22:28:18 +02:00
# Allow navigation to the anchor tile
if (grid_coords - anchor_tile).length() < 0.1:
continue
2021-07-11 16:09:04 +02:00
Globals.IslandNavGrid.add_obstacles(grid_coords, 0)
2021-07-10 14:57:18 +02:00
func update_current_island():
var islands = Islands.get_children()
var last_current_island = current_island
current_island = null
for island in islands:
if island.get_tile_by_world_coord(PlayerChar.position) != null:
current_island = island
break
if last_current_island != current_island:
if last_current_island != null:
2021-07-11 16:09:04 +02:00
on_leave_island(last_current_island)
2021-07-10 14:57:18 +02:00
if current_island != null:
2021-07-11 16:09:04 +02:00
on_enter_island(current_island)
2021-07-10 11:24:04 +02:00
2021-07-11 16:09:04 +02:00
func on_enter_island(island):
print ("Entering island")
2021-07-16 12:07:11 +02:00
PlayerChar.on_enter_island()
2021-07-11 16:09:04 +02:00
current_island = island
anchor_tile = PlayerChar.prev_tile
landing_tile = PlayerChar.cur_tile
island.landing_site_world = Globals.WorldToHexCenter(PlayerChar.position)
island.landing_site_local_coord = island.get_local_coord_by_world_coord(PlayerChar.position)
island.is_active = true
populate_island_nav_grid()
island.update()
2021-07-18 22:28:18 +02:00
if Globals.debug_nav:
update()
2021-07-11 16:09:04 +02:00
func on_leave_island(island):
print ("Leaving island")
2021-07-16 12:07:11 +02:00
PlayerChar.on_leave_island()
2021-07-11 16:09:04 +02:00
island.is_active = false
island.landing_site_local_coord = null
island.update()
2021-07-18 22:28:18 +02:00
if Globals.debug_nav:
update()
2021-07-11 16:09:04 +02:00
2021-07-16 12:07:11 +02:00
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:
2021-07-20 22:44:13 +02:00
emit_signal("wrong_digsite")
2021-07-16 12:07:11 +02:00
dig_site.texture = DigSiteSprite
DigSites.add_child(dig_site)
func on_treasure_found():
SuccessMessage.visible = true
2021-07-20 22:44:13 +02:00
func on_map_opened():
BirdyButton.disabled = true
DigButton.disabled = true
func on_map_closed():
BirdyButton.disabled = false
DigButton.disabled = false
func on_bird_flight_started():
print ("flight started")
DigButton.disabled = true
MapButton.disabled = true
func on_bird_flight_ended():
print ("flight ended")
DigButton.disabled = false
MapButton.disabled = false
2021-07-11 16:09:04 +02:00
func check_player_near_anchor():
if current_island == null:
return false
2021-07-10 14:18:47 +02:00
2021-07-11 16:09:04 +02:00
var anchor_world = Globals.HexToWorld(anchor_tile)
return (PlayerChar.position - anchor_world).length() < Globals.hex_size
2021-07-16 12:07:11 +02:00
2021-07-11 16:09:04 +02:00
func update_navigation_target_ocean(start_world: Vector2, target_world: Vector2):
2021-07-10 14:18:47 +02:00
var start_coord = Globals.WorldToHex(start_world)
2021-07-09 18:16:21 +02:00
var goal_coord = Globals.WorldToHex(target_world)
2021-07-11 16:09:04 +02:00
var island_landing_site_world = null
player_path_plan_start = null
player_path_plan_end = null
2021-07-09 18:16:21 +02:00
2021-07-11 16:09:04 +02:00
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:
2021-07-16 12:07:11 +02:00
# print ("on landing site: ", current_island.is_point_on_landing_site (start_world))
2021-07-11 16:09:04 +02:00
if current_island.is_point_on_landing_site (start_world):
if get_tile_type(direct_path[1]) == null:
2021-07-16 12:07:11 +02:00
# print ("starting from landing site")
2021-07-11 16:09:04 +02:00
direct_path.pop_front()
start_coord = Globals.WorldToHex(direct_path.front())
else:
print ("Invalid start")
return
# In case target is on an island we find both a landing site and
# the first point on the ocean that we can reach.
2021-07-10 14:18:47 +02:00
if get_tile_type(target_world) != null:
2021-07-10 14:57:18 +02:00
var last_removed = null
2021-07-11 16:09:04 +02:00
while len(direct_path) > 0 and get_tile_type(direct_path.back()) != null:
last_removed = direct_path.back()
direct_path.pop_back()
2021-07-10 14:18:47 +02:00
if len(direct_path) == 0:
print ("Could not find path!")
return
2021-07-16 12:07:11 +02:00
# print ("Using ", Globals.WorldToHex(direct_path.back()), " instead of ", goal_coord, " as goal.")
2021-07-11 16:09:04 +02:00
goal_coord = Globals.WorldToHex(direct_path.back())
island_landing_site_world = last_removed
2021-07-10 14:18:47 +02:00
2021-07-11 16:09:04 +02:00
player_path_plan_start = Globals.HexToWorld(start_coord)
player_path_plan_end = Globals.HexToWorld(goal_coord)
var path = Globals.OceanNavGrid.find_path(start_coord, goal_coord)
for target in path.slice(0,-1):
2021-07-09 22:19:23 +02:00
var target_world_coord = Globals.HexToWorld(target.axial_coords)
var target_type = get_tile_type(target_world_coord)
player_navigation_path.append(target_world_coord)
2021-07-10 14:57:18 +02:00
if target_type == "Sand":
break
2021-07-09 18:16:21 +02:00
2021-07-11 16:09:04 +02:00
if island_landing_site_world != null:
player_navigation_path.append(island_landing_site_world)
2021-07-10 14:57:18 +02:00
if len(player_navigation_path) > 0:
PlayerChar.target = player_navigation_path[0]
2021-07-11 16:09:04 +02:00
func update_navigation_target_island(start_world: Vector2, target_world: Vector2):
var start_coord = Globals.WorldToHex(start_world)
var goal_coord = Globals.WorldToHex(target_world)
var path = Globals.IslandNavGrid.find_path(start_coord, goal_coord)
for target in path.slice(0,-1):
var target_world_coord = Globals.HexToWorld(target.axial_coords)
var target_type = get_tile_type(target_world_coord)
player_navigation_path.append(target_world_coord)
func update_player_navigation_target(target_world: Vector2):
var start_world = PlayerChar.transform.origin
player_navigation_path = []
var start_timestamp = OS.get_system_time_msecs()
var player_near_anchor = check_player_near_anchor()
if current_island != null:
update_navigation_target_island(start_world, 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)
2021-07-18 22:28:18 +02:00
var planning_duration_msec = OS.get_system_time_msecs() - start_timestamp
2021-07-09 18:16:21 +02:00
2021-07-18 22:28:18 +02:00
if Globals.debug_nav:
update()
2021-07-10 11:24:04 +02:00
#
# Input & Events
#
func _on_generate_button_pressed():
2021-07-20 22:44:13 +02:00
emit_signal("world_generation_triggered")
2021-07-10 11:24:04 +02:00
generate()
2021-06-19 23:14:01 +02:00
func handle_game_event(event):
2021-07-14 20:11:20 +02:00
if Editor and Editor.is_active():
return false
2021-07-20 22:44:13 +02:00
if bird_flying:
return false
if event is InputEventMouseButton:
2021-06-17 23:03:45 +02:00
# Move main character
if event.pressed and event.button_index == BUTTON_LEFT:
2021-07-09 18:16:21 +02:00
update_player_navigation_target (Globals.HexGrid.get_hex_center(Globals.ScreenToHex(event.position, WorldCamera)))
return false
2021-06-28 21:51:09 +02:00
2021-07-10 14:18:47 +02:00
func update_hex_line_path(target: Vector2):
var start = PlayerChar.position
hex_line_path = Globals.WorldLineToHexTiles(start, target)
2021-06-19 23:14:01 +02:00
func _unhandled_input(event):
if event is InputEventMouseButton:
2021-07-10 14:57:18 +02:00
if handle_game_event(event):
2021-06-19 23:14:01 +02:00
return
2021-06-17 23:03:45 +02:00
# Move camera
2021-06-17 23:07:57 +02:00
if event.pressed and event.button_index == 2:
is_dragging = true
drag_start = (WorldCamera.offset / WorldCamera.zoom.x + event.position)
else:
is_dragging = false
2021-06-17 23:03:45 +02:00
# Zoom Camera
2021-06-28 21:51:09 +02:00
if event.pressed and event.button_index == BUTTON_WHEEL_DOWN and event.pressed and WorldCamera.zoom.y < 5.5:
WorldCamera.zoom = WorldCamera.zoom * 1.0 / 0.8
elif event.button_index == BUTTON_WHEEL_UP and event.pressed:
WorldCamera.zoom = WorldCamera.zoom * 0.8
if 'position' in event:
2021-06-28 21:51:09 +02:00
hex_hover = Globals.ScreenToHex(event.position, WorldCamera)
GridHighlight.pos = hex_hover
HexCoordValueLabel.text = str(hex_hover)
2021-07-09 18:16:21 +02:00
var world_coord = Globals.ScreenToWorld(event.position, WorldCamera)
var tile_type = get_tile_type(world_coord)
if tile_type != null:
TileTypeValueLabel.text = tile_type
else:
TileTypeValueLabel.text = "None"
2021-07-09 18:16:21 +02:00
WorldCoordValueLabel.text = str(world_coord)
2021-07-10 14:18:47 +02:00
update_hex_line_path(world_coord)
if is_dragging:
WorldCamera.offset = (drag_start - event.position) * WorldCamera.zoom.x
2021-06-28 21:51:09 +02:00
OffsetValueLabel.text = str(WorldCamera.offset)
ZoomValueLabel.text = str(WorldCamera.zoom)
2021-07-14 21:38:35 +02:00
func _on_MapButton_pressed():
IslandMap.visible = !IslandMap.visible
2021-07-14 21:58:07 +02:00
func _on_BirdyButton_pressed():
if birdy_spring_xt == Vector2.ONE:
birdy_spring_xt = Vector2.ONE * 4
BirdyTimer.one_shot = true
BirdyTimer.start(birdy_duration)
2021-07-18 16:59:23 +02:00
else:
BirdyTimer.stop()
birdy_spring_xt = Vector2.ONE
2021-07-14 21:58:07 +02:00
2021-07-16 12:07:11 +02:00
func _on_DigButton_pressed():
print ("dig pressed")
if PlayerChar.state == PlayerChar.State.Walking:
PlayerChar.on_dig_start()
2021-07-20 22:44:13 +02:00
func _on_IslandMap_visibility_changed():
if IslandMap.visible:
emit_signal("map_opened")
else:
emit_signal("map_closed")