#Region Project Attributes
#ApplicationLabel: B4A Example
#VersionCode: 1
#VersionName:
'SupportedOrientations possible values: unspecified, landscape or portrait.
#SupportedOrientations: portrait
#CanInstallToExternalStorage: False
#End Region
#Region Activity Attributes
#FullScreen: False
#IncludeTitle: False
#End Region
Sub Process_Globals
'These global variables will be declared once when the application starts.
'These variables can be accessed from all modules.
DimGameStateAsByte
DimGameState_LoadingAsByte = 0
DimGameState_RunningAsByte = 1
DimGameState_PlayingAsByte = 2
End Sub
Sub Globals
'These global variables will be redeclared each time the activity is created.
'These variables can only be accessed from this module.
DimStatetimeAsFloat = 0
DimMovementSpeedAsFloat = 200
DimTouchPosAslgMathVector2
DimPositionAslgMathVector2
DimbgBackgroundAslgTexture
DimbgLoader AslgTexture
DimbgBalloon AslgTexture
DimbgFontAslgBitmapFont
DimLibGDXAsLibGDX
Dim GL As lgGL
DimGameViewAsView
DimbatchAslgSpriteBatch
DimcameraAslgOrthographicCamera
DimInputProcAslgInputProcessor
Dim vpWidth As Float = 480
DimvpHeightAsFloat = 800
Dimmovementx, movementyAsInt
DimsmoothingAsFloat
End Sub
Sub Activity_Create(FirstTime As Boolean)
'Do not forget to load the layout file created with the visual designer. For example:
'Activity.LoadLayout("Layout1")
Dim config AslgConfiguration
config.maxSimultaneousSounds = 4
config.useAccelerometer = False
config.useCompass = False
config.useWakelock = True
GameView = LibGDX.InitializeView2(config, "LibGDX")
Activity.AddView(GameView, 0dip, 0dip, Activity.Width, Activity.Height)
End Sub
Sub Activity_Resume
If LibGDX.IsInitialized Then LibGDX.Resume
End Sub
Sub Activity_Pause (UserClosed As Boolean)
If LibGDX.IsInitialized Then LibGDX.Pause
End Sub
Sub LibGDX_Create
'init sprite batch, will be use in rendering
batch.Initialize
'initialize asset
bgBackground.InitializeWithFile(LibGDX.Files.internal("bg/bg.png"))
bgLoader.InitializeWithFile(LibGDX.Files.internal("bg/default.png"))
bgBalloon.InitializeWithFile(LibGDX.Files.internal("balloons/baloon_blue.fw.png"))
bgFont.Initialize
bgFont.Scale(15)
InputProc.Initialize("InputProc")
Position.Set(vpWidth / 2, vpHeight / 2)
TouchPos.Set(vpWidth / 2, vpHeight / 2)
GameState = GameState_Loading
End Sub
Sub LibGDX_Dispose
bgBackground.dispose
End Sub
Sub LibGDX_Pause
End Sub
Sub LibGDX_Render
'clear screen
GL.glClearColor(0, 0, 0, 1)
GL.glClear(GL.GL10_COLOR_BUFFER_BIT)
'Updates the matrices of the camera
camera.Update
'Uses the coordinate system specified by the camera
batch.ProjectionMatrix = camera.Combined
IfGameState = GameState_LoadingThen
batch.Begin
Statetime = Statetime + LibGDX.Graphics.DeltaTime
If Statetime <= 5 Then
batch.DrawTex2(bgLoader, 0, 0, vpWidth, vpHeight)
Else
GameState = GameState_Running
EndIf
batch.End
Return
EndIf
'draw
batch.Begin
'elapse seconds
batch.DrawTex2(bgBackground, 0, 0, vpWidth, vpHeight)
MovePlayer
batch.DrawTex(bgBalloon, Position.x, Position.y)
' If TouchPos.x >= 0 AND TouchPos.y >= 0 Then
' batch.DrawTex(bgBalloon, TouchPos.x - bgBalloon.Width / 2, TouchPos.y - bgBalloon.Height / 2)
' Else
' batch.DrawTex(bgBalloon, Position.x - bgBalloon.Width / 2, Position.y - bgBalloon.Height / 2)
' End If
batch.End
End Sub
Sub MovePlayer
IfTouchPos.x <> Position.x ANDTouchPos.y <> Position.y Then
Dim smoothingx, smoothingy As Float
Ifmovementx > movementyThen
smoothingx = 1
smoothingy = smoothing
Else
smoothingx = smoothing
smoothingy = 1
EndIf
'Log("smoothingx " & smoothingx)
'Log("smoothingy " & smoothingy)
IfTouchPos.x > Position.x Then
'move right
Position.x = (Position.x + (MovementSpeed * smoothingx) * LibGDX.Graphics.DeltaTime)
'Position.x = (Position.x + smoothingy * LibGDX.Graphics.DeltaTime)
'Position.x = (Position.x + MovementSpeed * smoothingx)
ElseIfTouchPos.x < Position.x Then
'move left
Position.x = (Position.x - (MovementSpeed * smoothingx) * LibGDX.Graphics.DeltaTime)
'Position.x = (Position.x - smoothingy * LibGDX.Graphics.DeltaTime)
'Position.x = (Position.x - MovementSpeed * smoothingx)
Else
Position.x = TouchPos.x - bgBalloon.Width / 2
TouchPos.x = Position.x
EndIf
IfTouchPos.y > Position.y Then
'move up
Position.y = (Position.y + (MovementSpeed * smoothingy) * LibGDX.Graphics.DeltaTime)
'Position.y = (Position.y + smoothingx * LibGDX.Graphics.DeltaTime)
'Position.y = (Position.y + MovementSpeed * smoothingy)
ElseIfTouchPos.y < Position.y Then
'move down
Position.y = (Position.y - (MovementSpeed * smoothingy) * LibGDX.Graphics.DeltaTime)
'Position.y = (Position.y - smoothingx * LibGDX.Graphics.DeltaTime)
'Position.y = (Position.y - MovementSpeed * smoothingy)
Else
Position.y = TouchPos.y - bgBalloon.Height / 2
TouchPos.y = Position.y
EndIf
EndIf
End Sub
Sub LibGDX_Resize(Width As Int, Height As Int)
'init camera
camera.Initialize
camera.SetToOrtho2(False, vpWidth, vpHeight)
End Sub
Sub LibGDX_Resume
End Sub
Sub InputProc_TouchDown(ScreenX As Int, ScreenY As Int, Pointer As Int) As Boolean
'transform x and y location
TouchPos.x = vpWidth * (ScreenX / LibGDX.Graphics.Width)
TouchPos.y = vpHeight - (vpHeight * (ScreenY / LibGDX.Graphics.Height)) 'flip Y coords
Log("TouchPos.x: " & TouchPos.x)
Log("TouchPos.y: " & TouchPos.y)
IfPosition.x > TouchPos.x Then
movementx = Position.x - TouchPos.x
Else
movementx = TouchPos.x - Position.x
EndIf
IfPosition.y > TouchPos.y Then
movementy = Position.y - TouchPos.y
Else
movementy = TouchPos.y - Position.y
EndIf
'Log("MovementX " & movementx)
'Log("MovementY " & movementy)
Ifmovementx > movementyThen
smoothing = movementy / movementx
Else
smoothing = movementx / movementy
EndIf
'Log("smoothing " & smoothing)
ReturnFalse
End Sub