using System;
using System.Windows.Forms;
using System.Collections.Generic;
using System.Text;
using Microsoft.DirectX;
using System.Drawing;

namespace DirectXEksempel07
{
    class Model
    {
        private Engine theEngine;
        private Keys keyb;
        private Ground g;
        private Airplane ap1;
        private Building b1;
        private Building b2;

        public Keys Keyboard
        {
            get { return keyb; }
            set { keyb = value; }
        }

        public Model(Engine anEngine)
        {
            theEngine = anEngine;
            ap1 = new Airplane(this, theEngine.GetDevice(), new Vector3(0,5,0));
            g = new Ground(theEngine.GetDevice());
            b1 = new Building(theEngine.GetDevice(), new Vector3(-40, 20, 60), Color.DarkGray, 8, 40, 4);
            b2 = new Building(theEngine.GetDevice(), new Vector3(30, 40, 20), Color.DarkRed, 4, 80, 4);
        }

        public void Render()
        {
            b1.Render();
            b2.Render();
            g.Render();
            ap1.Render();
        }

        public void UpdateModel()
        {
            float radius = 1.0f;
            ap1.Update();
            // Check for collisions
            if (ap1.Position.Y - radius < 0.0f)
                MessageBox.Show("Hit the dirt");
            //MessageBox.Show("" + b1.LowerLeft);
            //MessageBox.Show("" + b1.UpperRight);
            if (ap1.Position.Z + radius > b1.LowerLeft.Z &
               ap1.Position.Z - radius < b1.UpperRight.Z &
               ap1.Position.X + radius > b1.LowerLeft.X &
               ap1.Position.X - radius < b1.UpperRight.X &
               ap1.Position.Y + radius < b1.UpperRight.Y)
            {
                MessageBox.Show("Building 1 crash");
            }
        }
    }
}
