using System.Collections.Generic;
using Vortex;
using Vortex.Drawing;
using Vortex.Input;
using System.Drawing;

namespace Vortex.Tutorials.ParallaxEffect {

    class ParallaxEffect : Game {
        private Texture image;
        private Camera2D camera;
        private Parallax parallax;

        public ParallaxEffect() {
            Window.Title = "Parallax Effect by Rafael Vasco - Vortex2D.NET";
            Window.Size = new Size(1024, 768);
            Window.Location = new Point(100, 100);

            Window.VerticalSync = true;

            camera = new Camera2D();
        }

        protected override void Load() {
            image = new Texture(@"{graphics}\sonic.png");

            parallax = new Parallax();
            parallax.AddLayer(image.ToSprite(), 0.1f);
            parallax.AddLayer(image.ToSprite(), 0.2f);
            parallax.AddLayer(image.ToSprite(), 0.4f);
            parallax.AddLayer(image.ToSprite(), 0.6f);
            parallax.AddLayer(image.ToSprite(), 0.8f);
            parallax.AddLayer(image.ToSprite(), 1.0f);

            base.Load();
        }

        protected override void Unload() {
            image.Dispose();
        }

        protected override void Update(GameTime time) {
            camera.Update();

            if (Keyboard.IsPressed(Key.Escape)) {
                Terminate();
            }

            if (Keyboard.IsDown(Key.Left)) {
                camera.MoveTo(camera.X - 50, camera.Y, 0.12f);
            }
            if (Keyboard.IsDown(Key.Right)) {
                camera.MoveTo(camera.X + 50, camera.Y, 0.12f);
            }
            if (Keyboard.IsDown(Key.Up)) {
                camera.MoveTo(camera.X, camera.Y - 50, 0.12f);
            }
            if (Keyboard.IsDown(Key.Down)) {
                camera.MoveTo(camera.X, camera.Y + 50, 0.12f);
            }
        }

        protected override void Render(Canvas2D canvas) {
            canvas.Clear(ColorU.Black);

            parallax.Render(canvas, camera.Pos);

            canvas.DrawText(SpriteFont.Console, new Vector2(100, 6), string.Format("Camera Position: {0}, Camera Active: {1}", camera.Pos, camera.Active), ColorU.Red);
        }
    }
}
