a litle game in vb.net

Irrlicht.Net is no longer developed or supported, Irrlicht.Net Cross Platform is a much more complete wrapper. Please ask your C# related questions on their forums first.
Locked
karim1a2004
Posts: 41
Joined: Sat Jan 15, 2005 8:03 pm
Contact:

a litle game in vb.net

Post by karim1a2004 »

Imports Irrlicht
Imports Irrlicht.Core
Imports Irrlicht.GUI
Imports Irrlicht.IO
Imports Irrlicht.Scene
Imports Irrlicht.Video
Module Module1
Public device As New IrrlichtDevice(DriverType.OPENGL, New Dimension2D(640, 480), 16, False, True, False)
Public cam As Scene.ICameraSceneNode = device.SceneManager.AddCameraSceneNode(Nothing, New Vector3D(-50, 150, -200), New Vector3D(0, -55, 200), -1)
Public Text As GUI.IGUIEnvironment
Public Xc, Yc, Zc, Xc2, Yc2, Zc2 As Single
Public Xb, Yb, Zb, Dbx, Dbz As Single
Public Sc, Lv As Integer


Sub Main()
device.EventReceiver = New MyEventReceiver
Dim MeshBar As IAnimatedMesh = device.SceneManager.GetMesh("..\..\..\media\bar.x")


Dim Mesh As IAnimatedMesh = device.SceneManager.GetMesh("..\..\..\media\land.3ds")
Dim MeshBall As IAnimatedMesh = device.SceneManager.GetMesh("..\..\..\media\ball.x")
Dim AnodeB As ISceneNode = device.SceneManager.AddOctTreeSceneNode(Mesh, Nothing, -1)
Dim Ball As ISceneNode = device.SceneManager.AddAnimatedMeshSceneNode(MeshBall, Nothing, -1)
Dim Bar As ISceneNode = device.SceneManager.AddAnimatedMeshSceneNode(MeshBar, Nothing, -1)
Dim Bar2 As ISceneNode = device.SceneManager.AddAnimatedMeshSceneNode(MeshBar, Nothing, -1)

Dim tex As ITexture = device.VideoDriver.GetTexture("C:\zip\irrlicht\vb\IrrTUTORIAL\hiiplane\wall.bmp")
Dim tex3 As ITexture = device.VideoDriver.GetTexture("..\..\..\media\item_01.bmp")
Dim tex4 As ITexture = device.VideoDriver.GetTexture("..\..\..\media\rockwall_height.bmp")

Dim tex2 As ITexture = device.VideoDriver.GetTexture("..\..\..\media\light02_broken.jpg")

Dim Bal As Core.Line3D
Dim v3dCollision As Core.Vector3D
Dim test As Core.Triangle3D

Xc = -50 : Yc = 10 : Zc = -350
Xc2 = -50 : Yc2 = 10 : Zc2 = 300
Xb = 100 : Yb = 30 : Zb = -100 : Dbx = 2 : Dbz = 2
Sc = 0 : Lv = 3


cam.Position = New Vector3D(-50, 300, -705)

Bar.Position = New Core.Vector3D(Xc, Yc, Zc)
Bar.SetMaterialTexture(0, tex2)
Bar.SetMaterialFlag(MaterialFlag.LIGHTING, False)

Bar2.Position = New Core.Vector3D(Xc2, Yc2, Zc2)
Bar2.SetMaterialTexture(0, tex2)
Bar2.SetMaterialFlag(MaterialFlag.LIGHTING, False)

Ball.Position = New Core.Vector3D(Xb, Yb, Zb)
Ball.SetMaterialTexture(0, tex3)
Ball.SetMaterialFlag(MaterialFlag.LIGHTING, False)
Ball.Scale = New Vector3D(1, 1, 1)

