diff --git a/Levels/Scripts/Camera.gd b/Levels/Scripts/Camera.gd index 13edad7..e35a5d9 100644 --- a/Levels/Scripts/Camera.gd +++ b/Levels/Scripts/Camera.gd @@ -3,16 +3,36 @@ extends Camera3D const SCREEN_MARGIN : int = 150 +@export var curve : Curve + + +func _ready() -> void: + curve.bake() + func _process(_delta: float) -> void: var windowSize : Vector2i = get_window().size var mousePosition : Vector2 = get_viewport().get_mouse_position() if mousePosition.x < SCREEN_MARGIN: - position += Vector3(-0.05, 0, 0) + position.x += -0.05 if mousePosition.y < SCREEN_MARGIN: - position += Vector3(0, 0, -0.05) - if mousePosition.x > get_window().size.x - SCREEN_MARGIN: - position += Vector3(0.05, 0, 0) - if mousePosition.y > get_window().size.y - SCREEN_MARGIN: - position += Vector3(0, 0, 0.05) + position.z += -0.05 + if mousePosition.x > windowSize.x - SCREEN_MARGIN: + position.x += 0.05 + if mousePosition.y > windowSize.y - SCREEN_MARGIN: + position.z += 0.05 + + +func _input(event: InputEvent) -> void: + if not event is InputEventMouseButton: + return + + var newPosition : float = position.y + if event.button_index == MOUSE_BUTTON_WHEEL_UP: + newPosition = clampf(newPosition - .2, 2, 10) + elif event.button_index == MOUSE_BUTTON_WHEEL_DOWN: + newPosition = clampf(newPosition + .2, 2, 10) + + rotation.x = deg_to_rad(curve.sample(newPosition)) + position.y = newPosition diff --git a/Levels/world_manager.tscn b/Levels/world_manager.tscn index fdb0756..a6ca0b1 100644 --- a/Levels/world_manager.tscn +++ b/Levels/world_manager.tscn @@ -1,4 +1,4 @@ -[gd_scene load_steps=10 format=3 uid="uid://bph5gpic1arod"] +[gd_scene load_steps=11 format=3 uid="uid://bph5gpic1arod"] [ext_resource type="Script" uid="uid://qqid42jkpkmv" path="res://Levels/Scripts/WorldManager.gd" id="1_tk0a6"] [ext_resource type="Script" uid="uid://caf3yamufmhd4" path="res://Towers/TowerManager.gd" id="2_7pixp"] @@ -6,6 +6,11 @@ [ext_resource type="Texture2D" uid="uid://o83munu8dibp" path="res://Assets/Icones/kenney_game_icons_vector.svg" id="3_6dp1o"] [ext_resource type="PackedScene" uid="uid://p6a6rb7sgeqd" path="res://UI/gui.tscn" id="6_ebgat"] +[sub_resource type="Curve" id="Curve_c1rgm"] +_limits = [-70.0, -20.0, 2.0, 10.0] +_data = [Vector2(2, -20), 0.0, -12.5, 0, 1, Vector2(6, -70), 0.0, 0.0, 0, 0, Vector2(10, -70), 0.0, 0.0, 1, 0] +point_count = 3 + [sub_resource type="Animation" id="Animation_oyb16"] length = 0.001 tracks/0/type = "value" @@ -63,6 +68,7 @@ script = ExtResource("1_tk0a6") [node name="Camera3D" type="Camera3D" parent="."] transform = Transform3D(1, 0, 0, 0, 0.5, 0.866026, 0, -0.866026, 0.5, 0, 10, 0) script = ExtResource("2_c1rgm") +curve = SubResource("Curve_c1rgm") [node name="TowerManager" type="Node3D" parent="."] transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 4.73017, 0.728414, 0)