Sub Class_Globals
Private Ground As X2BodyWrapper
Dim blocksize As Int
End Sub
Public Sub Initialize (Parent As B4XView)
Parent.LoadLayout("GameLayout")
X2.Initialize(Me, ivForeground)
world = X2.World
X2.ConfigureDimensions(world.CreateVec2(5, 0),10)
X2.EnableDebugDraw
StartGame
End Sub
Public Sub StartGame
If X2.IsRunning Then Return
X2.UpdateWorldCenter(X2.CreateVec2(X2.ScreenAABB.Width/2,X2.ScreenAABB.Height/2))
X2.Start
blocksize=X2.ScreenAABB.Width/10
Dim sprites As List = X2.ReadSprites(xui.LoadBitmap(File.DirAssets, "crate.png"), 1, 1,blocksize,blocksize)
X2.GraphicCache.PutGraphic("crate", sprites)
CreateGround
Create_Bullet
For y=0 To 9
Create_Crate(0,y*blocksize)
Next
End Sub
Private Sub CreateGround
Dim GroundBox As B2Vec2 = X2.CreateVec2(9.60, 0)
Dim bd As B2BodyDef
bd.BodyType = bd.TYPE_STATIC
bd.Position = X2.CreateVec2(X2.ScreenAABB.Center.X, X2.ScreenAABB.BottomLeft.Y + GroundBox.Y / 2)
Ground = X2.CreateBodyAndWrapper(bd, Null, "Ground")
Dim rect As B2PolygonShape
rect.Initialize
rect.SetAsBox(GroundBox.X / 2, GroundBox.Y / 2)
Ground.Body.CreateFixture2(rect, 1)
End Sub
Private Sub Create_Bullet
Dim bd As B2BodyDef
bd.BodyType = bd.TYPE_DYNAMIC
bd.Position = X2.CreateVec2(0,2)
Dim wrapper As X2BodyWrapper = X2.CreateBodyAndWrapper(bd,Null, "crate")
wrapper.GraphicName = "crate"
Dim size As B2Vec2 = X2.GraphicCache.GetGraphicSizeMeters("crate", 0)
Dim rect As B2PolygonShape
rect.Initialize
rect.SetAsBox(size.X / 2, size.Y / 2)
wrapper.Body.CreateFixture2(rect, 1)
wrapper.Body.ApplyLinearImpulse(X2.CreateVec2(10,10),X2.CreateVec2(0,0))
End Sub
Private Sub Create_Crate(x As Int, y As Int)
Dim size As B2Vec2 = X2.GraphicCache.GetGraphicSizeMeters("crate", 0)
Dim xoffset,yoffset As Double
Dim bd As B2BodyDef
yoffset=blocksize/2
xoffset=X2.ScreenAABB.Width-blocksize
bd.BodyType = bd.TYPE_DYNAMIC
bd.Position = X2.CreateVec2(xoffset + x*size.x,yoffset + y*size.y)
Dim wrapper As X2BodyWrapper = X2.CreateBodyAndWrapper(bd,Null, "crate")
wrapper.GraphicName = "crate"
Dim rect As B2PolygonShape
rect.Initialize
rect.SetAsBox(size.X / 2, size.Y / 2)
wrapper.Body.CreateFixture2(rect, 2.0)
End Sub