Version 0.1 - 0.3.1
Added the World Added Mobs, and spawning those mobs at runtime Added simple camera movement Added simple UI/HUD
This commit is contained in:
41
scenes/camera_2d.gd
Normal file
41
scenes/camera_2d.gd
Normal file
@@ -0,0 +1,41 @@
|
||||
extends Camera2D
|
||||
|
||||
@export_group("Zoom")
|
||||
@export var _target_zoom: float = 1.0
|
||||
|
||||
func _ready() -> void:
|
||||
position = Vector2(500, 500)
|
||||
|
||||
func _unhandled_input(event: InputEvent) -> void:
|
||||
if event is InputEventMouseMotion:
|
||||
if event.button_mask == MOUSE_BUTTON_MASK_MIDDLE:
|
||||
position -= event.relative * zoom
|
||||
if event is InputEventMouseButton:
|
||||
if event.is_pressed():
|
||||
if event.button_index == MOUSE_BUTTON_WHEEL_DOWN:
|
||||
zoom_in()
|
||||
if event.button_index == MOUSE_BUTTON_WHEEL_UP:
|
||||
zoom_out()
|
||||
|
||||
@export_group("Zoom")
|
||||
@export var MIN_ZOOM: float = 0.1
|
||||
@export var MAX_ZOOM: float = 1.0
|
||||
@export var ZOOM_INCREMENT: float = 0.1
|
||||
|
||||
func zoom_in():
|
||||
_target_zoom = max(_target_zoom - ZOOM_INCREMENT, MIN_ZOOM)
|
||||
set_physics_process(true)
|
||||
|
||||
func zoom_out():
|
||||
_target_zoom = min(_target_zoom + ZOOM_INCREMENT, MAX_ZOOM)
|
||||
set_physics_process(true)
|
||||
|
||||
const ZOOM_RATE: float = 8.0
|
||||
|
||||
func _physics_process(delta: float) -> void:
|
||||
zoom = lerp(
|
||||
zoom,
|
||||
_target_zoom * Vector2.ONE,
|
||||
ZOOM_RATE * delta
|
||||
)
|
||||
set_physics_process(not is_equal_approx(zoom.x, _target_zoom))
|
||||
Reference in New Issue
Block a user