a litle snake 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 snake game in vb.net

Post by karim1a2004 »

Imports Irrlicht
Imports Irrlicht.Core
Imports Irrlicht.Scene
Imports Irrlicht.Video
Imports Irrlicht.GUI
Imports Irrlicht.IO


Module Module1
Public device As New IrrlichtDevice(DriverType.OPENGL, New Dimension2D(640, 480), 16, False, True, False)
' Public MeshPlayer As IAnimatedMesh = device.SceneManager.GetMesh("..\..\..\media\model\q2mdl-magikoopa\magikoopa\tris.md2")
' Public MeshEnemy As IAnimatedMesh = device.SceneManager.GetMesh("C:\zip\irrlicht\vb\media\model\q2mdl-lemming\Lemming\tris.md2")

Public Meshbonus As IAnimatedMesh = device.SceneManager.GetMesh("..\..\..\media\earth2.x")
Public Bonus As ISceneNode = device.SceneManager.AddOctTreeSceneNode(Meshbonus, Nothing, -1)

Public Enemy(200) As IAnimatedMeshSceneNode
Public Player As IAnimatedMeshSceneNode = device.SceneManager.AddAnimatedMeshSceneNode(Meshbonus, Nothing, -1)
Public texEnemy As ITexture = device.VideoDriver.GetTexture("C:\zip\irrlicht\vb\media\model\q2mdl-lemming\Lemming\lemming.pcx")
Public Score As IGUIFont = device.GUIEnvironment.BuiltInFont

Public camm As New IsoCam
Public Colid As New Collision
Public Xc, Yc, Zc, NBb, Xc2(100), Yc2(100), Zc2(100) As Single
Public Spd, intDirection, I, iLen, iStep, Sc As Single

Public Xcb, Ycb, Zcb As Single


Sub Main()
device.EventReceiver = New MyEventReceiver
Dim MeshLand As IAnimatedMesh = device.SceneManager.GetMesh("..\..\..\media\land.3ds")
Dim Land As ISceneNode = device.SceneManager.AddOctTreeSceneNode(MeshLand, Nothing, -1)


Dim tex As ITexture = device.VideoDriver.GetTexture("C:\zip\irrlicht\vb\IrrTUTORIAL\hiiplane\wall.bmp")
Dim tex2 As ITexture = device.VideoDriver.GetTexture("..\..\..\media\model\q2mdl-magikoopa\magikoopa\magikoopa.pcx")
Dim texBonus As ITexture = device.VideoDriver.GetTexture("..\..\..\media\fire.bmp")

Xc = -50 : Yc = 50 : Zc = -350
Xcb = Int(Rnd() * 300) : Ycb = 20 : Zcb = Int(Rnd() * -250)
NBb = 10 : iLen = 1 : Sc = 0

For i = 1 To NBb
Enemy(I) = device.SceneManager.AddAnimatedMeshSceneNode(Meshbonus, Nothing, -1)
Xc2(I) = Xc : Yc2(I) = Yc : Zc2(I) = Zc

Next
Land.Position = New Core.Vector3D(0, 7, 0)
Land.SetMaterialTexture(0, tex)
Land.SetMaterialFlag(MaterialFlag.LIGHTING, False)

' Bonus.Scale = New Vector3D(4, 4, 4)
Bonus.Position = New Core.Vector3D(Xcb, 50, Zcb)
Bonus.SetMaterialTexture(0, texBonus)
Bonus.SetMaterialFlag(MaterialFlag.LIGHTING, False)
For I = 1 To NBb
Enemy(I).Position = New Core.Vector3D(Xc2(I), Yc2(I), Zc2(I))
Enemy(I).SetMaterialTexture(0, texEnemy)
Enemy(I).SetMaterialFlag(MaterialFlag.LIGHTING, False)
' Enemy(I).Scale = New Vector3D(8, 8, 8)
Next

Player.Position = New Core.Vector3D(Xc, Yc, Zc)
Player.SetMaterialTexture(0, tex2)
Player.SetMaterialFlag(MaterialFlag.LIGHTING, False)
'Player.Scale = New Vector3D(8, 8, 8)

camm.INITCamera(Player, device.SceneManager, 150, 150, 2)

While device.Run() = True
If device.WindowActive Then
device.VideoDriver.BeginScene(True, True, New Color(0, 100, 100, 100))

camm.Update()

MoveSnake()


If Colid.TestCollision(Player, Bonus.Position) Then
AddBody()
End If

End If
Score.Draw(Sc, New Position2D(10, 10), New Color(200, 200, 200, 200))

device.SceneManager.DrawAll()
device.VideoDriver.EndScene()
End While

End Sub
Public Sub AddBody()
NBb = NBb + 1
Sc = Sc + 10
Enemy(NBb) = device.SceneManager.AddAnimatedMeshSceneNode(Meshbonus, Nothing, -1)
Xc2(NBb) = Xc : Yc2(NBb) = Yc : Zc2(NBb) = Zc
Enemy(NBb).Position = New Core.Vector3D(Xc2(I), Yc2(I), Zc2(I))
Enemy(NBb).SetMaterialTexture(0, texEnemy)
Enemy(NBb).SetMaterialFlag(MaterialFlag.LIGHTING, False)
Xcb = Rnd() * 400 : Ycb = 20 : Zcb = Rnd() * 400
If Xcb > 400 Or Xcb < -450 Then Xcb = Int(Rnd() * 400)
If Zcb < -400 Or Zcb > 400 Then Zcb = Rnd() * 400
Bonus.Position = New Core.Vector3D(Xcb, 50, Zcb)
End Sub
Public Sub MoveSnake()
If Sc > -1 Then iStep = 1
If Sc > 50 Then iStep = 2
If Sc > 150 Then iStep = 4
If Sc > 250 Then iStep = 6
If Sc > 500 Then iStep = 8

If intDirection = 1 Then Xc = Xc + iStep 'right
If intDirection = 2 Then Xc = Xc - iStep 'left
If intDirection = 3 Then Zc = Zc + iStep 'down
If intDirection = 4 Then Zc = Zc - iStep 'up

If intDirection = 4 And Zc < -420 Then Zc = 420
If intDirection = 3 And Zc > 420 Then Zc = -420
If intDirection = 1 And Xc > 420 Then Xc = -420
If intDirection = 2 And Xc < -420 Then Xc = 420

If iLen > NBb Then iLen = 1

If intDirection = 1 Then
Xc2(iLen) = Xc - (iStep + 10)
Zc2(iLen) = Zc

End If
If intDirection = 2 Then
Xc2(iLen) = Xc + (iStep + 10)
Zc2(iLen) = Zc

End If
If intDirection = 3 Then
Zc2(iLen) = Zc - (iStep + 10)
Xc2(iLen) = Xc

End If
If intDirection = 4 Then
Zc2(iLen) = Zc + (iStep + 10)
Xc2(iLen) = Xc

End If

Player.Position = New Vector3D(Xc, Yc, Zc)
Enemy(iLen).Position = New Vector3D(Xc2(iLen), Yc2(iLen), Zc2(iLen))
iLen = iLen + 1
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 = 40 Then
intDirection = 3

End If
If e.Key = 39 Then
intDirection = 1


End If
If e.Key = 37 Then
intDirection = 2


End If
If e.Key = 38 Then
intDirection = 4




End If

Return True
End If

Return False
End Function


End Class
Locked