fix minimap colors

This commit is contained in:
Antti Hakkarainen 2023-02-14 11:29:05 +02:00
parent 57d47c5eed
commit 63ea78592a
10 changed files with 155 additions and 92 deletions

View file

@ -1,5 +1,5 @@
class_name Minimap
extends Node
extends Control
@onready var minimap_texture:ImageTexture = null
@onready var sprite:Sprite2D
@ -15,15 +15,14 @@ func _process(_delta):
func _on_main_worldgen_ready():
print("test")
self.generate_minimap()
self.set_minimap()
func generate_minimap() -> void:
func generate_minimap() -> void:
var image = Image.new()
print(Globals.map_size)
image = Image.create(Globals.map_size, Globals.map_size, false, Image.FORMAT_RGB8)
image = Image.create(Globals.map_size, Globals.map_size, false, Image.FORMAT_RGBAF)
image.resize(Globals.map_size, Globals.map_size)
for y in Globals.map_size:
for x in Globals.map_size:
@ -31,24 +30,35 @@ func generate_minimap() -> void:
match Globals.map_terrain_data[y][x]:
Globals.TILE_WATER:
color = Color(0,0,255)
Globals.TILE_TERRAIN:
color = Color(148,113,71)
color = Globals.minimap_colors.get(Globals.TILE_WATER)
Globals.TILE_TERRAIN:
color = Globals.minimap_colors.get(Globals.TILE_TERRAIN)
Globals.TILE_FOREST:
color = Color(0,255,0)
color = Globals.minimap_colors.get(Globals.TILE_FOREST)
_: #default
color = Color(255,0,255)
color = Globals.minimap_colors.get("default")
image.set_pixel(x, y, color)
minimap_texture = ImageTexture.create_from_image(image)
minimap_texture = ImageTexture.create_from_image(image)
func set_minimap() -> void:
sprite = self.get_child(1)
sprite.texture = minimap_texture
sprite.set_scale(Vector2i(2,2))
sprite.set_position(Vector2(0, 0))
# Assuming the area has a child CollisionShape2D with a RectangleShape resource
var area_size = self.get_rect()
area_size = area_size.size
# The size of a sprite is determined from its texture
var texture_size = sprite.texture.get_size()
# Calculate which scale the sprite should have to match the size of the area
var sx = area_size.x / texture_size.x
var sy = area_size.y / texture_size.y
sprite.scale = Vector2(sx, sy)