using Otter;
using System;

namespace PpbbffttMiningHa.Utility
{
    class Camera : Entity
    {
        private readonly float _cameraOffset;
        private readonly 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)
        {
            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;

            Scene.CameraX = Math.Abs(newCameraX);
            Scene.CameraY = Math.Abs(newCameraY);
        }
        public void FollowPlayer(int mapWidth, int mapHeight, float playerX, float playerY, float playerSpeed)
        {
            //Scene.CameraX = playerX - 720;
            //Scene.CameraY = playerY - 480;
            /*if (_cameraSpeed != playerSpeed) _cameraSpeed = playerSpeed;
            if (playerX - Scene.CameraX < 320 + _cameraOffset - _cameraSpeed)
            {
                if (Scene.CameraX > 0) Scene.CameraX -= _cameraSpeed;
            }
            else if (Scene.CameraX + Global.GAME.Width - playerX < 200 + _cameraOffset - _cameraSpeed)
            {
                if (Scene.CameraX + Global.GAME.Width < mapWidth) Scene.CameraX += _cameraSpeed;
            }
            if (playerY - 180 - Scene.CameraY < 10 + _cameraOffset - _cameraSpeed)
            {
                if (Scene.CameraY > 0) Scene.CameraY -= _cameraSpeed;
            }
            else if (Scene.CameraY + Global.GAME.Height - playerY < 90 + _cameraOffset - _cameraSpeed)
            {
                if (Scene.CameraY + Global.GAME.Height < mapHeight) Scene.CameraY += _cameraSpeed;
            }*/
            //Console.WriteLine("mapWidth: {0}", mapWidth);
            //Console.WriteLine("mapHeight: {0}", mapHeight);
            //Console.WriteLine("playerX: {0}", playerX);
            //Console.WriteLine("playerY: {0}", playerY);
            //Console.WriteLine("playerSpeed: {0}", playerSpeed);
            //Console.WriteLine("cameraSpeed: {0}", _cameraSpeed);
            //this code is outdated? check the player update area for a better rendition of this.
        }
    }
}

