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

Imports System
Imports System.Collections.Generic
Imports System.Threading
Imports System.Drawing
Imports System.Drawing.Imaging
Imports System.IO

Imports OpenTK
Imports OpenTK.Graphics
Imports OpenTK.Graphics.OpenGL
Imports EZGL2D
Imports GL2DexampleJump.Game

Namespace GL2DexampleJump
	Public Class GL2Dexample ' inherit the GameWindow class
		Inherits GameWindow

		Private gameEngine As Game.Engine


		Public Sub New()
			MyBase.New(Constants.SCREEN_WIDTH, Constants.SCREEN_HEIGHT)

		End Sub

		Protected Overrides Sub OnLoad(ByVal e As EventArgs)
			MyBase.OnLoad(e)

			VSync = VSyncMode.On ' force vertical synching
			Title = "Sonic style game?  No problem!" ' set the title

            gameEngine = New Game.Engine(Me)
			gameEngine.load()

		End Sub

		Protected Overrides Sub OnResize(ByVal e As EventArgs)
			MyBase.OnResize(e)
			gameEngine.resize()
		End Sub

		Protected Overrides Sub OnUpdateFrame(ByVal e As FrameEventArgs)
			MyBase.OnUpdateFrame(e)

			gameEngine.update()

			' get input
			If Keyboard(OpenTK.Input.Key.Escape) Then
				Me.Exit()
				Return
			End If
		End Sub

		' This is where all rendering/drawing should be done
		Protected Overrides Sub OnRenderFrame(ByVal e As FrameEventArgs)
			MyBase.OnRenderFrame(e)

			gameEngine.render()

			Me.SwapBuffers() ' copy what we draw to screen

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

		End Sub

		' Draws a single cube

        <STAThread()> _
        Public Shared Sub Main()
            Using example As New GL2Dexample()
                example.Run(60) ' run the game at 60 frames per second
            End Using
        End Sub

	End Class
End Namespace
