using Otter;
using System;

namespace LOoSE_sLOTS.utilities
{
    class Camera : Entity
    {
        private float _cameraOffset;
        private float _cameraSpeed;
        private float newCameraX = 0;
        private float newCameraY = 0;

        public Camera(float cameraOffset, float cameraSpeed)
        {
            _cameraOffset = cameraOffset;
            _cameraSpeed = cameraSpeed;
        }
        public void AdjustToPlayer(int mapWidth, int mapHeight, float playerX, float playerY)
        {
            this.Scene.CenterCamera(playerX, playerY);
            newCameraX = playerX - Global.GAME.Width / 2;
            newCameraY = playerY - Global.GAME.Height / 2;

            if (newCameraX < 0) newCameraX = 0;
            if (newCameraY < 0) newCameraY = 0;
            if (newCameraX > mapWidth - Global.GAME.Width) newCameraX = mapWidth - Global.GAME.Width;
            if (newCameraY > mapHeight - Global.GAME.Height) newCameraY = mapHeight - Global.GAME.Height;

            this.Scene.CameraX = Math.Abs(newCameraX);
            this.Scene.CameraY = Math.Abs(newCameraY);
        }
        public void FollowPlayer(int mapWidth, int mapHeight, float playerX, float playerY, float playerSpeed)
        {
            if (_cameraSpeed != playerSpeed) _cameraSpeed = playerSpeed;
            if (playerX - this.Scene.CameraX < 320 + _cameraOffset - _cameraSpeed)
            {
                if (this.Scene.CameraX > 0) this.Scene.CameraX -= _cameraSpeed;
            }
            else if ((this.Scene.CameraX + Global.GAME.Width) - playerX < 200 + _cameraOffset - _cameraSpeed)
            {
                if (this.Scene.CameraX + Global.GAME.Width < mapWidth) this.Scene.CameraX += _cameraSpeed;
            }
            if (playerY - 180 - this.Scene.CameraY < 10 + _cameraOffset - _cameraSpeed)
            {
                if (this.Scene.CameraY > 0) this.Scene.CameraY -= _cameraSpeed;
            }
            else if ((this.Scene.CameraY + Global.GAME.Height) - playerY < 90 + _cameraOffset - _cameraSpeed)
            {
                if (this.Scene.CameraY + Global.GAME.Height < mapHeight) this.Scene.CameraY += _cameraSpeed;
            }
        }
    }
}


