InputController example updated

InputController example updated

Strict

Import mojo.graphics
Import bono

Class Handler Extends Partial
    Private

    Field lastTouchDown:TouchEvent
    Field lastTouchMove:TouchEvent
    Field lastTouchUp:TouchEvent
    Field lastKeyDown:KeyEvent
    Field lastKeyPress:KeyEvent
    Field lastKeyUp:KeyEvent

    Public

    Method OnRender:Void()
        Cls()

        SetColor(255, 0, 0)
        If lastTouchDown Then RenderTouch(lastTouchDown)

        SetColor(0, 255, 0)
        If lastTouchMove Then RenderTouch(lastTouchMove)

        SetColor(0, 0, 255)
        If lastTouchUp Then RenderTouch(lastTouchUp)

        SetColor(255, 255, 255)
        If lastKeyDown Then DrawText("lastKeyDown: " + lastKeyDown.code, 100, 100)
        If lastKeyPress Then DrawText("lastKeyPress: " + lastKeyPress.code, 100, 120)
        If lastKeyUp Then DrawText("lastKeyUp: " + lastKeyUp.code, 100, 140)
    End

    Method OnTouchDown:Void(touch:TouchEvent)
        lastTouchDown = touch
    End

    Method OnTouchMove:Void(touch:TouchEvent)
        lastTouchMove = touch
    End

    Method OnTouchUp:Void(touch:TouchEvent)
        lastTouchUp = touch
    End

    Method OnKeyUp:Void(event:KeyEvent)
        lastKeyUp = event
    End

    Method OnKeyPress:Void(event:KeyEvent)
        lastKeyPress = event
    End

    Method OnKeyDown:Void(event:KeyEvent)
        lastKeyDown = event
    End

    Private

    Method RenderTouch:Void(touch:TouchEvent)
        SetAlpha(0.2)
        For Local pos:Vector2D = EachIn touch.positions
            DrawCircle(pos.x, pos.y, 10)
        End

        SetAlpha(1)
        DrawCircle(touch.pos.x, touch.pos.y, 10)
    End
End

Function Main:Int()
    Local director:Director = New Director(640, 480)
    director.inputController.touchRetainSize = 25
    director.Run(New Handler())

    Return 0
End

Strict

Import mojo.graphics
Import bono

Class Handler Extends Partial
    Private

    Field lastTouchDown:TouchEvent
    Field lastTouchMove:TouchEvent
    Field lastTouchUp:TouchEvent

    Public

    Method OnRender:Void()
        Cls()

        SetColor(255, 0, 0)
        If lastTouchDown Then RenderTouch(lastTouchDown)

        SetColor(0, 255, 0)
        If lastTouchMove Then RenderTouch(lastTouchMove)

        SetColor(0, 0, 255)
        If lastTouchUp Then RenderTouch(lastTouchUp)
    End

    Method OnTouchDown:Void(touch:TouchEvent)
        lastTouchDown = touch
    End

    Method OnTouchMove:Void(touch:TouchEvent)
        lastTouchMove = touch
    End

    Method OnTouchUp:Void(touch:TouchEvent)
        lastTouchUp = touch
    End

    Private

    Method RenderTouch:Void(touch:TouchEvent)
        SetAlpha(0.2)
        For Local pos:Vector2D = EachIn touch.positions
            DrawCircle(pos.x, pos.y, 10)
        End

        SetAlpha(1)
        DrawCircle(touch.pos.x, touch.pos.y, 10)
    End
End

Function Main:Int()
    Local director:Director = New Director(640, 480)
    director.Run(New Handler())

    Return 0
End


MultiVarTween autostart

MultiVarTween autostart

Strict

Import reflection
Import flixel.flxbasic
Import flixel.flxg
Import flixel.system.tweens.flxtween
Import flixel.system.tweens.util.ease

Class MultiVarTween Extends FlxTween

Private
	Field _vars:Stack<FieldInfo>

	Field _start:Stack<Float>

	Field _range:Stack<Float>

	Field _object:Object

