display minimap sprite as map background
This commit is contained in:
parent
d07708ff01
commit
d31fced182
15 changed files with 135 additions and 56 deletions
|
@ -1,9 +0,0 @@
|
|||
class_name Building
|
||||
extends TileMap
|
||||
|
||||
func _init():
|
||||
print("perse")
|
||||
|
||||
func _process(_delta):
|
||||
#position = get_viewport().get_mouse_position()
|
||||
pass
|
|
@ -1,7 +1,7 @@
|
|||
[gd_scene load_steps=3 format=3 uid="uid://sqvd1ev6ubp"]
|
||||
[gd_scene load_steps=3 format=3]
|
||||
|
||||
[ext_resource type="Texture2D" uid="uid://cxn2fno1j7vf5" path="res://icon.svg" id="1_pe5ue"]
|
||||
[ext_resource type="Script" path="res://scenes/Building.gd" id="1_uqlnt"]
|
||||
[ext_resource type="Script" path="res://scripts/Building.gd" id="1_uqlnt"]
|
||||
|
||||
[node name="Building" type="Sprite2D"]
|
||||
texture = ExtResource("1_pe5ue")
|
||||
|
|
|
@ -1,28 +0,0 @@
|
|||
extends Sprite2D
|
||||
|
||||
var size_multiplier
|
||||
var w_s
|
||||
var previous_camera_zoom
|
||||
|
||||
# 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 amera 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)
|
|
@ -1,54 +0,0 @@
|
|||
class_name Chunk
|
||||
extends TileMap
|
||||
|
||||
var x:int = -1
|
||||
var y:int = -1
|
||||
var should_remove:bool = false
|
||||
|
||||
|
||||
# Called when the node enters the scene tree for the first time.
|
||||
func _init(ypos:int, xpos:int, sr: bool):
|
||||
self.x = xpos
|
||||
self.y = ypos
|
||||
self.should_remove = sr
|
||||
|
||||
self.name = "Chunk [%d,%d]" % [x, y]
|
||||
self.set_tileset(Globals.TILESET_TERRAIN)
|
||||
self.position = Vector2i(
|
||||
x*Globals.CHUNK_SIZE.x*Globals.TILE_SIZE_X,
|
||||
y*Globals.CHUNK_SIZE.y*Globals.TILE_SIZE_Y
|
||||
)
|
||||
|
||||
|
||||
func _ready():
|
||||
generate_chunk()
|
||||
|
||||
|
||||
func _draw():
|
||||
self.draw_rect(
|
||||
Rect2(
|
||||
Vector2(0,0),
|
||||
Vector2(
|
||||
Globals.CHUNK_SIZE.x*Globals.TILE_SIZE_X,
|
||||
Globals.CHUNK_SIZE.y*Globals.TILE_SIZE_Y)
|
||||
),
|
||||
Color(0,0,0,0.5),
|
||||
false
|
||||
)
|
||||
|
||||
|
||||
func generate_chunk() -> void:
|
||||
for row in Globals.CHUNK_SIZE.y:
|
||||
for col in Globals.CHUNK_SIZE.x:
|
||||
var tile_data: Array = Globals.map_tile_data[row+y*Globals.CHUNK_SIZE.y][col+x*Globals.CHUNK_SIZE.x]
|
||||
# layer | tile coords at tilemap | tilemap id | coords of the tile at tileset | alternative tile
|
||||
self.set_cell(
|
||||
Globals.LAYER_TERRAIN,
|
||||
Vector2i(col, row),
|
||||
0,
|
||||
tile_data[0],
|
||||
tile_data[1]
|
||||
)
|
||||
|
||||
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
[gd_scene load_steps=8 format=3 uid="uid://nfayf78xiuap"]
|
||||
[gd_scene load_steps=9 format=3 uid="uid://b1bahdquscsym"]
|
||||
|
||||
[ext_resource type="Script" path="res://scripts/Main.gd" id="1_ysxum"]
|
||||
[ext_resource type="Script" path="res://scripts/ChunkHandler.gd" id="2_6cequ"]
|
||||
|
@ -6,7 +6,8 @@
|
|||
[ext_resource type="PackedScene" uid="uid://2we3txfr812u" path="res://scenes/Camera_zoom_2d.tscn" id="4_rx82t"]
|
||||
[ext_resource type="Script" path="res://scripts/EntityPlacer.gd" id="5_8jju5"]
|
||||
[ext_resource type="Script" path="res://scripts/Minimap.gd" id="5_rg28x"]
|
||||
[ext_resource type="Script" path="res://scenes/CameraMarker.gd" id="7_0s6ed"]
|
||||
[ext_resource type="Script" path="res://scripts/CameraMarker.gd" id="7_6krn1"]
|
||||
[ext_resource type="Script" path="res://scripts/MapBackground.gd" id="8_ron2j"]
|
||||
|
||||
[node name="Main" type="Node2D"]
|
||||
script = ExtResource("1_ysxum")
|
||||
|
@ -32,6 +33,11 @@ limit_smoothed = true
|
|||
rotation_smoothing_enabled = true
|
||||
editor_draw_limits = true
|
||||
|
||||
[node name="MapBackground" type="Sprite2D" parent="."]
|
||||
z_index = -1
|
||||
centered = false
|
||||
script = ExtResource("8_ron2j")
|
||||
|
||||
[node name="UILayer" type="CanvasLayer" parent="."]
|
||||
|
||||
[node name="Control" type="Control" parent="UILayer"]
|
||||
|
@ -124,7 +130,7 @@ script = ExtResource("5_rg28x")
|
|||
z_index = 1
|
||||
position = Vector2(-32, 0)
|
||||
centered = false
|
||||
script = ExtResource("7_0s6ed")
|
||||
script = ExtResource("7_6krn1")
|
||||
|
||||
[node name="MinimapSprite" type="Sprite2D" parent="UILayer/Control/Minimap"]
|
||||
texture_repeat = 1
|
||||
|
@ -135,6 +141,7 @@ centered = false
|
|||
[connection signal="worldgen_ready" from="." to="CameraZoom2D" method="_on_main_worldgen_ready"]
|
||||
[connection signal="worldgen_ready" from="." to="UILayer/Control/Minimap" method="_on_main_worldgen_ready"]
|
||||
[connection signal="worldgen_ready" from="." to="UILayer/Control/Minimap/CameraMarker" method="_on_main_worldgen_ready"]
|
||||
[connection signal="chunk_stats" from="ChunkHandler" to="UILayer/Control" method="_on_chunk_handler_chunk_stats"]
|
||||
[connection signal="camera_rotation_changed" from="CameraZoom2D" to="UILayer/Control/Minimap/CameraMarker" method="_on_camera_zoom_2d_camera_rotation_changed"]
|
||||
[connection signal="camera_zoom_changed" from="CameraZoom2D" to="UILayer/Control/Minimap/CameraMarker" method="_on_camera_zoom_2d_camera_zoom_changed"]
|
||||
[connection signal="pressed" from="UILayer/Control/ConstructionPanel/button_residental" to="UILayer/Control" method="_on_button_residental_pressed"]
|
||||
|
@ -147,3 +154,4 @@ centered = false
|
|||
[connection signal="mouse_entered" from="UILayer/Control/Minimap" to="UILayer/Control/Minimap" method="_on_mouse_entered"]
|
||||
[connection signal="mouse_exited" from="UILayer/Control/Minimap" to="UILayer/Control/Minimap" method="_on_mouse_exited"]
|
||||
[connection signal="set_camera_position" from="UILayer/Control/Minimap" to="CameraZoom2D" method="_on_set_camera_position"]
|
||||
[connection signal="set_map_background_texture" from="UILayer/Control/Minimap" to="MapBackground" method="_on_minimap_set_map_background_texture"]
|
||||
|
|
|
@ -24,3 +24,6 @@ position = Vector2(1480, 700)
|
|||
rotation = 0.523598
|
||||
scale = Vector2(2.6875, 2.60938)
|
||||
texture = SubResource("NoiseTexture2D_kpv1q")
|
||||
|
||||
[node name="TileMap" type="TileMap" parent="."]
|
||||
format = 2
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue