/*
 *   EZ GL2D Platfom Game engine Example
 *   Source is provided "as is" without express or implied warranty of any kind.
 * 
*/

using System;
using System.Collections.Generic;
using System.Threading;
using System.Drawing;
using System.Drawing.Imaging;
using System.IO;

using OpenTK;
using OpenTK.Graphics;
using OpenTK.Graphics.OpenGL;
using EZGL2D;
using GL2DexampleJump.Game;

namespace GL2DexampleJump
{
    public class GL2Dexample : GameWindow  // inherit the GameWindow class
    {
        
        Game.Engine gameEngine;
        
        
        public GL2Dexample()
            : base(Constants.SCREEN_WIDTH, Constants.SCREEN_HEIGHT )
        {

        }

        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);

            VSync = VSyncMode.On;                           // force vertical synching
            Title = "Sonic style game?  No problem!";  // set the title
       
            gameEngine = new Game.Engine(this);
            gameEngine.load();

        }

        protected override void OnResize(EventArgs e)
        {
            base.OnResize(e);
            gameEngine.resize();
        }

        protected override void OnUpdateFrame(FrameEventArgs e)
        {
            base.OnUpdateFrame(e);

            gameEngine.update();
       
            // get input
            if (Keyboard[OpenTK.Input.Key.Escape])
            {
                this.Exit();
                return;
            }
        }

        // This is where all rendering/drawing should be done
        protected override void OnRenderFrame(FrameEventArgs e)
        {
            base.OnRenderFrame(e);

            gameEngine.render();
            
            this.SwapBuffers();     // copy what we draw to screen

            Thread.Sleep(1);        // sleep so that we don't hog CPU

        }

        // Draws a single cube
        
        [STAThread]
        public static void Main()
        {
            using (GL2Dexample example = new GL2Dexample())
            {
                example.Run(60);    // run the game at 60 frames per second
            }
        }

    }
}
