'
' *   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
	Public Class LevelMap
		Private tileAtlas() As GL2D.SpriteGL

		Private width As Integer = 0
		Private height As Integer = 0

		Private tileSize As Integer = 32


		Private map(,) As Integer

		Public Sub New()

		End Sub

		Public Sub init(ByVal width As Integer, ByVal height As Integer, ByVal tileSize As Integer, ByVal tileAtlas() As GL2D.SpriteGL)
			Me.tileAtlas = tileAtlas
			Me.width = width
			Me.height = height
			Me.tileSize = tileSize

			map = New Integer(width - 1, height - 1){}

			For y As Integer = 0 To height - 1
				For x As Integer = 0 To width - 1
					map(x,y) = 0
				Next x
			Next y

			Dim textMap() As String = { "++++++++++++++++++++", "+                  +", "+                  +", "+               ++++", "+       ##         +", "++++++         +   +", "+                  +", "+                  +", "+   ##### # #      +", "+                  +", "+              +++++", "+##                +", "+    ###  ++++     +", "+                  +", "+##################+"}

			For y As Integer = 0 To height - 1

				Dim len As Integer = textMap(y).Length
				For x As Integer = 0 To len - 1
                    Dim index As Integer = AscW(textMap(y).Chars(x))
					If index > 0 Then
                        Select Case index
                            Case AscW("#")
                                map(x, y) = 1
                            Case AscW("+")
                                map(x, y) = 2
                        End Select
					End If
				Next x
			Next y

		End Sub

		Public Sub fill(ByVal value As Integer)

			For y As Integer = 0 To height - 1
				For x As Integer = 0 To width - 1
					map(x,y) = value
				Next x
			Next y
		End Sub

		Public Sub update(ByVal speed As Single)
			updateMap(speed)
		End Sub

		Public Sub updateMap(ByVal speed As Single)

		End Sub

		Public Sub renderMap()

			For y As Integer = 0 To height - 1
				For x As Integer = 0 To width - 1
					Dim i As Integer = map(x,y) ' get map index
					If i > 0 Then

						Dim sx As Integer = (x * tileSize) 'Calculate where to put a
						Dim sy As Integer = (y * tileSize) 'particular tile
						GL2D.Sprite(sx, sy, GL2D.SpriteGL.FLIP_NONE, tileAtlas(i-1))

						'g.drawImage( tileAtlas[i-1], 
						'	 	     sx,
						'	 	     sy,
						'	 	     screen );

					End If
				Next x
			Next y


		End Sub

		Public Function getWidth() As Integer
			Return width
		End Function

		Public Function getHeight() As Integer
			Return height
		End Function

		Public Function getTileSize() As Integer
			Return tileSize
		End Function


		Public Sub setWidth(ByVal width As Integer)
			Me.width = width
		End Sub

		Public Sub setHeight(ByVal height As Integer)
			Me.height = height
		End Sub

		Public Sub setTileSize(ByVal tileSize As Integer)
			Me.tileSize = tileSize
		End Sub

		Public Function getMap() As Integer(,)
			Return map
		End Function

	End Class
End Namespace