Public
	Method New(complete:FlxTweenListener = Null, type:Int = -1)
		Super.New(0, type, complete)

		_vars = New Stack<FieldInfo>
		_start = New Stack<Float>
		_range = New Stack<Float>
	End Method

	Method Destroy:Void()
		_object = Null
		Super.Destroy()
	End Method

	Method Tween:Void(object:Object, properties:StringMap<Float>, duration:Float, ease:FlxEaseFunction = Null)
		_object = object

		_vars.Clear()
		_start.Clear()
		_range.Clear()

		Local classInfo:ClassInfo

		If (FlxBasic(object) <> Null) Then
			classInfo = FlxBasic(object).GetClass()

			If (FlxObject(object) <> Null) Then
				FlxObject(object).immovable = True
			End If
		Else
			classInfo = GetClass(object)
		End If

		_target = duration
		_ease = ease

		Local f:FieldInfo
		For Local prop:String = EachIn properties.Keys()
			f = classInfo.GetField(prop, True)
			If (f <> Null) Then
				If (f.Type.ExtendsClass(FloatClass()) Or f.Type.ExtendsClass(IntClass())) Then
					Local value:Float = UnboxFloat(f.GetValue(object))

					_vars.Push(f)
					_start.Push(value)
					_range.Push(properties.Get(f.Name) - value)
				Else
					FlxG.Log("WARNING: The property ~q" + prop + "~q is not numeric")
				End If
			Else
				FlxG.Log("WARNING: The ~q" + classInfo.Name + "~q does not have the property ~q" + prop + "~q, or it is not accessible")
			End If
		Next

		Start()
	End Method

	Method Update:Void()
		Super.Update()

		Local i:Int = _vars.Length()
		While (i > 0)
			i -= 1
			_vars.Get(i).SetValue(_object, BoxFloat(_start.Get(i) + _range.Get(i) * _t))
		Wend
	End Method

End Class

Strict

Import reflection
Import flixel.flxbasic
Import flixel.flxg
Import flixel.system.tweens.flxtween
Import flixel.system.tweens.util.ease

Class MultiVarTween Extends FlxTween

Private
	Field _vars:Stack<FieldInfo>

	Field _start:Stack<Float>

	Field _range:Stack<Float>

	Field _object:Object

Public
	Method New(complete:FlxTweenListener = Null, type:Int = -1)
		Super.New(0, type, complete)

		_vars = New Stack<FieldInfo>
		_start = New Stack<Float>
		_range = New Stack<Float>
	End Method

	Method Destroy:Void()
		_object = Null
		Super.Destroy()
	End Method

	Method Tween:Void(object:Object, properties:StringMap<Float>, duration:Float, ease:FlxEaseFunction = Null)
		_object = object

		_vars.Clear()
		_start.Clear()
		_range.Clear()

		Local classInfo:ClassInfo

		If (FlxBasic(object) <> Null) Then
			classInfo = FlxBasic(object).GetClass()

			If (FlxObject(object) <> Null) Then
				FlxObject(object).immovable = True
			End If
		Else
			classInfo = GetClass(object)
		End If

		_target = duration
		_ease = ease

		Local f:FieldInfo
		For Local prop:String = EachIn properties.Keys()
			f = classInfo.GetField(prop, True)
			If (f <> Null) Then
				If (f.Type.ExtendsClass(FloatClass()) Or f.Type.ExtendsClass(IntClass())) Then
					Local value:Float = UnboxFloat(f.GetValue(object))

					_vars.Push(f)
					_start.Push(value)
					_range.Push(properties.Get(f.Name) - value)
				Else
					FlxG.Log("WARNING: The property ~q" + prop + "~q is not numeric")
				End If
			Else
				FlxG.Log("WARNING: The ~q" + classInfo.Name + "~q does not have the property ~q" + prop + "~q, or it is not accessible")
			End If
		Next
	End Method

	Method Update:Void()
		Super.Update()

		Local i:Int = _vars.Length()
		While (i > 0)
			i -= 1
			_vars.Get(i).SetValue(_object, BoxFloat(_start.Get(i) + _range.Get(i) * _t))
		Wend
	End Method

End Class


Fixed the Adler32 demo.

Fixed the Adler32 demo.

Strict

Public

' Preprocessor related:
#ADLER32_DEMO_HEX = True

' Imports:
Import brl.databuffer

Import regal.hash.adler32

#If ADLER32_DEMO_HEX
	Import regal.retrostrings
#End

' Functions:
Function Main:Int()
	Local TestValue:String = "Hello world, this is a test."

	Local Buffer:= New DataBuffer(TestValue.Length)

	Buffer.PokeString(0, TestValue, "ascii")

	Local Hash:= Adler32(Buffer, Buffer.Length, 0, 1) ' 910C09CC

	#If ADLER32_DEMO_HEX
		Local DisplayValue:= Hex(Hash)
	#Else
		Local DisplayValue:= Hash
	#End

	Print("The Adler32 hash is: " + DisplayValue + " | " + TestValue)

	Buffer.Discard()

	Return 0
End

Strict

Public

' Preprocessor related:
#ADLER32_DEMO_HEX = True

' Imports:
Import regal.hash

#If ADLER32_DEMO_HEX
	Import regal.retrostrings
#End

' Functions:
Function Main:Int()
	Local TestValue:String = "Hello world, this is a test."

	Local Buffer:= New DataBuffer(TestValue.Length)

	Buffer.PokeString(0, TestValue, "ascii")

	Local Hash:= Adler32(Buffer, Buffer.Length, 0, 1) ' 910C09CC

	#If ADLER32_DEMO_HEX
		Local DisplayValue:= Hex(Hash)
	#Else
		Local DisplayValue:= Hash
	#End

	Print("The Adler32 hash is: " + DisplayValue + " | " + TestValue)

	Buffer.Discard()

	Return 0
End