using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using HumanLikeBattleRobots.Graphic;

namespace HumanLikeBattleRobots.Logic
{
    class Screen
    {
        private Vec2f globalPosition;
        private GroundSprite[,] groundSprites = new GroundSprite[3, 3];

        BushSprite bush;

        private static int screenWidth = 768;

        public Vec2f upLeftCorner
        {
            get
            {
                return (globalPosition - new Vec2f(0.5f, 0.5f)) * screenWidth;
            }
        }
        public Vec2f downRightCorner
        {
            get
            {
                return (globalPosition + new Vec2f(0.5f, 0.5f)) * screenWidth;
            }
        }

        public Screen(Vec2f position)
        {
            globalPosition = position;
            for (int i = 0; i < 3; i++)
                for (int j = 0; j < 3; j++)
                {
                    groundSprites[i, j] = new GroundSprite(0);
                    groundSprites[i, j].Position = this.upLeftCorner + new Vec2f(i, j) * 256; //MAGIC NUMBER!
                }

            if (globalPosition.Length() > 1.5)
            {
                EnemyRobot newRobot;
                for (int i = 0; i < (int)(GameManager.enemiesKilled/7 + 1); i++)
                {
                    newRobot = new RoboSoldier(upLeftCorner + new Vec2f(0, 150 * i));
                    GameManager.enemyRobots.Add(newRobot);
                    GameManager.myRobot.OnMove += newRobot.OnMyRobotMove;
                    GameManager.collidable.Add(newRobot);
                }

                for (int i = 0; i < 2 * (int)(GameManager.enemiesKilled / 7 + 1); i++)
                {
                    newRobot = new RoboBomb(upLeftCorner + new Vec2f(15 * i, 60 * i));
                    GameManager.enemyRobots.Add(newRobot);
                    GameManager.myRobot.OnMove += newRobot.OnMyRobotMove;
                    GameManager.collidable.Add(newRobot);
                }
            }
            new Box(downRightCorner);
        }

        public void Draw()
        {
            for (int i = 0; i < 3; i++)
                for (int j = 0; j < 3; j++)
                    groundSprites[i, j].Draw();
        }

        public static Vec2f GetCurrentScreen(Vec2f position)
        {
            Vec2f result = new Vec2f(0, 0);
            result.X = (float)Math.Round(position.X / screenWidth);
            result.Y = (float)Math.Round(position.Y / screenWidth);
            return result;
        }

    }
}
