1. Imports XilonEngineII.NET
  2.  
  3. ''' <summary>
  4. ''' Xilon Engine II .NET sample/test app
  5. ''' </summary>
  6. ''' <remarks>This code sample and engine design is still under development and can change over time creating incompatible issues.</remarks>
  7. Module modMain
  8.  
  9. Private DataDirectory As IO.DirectoryInfo = (New IO.DirectoryInfo(My.Application.Info.DirectoryPath).Parent)
  10.  
  11. Private Engine As Xilon_EngineII
  12. 'XEII class
  13.  
  14. Private WithEvents frmTarget As Form
  15. 'the target (graphics display) to render to
  16.  
  17. Private mySprite As XEII_2DPhysicalSprite
  18. Private myFloor As XEII_2DPhysicalSprite
  19.  
  20. Private myTexture As XEII_Texture
  21.  
  22. Public Sub Main()
  23. Engine = New Xilon_EngineII
  24. 'create new XEII instance
  25.  
  26. Engine.Size = New Size(1024, 768)
  27. 'Engine.Fullscreen = True
  28.  
  29. Engine.Initialize()
  30. 'initalize engine (create DirectX 9 device);
  31. 'Settings should be changed before initializing engine; Default:
  32. ' Engine.Adapter: XEII_Adapter.Primary
  33. ' Engine.Behavior: XEII_EnumDeviceBehavior.DeviceBehavior_HardwareVertexProcessing
  34. ' Engine.ColorDepth: XEII_EnumColorDepth.ColorDepth_Adapterbpp
  35. ' Engine.Fullscreen: False
  36. ' Engine.RefreshRate: 60
  37. ' Engine.Size: Size(800, 600)
  38. ' Engine.Target: Form (Engine Creates Form)
  39. ' Engine.Type: XEII_EnumDeviceType.DeviceType_Hardware
  40. ' Engine.VSync: False
  41.  
  42. 'Engine.Renderer.FramesPerSecondLimit = 30
  43.  
  44. frmTarget = CType(Engine.Target, Form)
  45. 'get the form the engine created
  46. frmTarget.BackColor = Color.Black
  47. 'the backbuffer is black so make the form match
  48.  
  49. Engine.Scene2D.Physics.Gravity = New PointF(0.0F, 200.0F)
  50. 'apply a downward force (aka Gravity)
  51.  
  52. myFloor = New XEII_2DPhysicalSprite("myFloor", (Engine.Size.Width * 0.5F), Engine.Size.Height, Engine.Size.Width * 2.0F, 32, 0.5F, 0.4F, 0.4F)
  53. myFloor.Mass = Single.PositiveInfinity
  54. myFloor.IgnoreGravity = True
  55. Engine.Scene2D.World.Add(myFloor)
  56. 'create and add a floor for the boxes to land on
  57.  
  58. myTexture = New XEII_Texture("myBoxes", DataDirectory.FullName & "TexturesBladeBox.jpg", Color.Empty, XEII_Texture.XEII_EnumTextureFilter.Filter_LinearBilinear, 8, XEII_Texture.XEII_EnumTextureFilter.Filter_LinearBilinear)
  59. Engine.Data.Textures.Add(myTexture)
  60. 'create the box texture
  61. 'myTexture.Load()
  62.  
  63. mySprite = New XEII_2DPhysicalSprite("myCharacter", 0.5F, 0.4F, 0.4F)
  64. 'create a new physical sprite
  65. mySprite.Size = New SizeF(64, 64)
  66. 'set sprite to 64x64
  67. mySprite.Location = New PointF(Engine.Size.Width * 0.5F - 92, 32)
  68. 'set sprite location to center of screen (off by 92 pixels)
  69. mySprite.Visible = True
  70. 'sprite should be rendered
  71. mySprite.Mass = 20
  72. 'set sprite mass
  73.  
  74. mySprite.SetTexture(myTexture)
  75. 'link the sprite to the texture
  76.  
  77. 'Engine.Scene2D.Characters.Add(mySprite)
  78. 'add sprite to characters category
  79.  
  80. Dim x As Integer, y As Integer
  81. Dim sprTemp As XEII_2DPhysicalSprite
  82. For y = 0 To 9
  83. For x = -6 To 6
  84. sprTemp = New XEII_2DPhysicalSprite("mySprite_" & x.ToString() & "x" & y.ToString(), 0.5F, 0.4F, 0.4F)
  85. sprTemp.Size = New SizeF(64, 64)
  86. sprTemp.Location = New PointF(Engine.Size.Width * 0.5F - (x * 72), -(y * 72))
  87. sprTemp.Visible = True
  88. sprTemp.Mass = 10
  89.  
  90. sprTemp.SetTexture(myTexture)
  91.  
  92. Engine.Scene2D.Props.Add(sprTemp)
  93. If y = 0 Then XEII_2DPhysics.ApplyTorque(sprTemp, 950000)
  94. Next x
  95. Next y
  96.  
  97. Engine.Renderer.Start()
  98. 'start the engine renderer (the renderer is started in a different thread)
  99. 'myTexture.Load(True)
  100.  
  101. Engine.Scene2D.Physics.Start()
  102.  
  103. Application.Run()
  104. End Sub
  105.  
  106. Private Sub frmTarget_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles frmTarget.Click
  107.  
  108. End Sub
  109.  
  110. Private Sub frmTarget_DoubleClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles frmTarget.DoubleClick
  111. frmTarget.Close()
  112. 'double click equals end application
  113. End Sub
  114.  
  115. Private Sub frmTarget_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles frmTarget.FormClosing
  116. Engine = Nothing
  117. 'the engine handles destorying all objects in the pools
  118.  
  119. Application.Exit()
  120. End Sub
  121.  
  122. Private Sub frmTarget_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles frmTarget.KeyDown
  123. If Not mySprite Is Nothing Then
  124. If e.KeyCode = Keys.Right Then
  125. XEII_2DPhysics.ApplyTorque(mySprite, 1000000)
  126. ElseIf e.KeyCode = Keys.Left Then
  127. XEII_2DPhysics.ApplyTorque(mySprite, -1000000)
  128. ElseIf e.KeyCode = Keys.Up Then
  129. End If
  130. End If
  131. End Sub
  132. End Module