using System; using Godot; using static GameData; public partial class Camera3d : Camera3D { [Export] public float Speed = 7.5f; [Export] public float MouseSensitivity = 0.2f; [Export] public float ScrollStrength = 5.0f; private bool isShowingMap = false; private Vector3 previousPosition; private Vector2 _mouseDelta; public override void _Process(double delta) { if (canMove) MoveCamera(delta); if (Input.IsActionJustPressed("map")) { isShowingMap = !isShowingMap; canMove = !isShowingMap; if (isShowingMap) { previousPosition = Position; Position = new Vector3(layerSize * tileWidth / 2 - tileWidth / 2, 90 - visibleLayer * 4, layerSize * tileWidth / 2 - tileWidth / 2); RotationDegrees = new Vector3(-90, 0, 0); } else { Position = previousPosition; RotationDegrees = new Vector3(-75, 0, 0); } } } public void MoveCamera(double delta) { float d = (float)delta; var rotation = RotationDegrees; rotation.X = Mathf.Clamp(rotation.X, -90f, 90f); RotationDegrees = rotation; _mouseDelta = Vector2.Zero; Vector3 direction = Vector3.Zero; if (Input.IsActionPressed("move_forward") && Position.Z > 0) direction += Transform.Basis.Z; if (Input.IsActionPressed("move_backward") && Position.Z < layerSize * 6) direction -= Transform.Basis.Z; if (Input.IsActionPressed("move_left") && Position.X > 0) direction -= Transform.Basis.X; if (Input.IsActionPressed("move_right") && Position.X < layerSize * 6) direction += Transform.Basis.X; if (direction != Vector3.Zero) { direction = direction.Normalized() * Speed * (Input.IsActionPressed("sprint") ? 2.5f : 1) * d; Translate(direction); } if (Position.Y != 10 - visibleLayer * 4) { Position = new Vector3(Position.X, 10 - visibleLayer * 4, Position.Z); } } }