minimap: move camera with mouse, show camera pos on map
This commit is contained in:
parent
0f6343b44f
commit
14aa4f0e9a
6 changed files with 68 additions and 23 deletions
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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")
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue