diff --git a/scenes/BiomeNoiseTesting.tscn b/scenes/BiomeNoiseTesting.tscn index bb95677..f383cab 100644 --- a/scenes/BiomeNoiseTesting.tscn +++ b/scenes/BiomeNoiseTesting.tscn @@ -1,20 +1,20 @@ [gd_scene load_steps=3 format=3 uid="uid://d373de88jug8x"] [sub_resource type="FastNoiseLite" id="FastNoiseLite_ncuso"] -noise_type = 3 +noise_type = 0 seed = 35 -frequency = 0.008 -fractal_octaves = 3 -fractal_lacunarity = 1.0 -fractal_gain = 1.746 +fractal_octaves = 7 +fractal_lacunarity = 1.671 +fractal_gain = 0.947 fractal_ping_pong_strength = 25.0 domain_warp_fractal_type = 2 [sub_resource type="NoiseTexture2D" id="NoiseTexture2D_l3pkr"] -width = 1024 -height = 1024 +width = 256 +height = 256 noise = SubResource("FastNoiseLite_ncuso") [node name="BiomeNoise" type="Sprite2D"] -position = Vector2(528, 520) +position = Vector2(604, 592) +scale = Vector2(1.59375, 1.5625) texture = SubResource("NoiseTexture2D_l3pkr") diff --git a/scenes/Main.tscn b/scenes/Main.tscn index 50d3dfb..9e7d04e 100644 --- a/scenes/Main.tscn +++ b/scenes/Main.tscn @@ -39,7 +39,7 @@ anchor_right = 1.0 anchor_bottom = 1.0 grow_horizontal = 2 grow_vertical = 2 -mouse_filter = 2 +mouse_filter = 1 script = ExtResource("3_1t1c8") metadata/_edit_use_anchors_ = true @@ -111,11 +111,15 @@ anchor_left = 1.0 anchor_top = 1.0 anchor_right = 1.0 anchor_bottom = 1.0 +offset_left = -512.0 +offset_top = -512.0 grow_horizontal = 0 grow_vertical = 0 +mouse_filter = 1 script = ExtResource("5_rg28x") [node name="CameraMarker" type="Sprite2D" parent="UILayer/Control/Minimap"] +z_index = 1 position = Vector2(-32, 0) texture = ExtResource("7_w68w7") @@ -134,3 +138,6 @@ centered = false [connection signal="pressed" from="UILayer/Control/ConstructionPanel/button_demolish" to="UILayer/Control" method="_on_button_demolish_pressed"] [connection signal="pressed" from="UILayer/Control/ConstructionPanel/button_services" to="UILayer/Control" method="_on_button_services_pressed"] [connection signal="pressed" from="UILayer/Control/ConstructionPanel/button_social" to="UILayer/Control" method="_on_button_social_pressed"] +[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"] diff --git a/scripts/Control.gd b/scripts/Control.gd index dda4d6f..bc8a59b 100644 --- a/scripts/Control.gd +++ b/scripts/Control.gd @@ -29,7 +29,8 @@ func _process(_delta): str(get_viewport().get_mouse_position()) +"\n" + "FPS " + str(Engine.get_frames_per_second()) + "\n" + "Zoom lvl: " + str(Globals.CAMERA_ZOOM_LEVEL) + "\n" + - "Camera pos: " + str(Globals.CAMERA_POSITION) + "Camera pos: " + str(Globals.CAMERA_POSITION) + "\n" + + "Camera pos: " + str(Globals.camera_marker.position) ) # defines construction toolbar buttons diff --git a/scripts/Globals.gd b/scripts/Globals.gd index 2b80d57..6dc7aef 100644 --- a/scripts/Globals.gd +++ b/scripts/Globals.gd @@ -55,16 +55,18 @@ var map_tile_data:Array[Array] = [[]] # CAMERA SETTINGS # ################################### +var camera_marker + # GAME WINDOW DEFAULT SIZE const DEFAULT_X_RES:int = 1920 const DEFAULT_Y_RES:int = 1080 # current camera zoom level var CAMERA_ZOOM_LEVEL: float = 1.0 -var CAMERA_POSITION +var CAMERA_POSITION:Vector2i # camera movement settings -const CAMERA_MIN_ZOOM_LEVEL: float = 0.1 +const CAMERA_MIN_ZOOM_LEVEL: float = 0.5 const CAMERA_MAX_ZOOM_LEVEL: float = 2.0 const CAMERA_ZOOM_FACTOR: float = 0.1 const CAMERA_ZOOM_DURATION: float = 0.1 diff --git a/scripts/Minimap.gd b/scripts/Minimap.gd index 8883fed..8d9150a 100644 --- a/scripts/Minimap.gd +++ b/scripts/Minimap.gd @@ -1,24 +1,54 @@ class_name Minimap extends Control +signal set_camera_position(pos:Vector2) + @onready var minimap_texture:ImageTexture = null @onready var sprite:Sprite2D +var is_mouse_inside_minimap:bool = false + # Called when the node enters the scene tree for the first time. func _ready(): - self.minimap_texture = ImageTexture.new() + self.minimap_texture = ImageTexture.new() + + +func _draw(): + #self.draw_rect(Rect2i(Vector2i(1,1), Vector2i(514,514)), Color(0,0,0), false, 2.0) + pass # Called every frame. 'delta' is the elapsed time since the previous frame. func _process(_delta): - pass - + if !is_mouse_inside_minimap: + Globals.camera_marker.position = Vector2i( + Globals.CAMERA_POSITION.x / 8, + Globals.CAMERA_POSITION.y / 8, + ) + func _on_main_worldgen_ready(): self.generate_minimap() self.set_minimap() self.setup_camera_marker() + +func _on_mouse_entered(): + is_mouse_inside_minimap = true + +func _on_mouse_exited(): + is_mouse_inside_minimap = false + + +func _unhandled_input(event) -> void: + if is_mouse_inside_minimap: + if event is InputEventMouseButton and event.button_index == MOUSE_BUTTON_LEFT: + Globals.camera_marker.position = get_local_mouse_position() + emit_signal( + "set_camera_position", + get_local_mouse_position() * 8 + ) + func generate_minimap() -> void: var image = Image.new() @@ -63,8 +93,8 @@ func set_minimap() -> void: func setup_camera_marker() -> void: - var marker = self.find_child("CameraMarker") - marker.position = Vector2i(1000,500) + Globals.camera_marker = self.find_child("CameraMarker") + diff --git a/scripts/WorldGenerator.gd b/scripts/WorldGenerator.gd index ad6b4ad..da0d780 100644 --- a/scripts/WorldGenerator.gd +++ b/scripts/WorldGenerator.gd @@ -1,6 +1,11 @@ class_name WorldGenerator extends RefCounted + +# About biome generation with noise: https://www.redblobgames.com/maps/terrain-from-noise/ +# Trees with Poisson Disc: http://devmag.org.za/2009/05/03/poisson-disk-sampling/ + + var image:Image = Image.new() @@ -58,13 +63,13 @@ func choose_tile(tile:Vector2i, selected, surrounding) -> Array: func generate_biomes() -> void: # generate a new noisemap which should emulate forest-looking areas var fnl = FastNoiseLite.new() - fnl.noise_type = FastNoiseLite.TYPE_PERLIN + fnl.noise_type = FastNoiseLite.TYPE_SIMPLEX fnl.seed = 69 #randi() - fnl.frequency = 0.1 + fnl.frequency = 0.01 fnl.fractal_type = FastNoiseLite.FRACTAL_FBM - fnl.fractal_octaves = 3 - fnl.fractal_lacunarity = 1 - fnl.fractal_gain = 1.746 + fnl.fractal_octaves = 7 + fnl.fractal_lacunarity = 1.671 + fnl.fractal_gain = 0.947 var water_next_to_tile:bool = false @@ -84,7 +89,7 @@ func generate_biomes() -> void: # if there's no water next to a land tile, it can be replaced with forest if !water_next_to_tile: - var noise_sample = fnl.get_noise_2d(x,y) + var noise_sample = fnl.get_noise_2d(x, y) if noise_sample < 0.1: Globals.map_terrain_data[y][x] = Globals.TILE_FOREST # can add other tresholds here for other biomes