'
' *   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

Namespace GL2DexampleJump.Game
	Friend Class Engine
		Private gameWindow As GameWindow

		Private frame As Integer

		Private player As New Player()

		Private levelMap As New LevelMap()

		Private fontProto As New FontGL()

		Private tileImages() As GL2D.SpriteGL
		Private sonicImages() As GL2D.SpriteGL

		Public Sub New(ByVal gameWindow As GameWindow)
			Me.gameWindow = gameWindow
		End Sub

		Public Sub load()

			GL2D.Screen2D(gameWindow.Width, gameWindow.Height) ' reset the screen on load

			' Load our font
			fontProto.loadFont("data/EZGL2DexampleJump/protofont.png", 32, 32, CInt(TextureMinFilter.Nearest))

			tileImages = GL2D.LoadTileSet("data/EZGL2DexampleJump/tiles.png", 32, 32, CInt(TextureMinFilter.Nearest))
			sonicImages = GL2D.LoadSpriteSet("data/EZGL2DexampleJump/sonic.png", AtlasCoords.sonicTextureCoords.Length \ 4, AtlasCoords.sonicTextureCoords, CInt(TextureMinFilter.Nearest))
			levelMap.init(Constants.SCREEN_WIDTH \ Constants.TILE_SIZE, Constants.SCREEN_HEIGHT \ Constants.TILE_SIZE, Constants.TILE_SIZE, tileImages)
		End Sub

		Public Sub resize()
			GL2D.Screen2D(gameWindow.Width, gameWindow.Height) ' reset the screen every resize
		End Sub

		Public Sub update()
			frame += 1
			player.update(levelMap, gameWindow)
			levelMap.update(0)

		End Sub

		Public Sub render()
			GL2D.ClearScreen() ' clear the screen


			GL2D.Begin2D() ' start 2D drawing mode

				levelMap.renderMap()
				player.render(sonicImages)
				fontProto.print(32, 32, "[Arrow Keys]->Move") ' Wavy font
				fontProto.print(32, 64, "[Space]->Jump") ' Wavy font

			GL2D.End2D()

		End Sub


	End Class
End Namespace
