Updated VR example to show DebugRender

Updated VR example to show DebugRender

--HG--
extra : convert_revision : svn%3Ae934d3cd-0d57-f34a-94d0-9e8d31ae1c29/trunk%40170

Strict

Import diddy

Function Main:Int()
	game = New MyGame()
	Return 0
End

Global gameScreen:GameScreen

Class MyGame Extends DiddyApp
	Method OnCreate:Int()
		Super.OnCreate()

		images.Load("background.png", "", False)
		SetScreenSize(480, 320)

		gameScreen = new GameScreen
		gameScreen.PreStart()

		Return 0
	End
End

Class GameScreen Extends Screen
	Field backgroundImg:GameImage

	Method New()
		name = "Game"
	End

	Method Start:Void()
		game.screenFade.Start(50, false)
		backgroundImg = game.images.Find("background")
	End

	Method Render:Void()
		Cls
		backgroundImg.Draw(0, 0)
	End

	Method ExtraRender:Void()
		DrawText "This part of the render isnt affected by the virtual resolution!", 0, 10
		DrawText "but is affected by fading!", 0, 25
	End

	Method DebugRender:Void()
		Local starty% = 120
		Local height% = 20
		DrawText "This part of the render isnt affected by the virtual resolution or fading either!", 0, DEVICE_HEIGHT - starty
		starty-=height
		DrawText "Use the cursor keys to change the virtual resolution", 0, DEVICE_HEIGHT - starty
		starty-=height
		DrawText "Press Space to reset to 480 x 320", 0, DEVICE_HEIGHT - starty
		starty-=height
		DrawText "Device Width x Height = "+DEVICE_WIDTH+" x "+DEVICE_HEIGHT, 0, DEVICE_HEIGHT - starty
		starty-=height
		DrawText "Virtual Width x Height = "+FormatNumber(SCREEN_WIDTH, 3)+" x "+FormatNumber(SCREEN_HEIGHT,3), 0, DEVICE_HEIGHT - starty
	End

	Method Update:Void()
		If KeyDown(KEY_LEFT)
			SCREEN_WIDTH-=1*dt.delta
		End
		If KeyDown(KEY_RIGHT)
			SCREEN_WIDTH+=1*dt.delta
		End
		If KeyDown(KEY_UP)
			SCREEN_HEIGHT-=1*dt.delta
		End
		If KeyDown(KEY_DOWN)
			SCREEN_HEIGHT+=1*dt.delta
		End
		If KeyHit(KEY_SPACE)
			SCREEN_WIDTH = 480
			SCREEN_HEIGHT = 320
		End
		If KeyHit(KEY_ENTER)
			game.screenFade.Start(50, true)
			game.nextScreen = gameScreen
		End

		game.SetScreenSize(SCREEN_WIDTH, SCREEN_HEIGHT)
		If KeyHit(KEY_ESCAPE)
			game.screenFade.Start(50, true)
			game.nextScreen = game.exitScreen
		End
	End
End

Strict

Import diddy

Function Main:Int()
	game = New MyGame()
	Return 0
End

Global gameScreen:GameScreen

Class MyGame Extends DiddyApp
	Method OnCreate:Int()
		Super.OnCreate()

		images.Load("background.png", "", False)
		SetScreenSize(480, 320)

		gameScreen = new GameScreen
		gameScreen.PreStart()

		Return 0
	End
End

