drawing treasure on map

master
Martin Felis 2021-07-16 10:38:57 +02:00
parent 6661c3073d
commit c94209ba7b
2 changed files with 40 additions and 24 deletions

View File

@ -4,7 +4,6 @@ var tiles = {}
var offset_world = Vector2.ZERO var offset_world = Vector2.ZERO
var center_coord = Vector2.ZERO var center_coord = Vector2.ZERO
var center_world_coord = Vector2.ZERO var center_world_coord = Vector2.ZERO
var tile_local_coords = []
var rect_local = Rect2() var rect_local = Rect2()
var radius_world = 0.0 var radius_world = 0.0
var is_active = false var is_active = false
@ -13,6 +12,8 @@ var landing_site_world = null
var ship_anchor_world = null var ship_anchor_world = null
var obstacles_local_coords = {} var obstacles_local_coords = {}
var treasure_local_coords = null
var highlight_treasure = 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():
@ -45,7 +46,6 @@ func calc_bbox():
var coords = tiles.keys() var coords = tiles.keys()
for coord in coords: for coord in coords:
var local_coords = (coord) var local_coords = (coord)
tile_local_coords.append(local_coords)
if local_coords.x < coord_min.x: if local_coords.x < coord_min.x:
coord_min.x = local_coords.x coord_min.x = local_coords.x
if local_coords.y < coord_min.y: if local_coords.y < coord_min.y:
@ -163,6 +163,10 @@ func _draw():
draw_set_transform (coord + offset_world, 0, Vector2.ONE) draw_set_transform (coord + offset_world, 0, Vector2.ONE)
draw_polygon(HexTileDrawer.HexPoints, HexTileDrawer.get_tile_color(tiles[coord])) draw_polygon(HexTileDrawer.HexPoints, HexTileDrawer.get_tile_color(tiles[coord]))
if treasure_local_coords and highlight_treasure:
draw_set_transform (treasure_local_coords + offset_world, 0, Vector2.ONE)
draw_polygon(HexTileDrawer.HexPoints, HexTileDrawer.create_color_array("#922"))
draw_set_transform(transform.origin + offset_world, transform.get_rotation(), transform.get_scale()) draw_set_transform(transform.origin + offset_world, transform.get_rotation(), transform.get_scale())
if Globals.debug_nav and is_active: if Globals.debug_nav and is_active:

View File

@ -153,28 +153,39 @@ func check_island_location_valid(new_island):
return true return true
func render_treasure_map(): func place_treasure():
if treasure_map_rendered == false: assert (treasure_island != null)
treasure_map_rendered = true var island_tile_coords = treasure_island.tiles.keys()
var grass_tiles = []
IslandMapRenderer.render_target_update_mode = Viewport.UPDATE_ONCE for coord in island_tile_coords:
IslandMapRenderer.render_target_clear_mode = Viewport.CLEAR_MODE_ONLY_NEXT_FRAME if treasure_island.tiles[coord] == "Grass":
var camera = IslandMapRenderer.get_node("Camera2D") grass_tiles.append(coord)
camera.current = true
camera.zoom = Vector2.ONE * 10.0 treasure_island.treasure_local_coords = grass_tiles[randi() % len(grass_tiles)]
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) 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
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
IslandMapRenderer.add_child(island)
IslandMap.texture = IslandMapRenderer.get_texture() IslandMap.texture = IslandMapRenderer.get_texture()
@ -185,7 +196,6 @@ func generate():
PlayerChar.target = Vector2.ZERO PlayerChar.target = Vector2.ZERO
treasure_island = null treasure_island = null
treasure_map_rendered = false
var rng = RandomNumberGenerator.new() var rng = RandomNumberGenerator.new()
rng.randomize() rng.randomize()
@ -226,6 +236,8 @@ func generate():
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(randi() % num_islands)
place_treasure()
render_treasure_map() render_treasure_map()
populate_ocean_nav_grid() populate_ocean_nav_grid()