display minimap sprite as map background

This commit is contained in:
Antti Hakkarainen 2023-02-15 21:13:24 +02:00
parent d07708ff01
commit d31fced182
15 changed files with 135 additions and 56 deletions

28
scripts/CameraMarker.gd Normal file
View file

@ -0,0 +1,28 @@
extends Sprite2D
var size_multiplier:float
var w_s:Vector2
# Draws a box represnting the camera view in minimap
func _draw():
draw_rect(Rect2(-w_s.x/2, -w_s.y/2, w_s.x, w_s.y), Color.GREEN, false, -3.0)
# Rotates the box if camera is rotated
func _on_camera_zoom_2d_camera_rotation_changed(new_rotation):
self.rotation = new_rotation
# Redraws the box to a different size if camera is zoomed
func _on_camera_zoom_2d_camera_zoom_changed(new_zoom_factor):
w_s = DisplayServer.window_get_size(0) / size_multiplier
w_s.x /= new_zoom_factor
w_s.y /= new_zoom_factor
queue_redraw()
# Sets the initial size of the camera box, after game is loaded
func _on_main_worldgen_ready() -> void:
size_multiplier = Globals.map_size / 32
w_s = DisplayServer.window_get_size(0) / size_multiplier