Class GameScreen Extends Screen
	Field backgroundImg:GameImage

	Method New()
		name = "Game"
	End

	Method Start:Void()
		game.screenFade.Start(50, false)
		backgroundImg = game.images.Find("background")
	End

	Method Render:Void()
		Cls
		backgroundImg.Draw(0, 0)
	End

	Method ExtraRender:Void()
		Local starty% = 120
		Local height% = 20
		DrawText "This part of the render isnt affected by the virtual resolution!", 0, DEVICE_HEIGHT - starty
		starty-=height
		DrawText "Use the cursor keys to change the virtual resolution", 0, DEVICE_HEIGHT - starty
		starty-=height
		DrawText "Press Space to reset to 480 x 320", 0, DEVICE_HEIGHT - starty
		starty-=height
		DrawText "Device Width x Height = "+DEVICE_WIDTH+" x "+DEVICE_HEIGHT, 0, DEVICE_HEIGHT - starty
		starty-=height
		DrawText "Virtual Width x Height = "+FormatNumber(SCREEN_WIDTH, 3)+" x "+FormatNumber(SCREEN_HEIGHT,3), 0, DEVICE_HEIGHT - starty

	End

	Method Update:Void()
		If KeyDown(KEY_LEFT)
			SCREEN_WIDTH-=1*dt.delta
		End
		If KeyDown(KEY_RIGHT)
			SCREEN_WIDTH+=1*dt.delta
		End
		If KeyDown(KEY_UP)
			SCREEN_HEIGHT-=1*dt.delta
		End
		If KeyDown(KEY_DOWN)
			SCREEN_HEIGHT+=1*dt.delta
		End
		If KeyHit(KEY_SPACE)
			SCREEN_WIDTH = 480
			SCREEN_HEIGHT = 320
		End
		If KeyHit(KEY_ENTER)
			game.screenFade.Start(50, true)
			game.nextScreen = gameScreen
		End

		game.SetScreenSize(SCREEN_WIDTH, SCREEN_HEIGHT)
		If KeyHit(KEY_ESCAPE)
			game.screenFade.Start(50, true)
			game.nextScreen = game.exitScreen
		End
	End
End


Fixed joystick. Thanks @programmerby

Fixed joystick. Thanks @programmerby

Strict

Import input
Import flixel.system.replay.xyzrecord

Class Joystick Extends Input

	Field unit:Int = 0

Private
#If TARGET = "bmax"
	Const _COUNT_INDEXS:Int = 1
#Else
	Const _COUNT_INDEXS:Int = 2
#End

	Field _x:Float[_COUNT_INDEXS]

	Field _y:Float[_COUNT_INDEXS]

	Field _z:Float[_COUNT_INDEXS]

Public
	Method New(unit:Int)
		Super.New(unit Shl 5 | KEY_JOY0, $20 | unit Shl 5 | KEY_JOY0)
		Self.unit = unit

		Local i:Int = 0

		While (i < _COUNT_INDEXS)
			_x[i] = 0
			_y[i] = 0
			_z[i] = 0

			i += 1
		Wend
	End Method

	Method Update:Void()
		Super.Update()

		Local i:Int = 0

		While (i < _COUNT_INDEXS)
			_x[i] = JoyX(i, unit)
			_y[i] = JoyY(i, unit)
			_z[i] = JoyZ(i, unit)

			i += 1
		Wend
	End Method

	Method Reset:Void()
		Local i:Int = 0

		While (i < _COUNT_INDEXS)
			_x[i] = 0
			_y[i] = 0
			_z[i] = 0

			i += 1
		Wend
	End Method

	Method Pressed:Bool(button:Int)
		Return Super.Pressed(button | unit Shl 5 | KEY_JOY0)
	End Method

	Method JustPressed:Bool(button:Int)
		Return Super.JustPressed(button | unit Shl 5 | KEY_JOY0)
	End Method

	Method JustReleased:Bool(button:Int)
		Return Super.JustReleased(button | unit Shl 5 | KEY_JOY0)
	End Method

	Method X:Float() Property
		Return _x[0]
	End Method

	Method Y:Float() Property
		Return _y[0]
	End Method

	Method Z:Float() Property
		Return _z[0]
	End Method

	Method X:Float(index:Int)
		Return _x[index]
	End Method

	Method Y:Float(index:Int)
		Return _y[index]
	End Method

	Method Z:Float(index:Int)
		Return _z[index]
	End Method

	Method RecordXYZ:XYZRecord[]()
		Local i:Int = 0
		Local data:XYZRecord[]

		While (i < _COUNT_INDEXS)
			If (_x[i] = 0 And _y[i] = 0 And _z[i] = 0) Then
				i += 1
				Continue
			End If

			If (data.Length() = 0) data = data.Resize(_COUNT_INDEXS)
			data[i] = New XYZRecord(_x[i], _y[i], _z[i])

			i += 1
		Wend

		Return data
	End Method

	Method PlaybackXYZ:Void(record:XYZRecord[])
		Local xyz:XYZRecord
		Local i:Int = 0
		Local l:Int = record.Length()

		While (i < l)
			xyz = record[i]

			_x[i] = xyz.x
			_y[i] = xyz.y
			_z[i] = xyz.z

			i += 1
		Wend
	End Method