AnodeB.Position = New Core.Vector3D(0, 7, 0)
AnodeB.SetMaterialTexture(0, tex)
AnodeB.SetMaterialFlag(MaterialFlag.LIGHTING, False)
Dim Text As GUI.IGUIFont = device.GUIEnvironment.BuiltInFont
Dim Score As GUI.IGUIFont = device.GUIEnvironment.BuiltInFont
Dim Live As GUI.IGUIFont = device.GUIEnvironment.BuiltInFont
Dim Nbl As GUI.IGUIFont = device.GUIEnvironment.BuiltInFont

Dim Colid As New Collision

While device.Run() = True
If device.WindowActive Then
device.VideoDriver.BeginScene(True, True, New Color(0, 100, 100, 100))
Text.Draw("SCORE: ", New Position2D(10, 10), New Color(200, 200, 200, 200))
Score.Draw(Sc, New Position2D(47, 10), New Color(200, 200, 200, 200))
Live.Draw("LIVES: ", New Position2D(500, 10), New Color(200, 200, 200, 200))
Nbl.Draw(Lv, New Position2D(540, 10), New Color(200, 200, 200, 200))

Bar.Position = New Core.Vector3D(Xc, Yc, Zc)
If Xc2 < Ball.Position.X Then Xc2 += 2
If Xc2 > Ball.Position.X Then Xc2 -= 2
Bar2.Position = New Core.Vector3D(Xc2, Yc2, Zc2)

Move()

Ball.Position = New Core.Vector3D(Xb, Yb, Zb)

If Colid.TestCollision(Bar, Ball.Position) = True Then
Dbz = -Dbz
Sc = Sc + 10
End If


If Colid.TestCollision(Bar2, Ball.Position) = True Then Dbz = -Dbz

End If


device.SceneManager.DrawAll()

device.VideoDriver.EndScene()
If Sc = 100 Then
AnodeB.SetMaterialTexture(0, tex4)
Sc = 110
End If
If Sc = 200 Then
AnodeB.SetMaterialTexture(0, tex2)
Sc = 210
End If
If Sc = 500 Then
AnodeB.SetMaterialTexture(0, tex)
Sc = 510
End If

End While
End Sub
Public Sub Move()

If Xb > 400 Or Xb < -450 Then Dbx = -Dbx

If Zb < -400 Then
Lv = Lv - 1
Zb = -399 : Dbz = -Dbz

End If
If Zb > 400 Then End

Xb = Xb + Dbx : Zb = Zb + Dbz
End Sub

End Module
Public Class MyEventReceiver
Implements IEventReceiver

Public Function OnEvent(ByVal e As [Event]) As Boolean Implements IEventReceiver.OnEvent
If e.Type = EventType.KeyInput Then
'37=leftkey,38=upkey,39=rightkey,40=downkey,
If e.Key = 27 Then End
' If e.Key = 38 Then Yc -= 10
' If e.Key = 40 Then Yc += 10
If e.Key = 37 Then Xc -= 12
If e.Key = 39 Then Xc += 12
' Xc = e.MousePos.X

Return True
End If

Return False
End Function


End Class

the classe for the collissions

Imports Irrlicht.Core
Imports Irrlicht.Scene

Public Class Collision
Public Function TestCollision(ByVal NodeA As ISceneNode, ByVal Tpoint As Vector3D) As Boolean
Dim Cx, Cy, Cz As Boolean
Dim OBJbox As Box3D = NodeA.BoundingBox
Dim Pos As Vector3D = NodeA.Position


If (Tpoint.X > (Pos.X + OBJbox.MinEdge.X) And Tpoint.X < (Pos.X + OBJbox.MaxEdge.X)) Then Cx = True


If (Tpoint.Y > (Pos.Y + OBJbox.MinEdge.Y) And Tpoint.Y < (Pos.Y + OBJbox.MaxEdge.Y)) Then Cy = True

If (Tpoint.Z > (Pos.Z + OBJbox.MinEdge.Z) And Tpoint.Z < (Pos.Z + OBJbox.MaxEdge.Z)) Then Cz = True


If (Cx And Cy And Cz) Then Return True



End Function
End Class
Locked