End Class

Strict

Import input
Import flixel.system.replay.xyzrecord

Class Joystick Extends Input

	Field unit:Int = 0

Private
#If TARGET = "bmax"
	Const _COUNT_INDEXS:Int = 1
#Else
	Const _COUNT_INDEXS:Int = 2
#End

	Field _x:Float[_COUNT_INDEXS]

	Field _y:Float[_COUNT_INDEXS]

	Field _z:Float[_COUNT_INDEXS]

Public
	Method New(unit:Int)
		Super.New(unit Shl 4 | KEY_JOY0, $20 | unit Shl 4 | KEY_JOY0)
		Self.unit = unit

		Local i:Int = 0

		While (i < _COUNT_INDEXS)
			_x[i] = 0
			_y[i] = 0
			_z[i] = 0

			i += 1
		Wend
	End Method

	Method Update:Void()
		Super.Update()

		Local i:Int = 0

		While (i < _COUNT_INDEXS)
			_x[i] = JoyX(i, unit)
			_y[i] = JoyY(i, unit)
			_z[i] = JoyZ(i, unit)

			i += 1
		Wend
	End Method

	Method Reset:Void()
		Local i:Int = 0

		While (i < _COUNT_INDEXS)
			_x[i] = 0
			_y[i] = 0
			_z[i] = 0

			i += 1
		Wend
	End Method

	Method Pressed:Bool(button:Int)
		Return Super.Pressed(button | unit Shl 4 | KEY_JOY0)
	End Method

	Method JustPressed:Bool(button:Int)
		Return Super.JustPressed(button | unit Shl 4 | KEY_JOY0)
	End Method

	Method JustReleased:Bool(button:Int)
		Return Super.JustReleased(button | unit Shl 4 | KEY_JOY0)
	End Method

	Method X:Float() Property
		Return _x[0]
	End Method

	Method Y:Float() Property
		Return _y[0]
	End Method

	Method Z:Float() Property
		Return _z[0]
	End Method

	Method X:Float(index:Int)
		Return _x[index]
	End Method

	Method Y:Float(index:Int)
		Return _y[index]
	End Method

	Method Z:Float(index:Int)
		Return _z[index]
	End Method

	Method RecordXYZ:XYZRecord[]()
		Local i:Int = 0
		Local data:XYZRecord[]

		While (i < _COUNT_INDEXS)
			If (_x[i] = 0 And _y[i] = 0 And _z[i] = 0) Then
				i += 1
				Continue
			End If

			If (data.Length() = 0) data = data.Resize(_COUNT_INDEXS)
			data[i] = New XYZRecord(_x[i], _y[i], _z[i])

			i += 1
		Wend

		Return data
	End Method

	Method PlaybackXYZ:Void(record:XYZRecord[])
		Local xyz:XYZRecord
		Local i:Int = 0
		Local l:Int = record.Length()

		While (i < l)
			xyz = record[i]

			_x[i] = xyz.x
			_y[i] = xyz.y
			_z[i] = xyz.z

			i += 1
		Wend
	End Method

End Class