Search Home Members Contacts
About Us
Products
Downloads
Community
Support
Pages: [1]
  Print  
Author Topic: Random Maze Generator  (Read 5272 times)
BYTE-Smasher
Community Member
*
Posts: 956

vaporware makes baby jesus cry


WWW
« on: August 06, 2004, 10:21:59 AM »

I've made a random maze generator... why? because I was bored.... here's a screenie... lemme know if you guys want source... I'll post a class for it l8r if you do...
[/img]
Logged

darqSHADOW
Administrator
Community Member
*****
Posts: 2817


« Reply #1 on: August 06, 2004, 10:32:32 AM »

Heh, that's pretty cool!  I'd like a copy of the source, if you make it available.  I am sure I can think of a few mini-games to make using this.  Wink

Is the maze always solvable?  If not, no biggy, it looks amazing...

DS
Logged

TrueVision3D Project Manager
The fast and simple way of 3D development.
BYTE-Smasher
Community Member
*
Posts: 956

vaporware makes baby jesus cry


WWW
« Reply #2 on: August 06, 2004, 10:37:55 AM »

the maze is always solveable... in fact, there's always a way to get to every room in the maze... so you can pretty much make any room the start+end points...

the only problem with the source as it stands right now is the 10 second generating time... this is the first project I've ever had a legitimate loading screen for... (addwall is kinda slow :shock: ) ... and i don't have it wrapped up nicely yet... I'm a messy coder who cleans up when I'm done  :lol:
Logged

darqSHADOW
Administrator
Community Member
*****
Posts: 2817


« Reply #3 on: August 06, 2004, 11:41:06 AM »

Ah that'd work perfectly for the project I started last nite, then.  I'd most likely need to be able to add "avoid locations" so it doesn't place walls at certain locations, but other than that it sounds great.  I'm hoping to get a mini-game done in 6.5 completed shortly, so we can show off a few key features, and generate a bit more interest.  And it'll let me see if AddWall is any faster on 6.5 then in 6.2...  =)

DS
Logged

TrueVision3D Project Manager
The fast and simple way of 3D development.
Zaknafein
Customers
Community Member
*****
Posts: 2940


WWW
« Reply #4 on: August 06, 2004, 11:53:19 AM »

That is really cool... I wish I could do such cool things when I'm bored Wink
Logged

newborn
Customers
Community Member
*****
Posts: 2451


WWW
« Reply #5 on: August 06, 2004, 04:03:55 PM »

thats a very nice base for a random dungeon creator!
Logged

Dimple
Community Member
*
Posts: 580


« Reply #6 on: August 07, 2004, 11:50:53 AM »

Tongue

BYTE-Smasher

I think you can take it as a given by those other posts, that TV3D users would like to get the source code for it.  Heh!  I know I would!!
Logged

Using VB.NET, TV3D 6.5, VISTA
~~~~~~~~~~~~~~~~~~~~~~~

"Know how to ask. There is nothing more difficult for some people, nor for others, easier."

- Baltasar Gracian
roodie
Community Member
*
Posts: 3


« Reply #7 on: August 07, 2004, 03:53:25 PM »

Hmm, I would like to see that source definitely ;-)
Logged
GoodVillain
Community Member
*
Posts: 1631


« Reply #8 on: August 07, 2004, 04:50:40 PM »

Quote from: "newborn"
thats a very nice base for a random dungeon creator!

More of a random maze generator. But with a little modding I am sure you can make a really cool dungeon generator. IE: Have it randomly place traps, mobs, items, doors, ect. Sort of like that old DOS game called Dungeon Hack. Smiley
Logged
BYTE-Smasher
Community Member
*
Posts: 956

vaporware makes baby jesus cry


WWW
« Reply #9 on: August 09, 2004, 08:14:13 AM »

actually, I'm slowly making it into a game-like entity.... I was fooling around on the weekend, got collision detection working on it... (took me forever... don't have gravity implemented yet... I'm starting to hate collision....) and added a gun... can shoot spheres now... I'll post the raw (NOT CLEAN) source for the project below... let ppl at least see what I've done... I've got dead-end detection too... either way... yah... here it is:

Code:

Dim CPU As New TVEngine
Dim Scene As New TVScene
Dim Column As New TVMesh
Dim Columns(20, 20) As New TVMesh
Dim DeadEnds(20, 20) As Boolean
Dim Sphere As New TVMesh
Dim Spheres(20, 20) As New TVMesh
Dim hwall As New TVMesh
Dim hwalls(20, 20) As New TVMesh
Dim vwall As New TVMesh
Dim vwalls(20, 20) As New TVMesh
Dim mfloor As New TVMesh
Dim IOsys As New TVInputEngine
Dim Mothernature As New TVAtmosphere
Dim CamOldPos As D3DVECTOR
Dim CamNewPos As D3DVECTOR
Dim Math As New TVMathLibrary
Dim Eye As New TVCamera
Dim TwoDee As New TVScreen2DImmediate
Dim blah As D3DVECTOR2
Dim Hands As New TVActor2
Dim HandsNextAnim As Integer
Dim totDeadEnds
Dim LastNonCollidedPosition  As D3DVECTOR
Dim matrix As D3DMATRIX
Dim Guts As New TVInternalObjects
Dim Shooting As Boolean
Dim DoneShooting As Boolean
Dim ColRes As TV_COLLISIONRESULT
Dim colide As New TVCollisionResult

Private Sub Form_Load()
CPU.SetDebugMode True, True
CPU.SetDebugFile App.Path & "\Debug.txt"
'CPU.Init3DFullscreen 800, 600, 32, True, False, TV_DEPTHBUFFER_24BITS_8STENCILBITS, , Me.hWnd
CPU.Init3DFullscreen 1024, 768, 32, True, False, TV_DEPTHBUFFER_24BITS_8STENCILBITS, , Me.hWnd
'CPU.Init3DWindowedMode Me.hWnd
CPU.SetSearchDirectory "c:\tv3dsdk\media"
Dim xwalls(20, 20)
Dim ywalls(20, 20)
Scene.LoadTexture "c:\tv3dsdk\media\21.bmp", , , "Wall"
Scene.LoadTexture "c:\tv3dsdk\media\floor_3.bmp", , , "Floor"
Scene.LoadTexture "c:\tv3dsdk\media\front.bmp", , , "front"
Scene.LoadTexture "c:\tv3dsdk\media\back.bmp", , , "back"
Scene.LoadTexture "c:\tv3dsdk\media\right.bmp", , , "right"
Scene.LoadTexture "c:\tv3dsdk\media\left.bmp", , , "left"
Scene.LoadTexture "c:\tv3dsdk\media\top.bmp", , , "top"
Scene.LoadTexture "c:\tv3dsdk\media\bottom.bmp", , , "bottom"
Mothernature.SkyBox_Enable True
Mothernature.SkyBox_SetTexture GetTex("front"), GetTex("back"), GetTex("left"), GetTex("right"), GetTex("top"), GetTex("bottom")
Mothernature.SkyBox_SetDistance 3800
Me.Show
Me.SetFocus
CPU.Clear
Scene.DrawText "Loading", 0, 1
CPU.RenderToScreen
Scene.SetViewFrustum 65, 8000

generatemaze xwalls, ywalls, 20, 20

roomsize = 200

Set Sphere = Scene.CreateMeshBuilder
Sphere.CreateSphere GetTex("floor"), 5, 4, 10
Sphere.EnableSphereMapping True

Set Column = Scene.CreateMeshBuilder
Column.CreateCylinder 20, 51.1, 20
Column.SetTexture GetTex("wall")
Column.RotateX 3.14159
Column.RotateY 2
Column.SetTextureModEnable True
Column.SetTextureModTranslationScale 0, 0, 6, 1

Hands.Load "c:\tv3dsdk\media\v_shotgun.mdl"
Hands.SetAnimationID 0
Hands.PlayAnimation 10

Set mfloor = Scene.CreateMeshBuilder
mfloor.AddFloor GetTex("Floor"), 0, 0, 20 * roomsize, 20 * roomsize, , 40, 40
mfloor.Optimize
Set hwall = Scene.CreateMeshBuilder
hwall.AddWall3D GetTex("Wall"), -roomsize, 0, 0, 0, 50, 10, , , , -1.02, -4.2
hwall.AddFloor GetTex("Wall"), -roomsize, 10, 0, -10, 50
hwall.Optimize
Set vwall = Scene.CreateMeshBuilder
vwall.AddWall3D GetTex("Wall"), 0, 0, 0, -roomsize, 50, 10, , , , -1.02, -4.2
vwall.AddFloor GetTex("Wall"), 10, 0, -10, -roomsize, 50
vwall.Optimize

For x = 0 To 20
    For y = 0 To 20
        If xwalls(x, y) = True Then
            Set hwalls(x, y) = hwall.DuplicateMesh
            hwalls(x, y).SetPosition x * roomsize, 0, y * roomsize
        End If
        If ywalls(x, y) = True Then
            Set vwalls(x, y) = vwall.DuplicateMesh
            vwalls(x, y).SetPosition x * roomsize, 0, y * roomsize
        End If
        Set Columns(x, y) = Column.DuplicateMesh
        Columns(x, y).SetPosition x * roomsize, 24.5, y * roomsize
       
        If DeadEnds(x, y) Then
            Set Spheres(x, y) = Sphere.DuplicateMesh
            Spheres(x, y).SetPosition x * roomsize - roomsize / 2, 25, y * roomsize - roomsize / 2
        End If
    Next
    CPU.Clear
    Scene.DrawText "Loading " & (80 + x) & "%", 0, 0
    CPU.RenderToScreen
    DoEvents
Next
Column.SetPosition 20000, 20000, 20000
hwall.SetPosition 20000, 20000, 20000
vwall.SetPosition 20000, 20000, 20000

Dim cx As Single, cy As Single, fu As Single, mx As Long, my As Long, mb1 As Integer
Scene.SetCamera 50, 25, 50, 51, 50, 50
DoneShooting = True
Do
    skyrot = skyrot + CPU.AccurateTimeElapsed / 50000
    Mothernature.SkyBox_SetRotation 0, skyrot, 0
    Eye.SetRotation 0, cy, 0
    CamOldPos = Eye.GetPosition
    If IOsys.IsKeyPressed(TV_KEY_W) Then Eye.MoveRelative CPU.AccurateTimeElapsed / 7, 0, 0
    If IOsys.IsKeyPressed(TV_KEY_S) Then Eye.MoveRelative -CPU.AccurateTimeElapsed / 7, 0, 0
    If IOsys.IsKeyPressed(TV_KEY_A) Then Eye.MoveRelative 0, 0, -CPU.AccurateTimeElapsed / 7
    If IOsys.IsKeyPressed(TV_KEY_D) Then Eye.MoveRelative 0, 0, CPU.AccurateTimeElapsed / 7
    If IOsys.IsKeyPressed(TV_KEY_LEFT) Then cy = cy - CPU.AccurateTimeElapsed / 400
    If IOsys.IsKeyPressed(TV_KEY_RIGHT) Then cy = cy + CPU.AccurateTimeElapsed / 400
    If IOsys.IsKeyPressed(TV_KEY_UP) Then Eye.MoveRelative CPU.AccurateTimeElapsed / 7, 0, 0
    If IOsys.IsKeyPressed(TV_KEY_DOWN) Then Eye.MoveRelative -CPU.AccurateTimeElapsed / 7, 0, 0
    If CamOldPos.x = Eye.GetPosition.x And CamOldPos.y = Eye.GetPosition.y And CamOldPos.z = Eye.GetPosition.z Then
        HandsNextAnim = 0
    Else
        HandsNextAnim = 9
    End If
    IOsys.GetMouseState mx, my, mb1
    If mb1 <> 0 Then
        HandsNextAnim = 2
        If Shooting = False And DoneShooting = True Then
            DoneShooting = False
            Shooting = True
        Else
            Shooting = False
        End If
    Else
        Shooting = False
    End If
    If (Hands.GetKeyFrame >= Hands.GetAnimationLength(Hands.GetAnimation) - 4) Or (Hands.GetAnimation = 0) Or (Hands.GetAnimation = 9) Then
        If Hands.GetAnimation <> HandsNextAnim Then Hands.SetAnimationID HandsNextAnim
        Hands.PlayAnimation 10
        If Shooting = False Then DoneShooting = True
    End If
    cx = cx + my / 200
    cy = cy + mx / 100
    Eye.SetRotation cx, cy, 0
    CamNewPos = checkbounds(CamOldPos, Eye.GetPosition)
    Eye.SetPosition CamNewPos.x, CamNewPos.y, CamNewPos.z
    Hands.SetPosition CamNewPos.x, CamNewPos.y, CamNewPos.z
    Hands.SetRotation 0, cy + (3.14159 / 2), cx
   
    If Shooting Then
        If Scene.AdvancedCollision(CamNewPos, Vector3(CamNewPos.x + Sin(cy) * 2000, CamNewPos.y + Sin(-cx) * 2000, CamNewPos.z + Cos(cy) * Cos(-cx) * 2000), ColRes, TV_COLLIDE_MESH, TV_TESTTYPE_ACCURATETESTING, True) Then
            For x = 0 To 20
                For y = 1 To 20
                    If Spheres(x, y).GetMeshIndex = ColRes.MeshID Then Spheres(x, y).Destroy
                Next
            Next
            Scene.DrawText ColRes.MeshID, 0, 40
        End If
    End If
    CPU.Clear
        Scene.RenderAllMeshes False
        Mothernature.Skybox_Render
        Hands.Render
        'TwoDee.DRAW_Line3D Hands.GetBonePosition(30, Vector3(0, 0, 0)).x, Hands.GetBonePosition(30, Vector3(0, 0, 0)).y, Hands.GetBonePosition(30, Vector3(0, 0, 0)).z, CamNewPos.x + Sin(cy) * 500, CamNewPos.y + Sin(-cx) * 500, CamNewPos.z + Cos(cy) * Cos(-cx) * 500, RGBA(1, 0, 0, 1)
        TwoDee.DRAW_FilledCircle 1024 / 2, 768 / 2, 20, , RGBA(1, 0, 0, 0.2)
        TwoDee.DRAW_Line 1024 / 2 - 20, 768 / 2, 1024 / 2 + 20, 768 / 2, RGBA(0, 0, 0, 0.2)
        TwoDee.DRAW_Line 1024 / 2, 768 / 2 - 20, 1024 / 2, 768 / 2 + 20, RGBA(0, 0, 0, 0.2)
        Scene.DrawText CPU.GetFPS & " Frames Per Second", 0, 0
        If Scene.AdvancedCollision(CamNewPos, Vector3(CamNewPos.x + Sin(cy) * 2000, CamNewPos.y + Sin(-cx) * 2000, CamNewPos.z + Cos(cy) * Cos(-cx) * 2000), ColRes, TV_COLLIDE_MESH, TV_TESTTYPE_ACCURATETESTING, True) Then
            Scene.DrawText ColRes.MeshID, 0, 40
        End If
    CPU.RenderToScreen
    DoEvents
Loop Until IOsys.IsKeyPressed(TV_KEY_ESCAPE)
DoEvents
CPU.ReleaseAll
DoEvents
Set CPU = Nothing
DoEvents
Unload Me
DoEvents
End
End Sub

Function collision(StartPosition As D3DVECTOR, EndPosition As D3DVECTOR) As D3DVECTOR
collided = False
b1 = Rnd
For a1 = -3.14159 * 1 To 3.14159 * 1 Step 1 '0.5
    a2 = a1 + b1
    If Scene.Collide(Vector3(EndPosition.x + Sin(a2) * 5, EndPosition.y, EndPosition.z + Cos(a2) * 5), Vector3(StartPosition.x + Sin(a2 - 3.14159) * 5, StartPosition.y, StartPosition.z + Cos(a2 - 3.14159) * 5), TV_TESTTYPE_ACCURATETESTING) Then collided = True
    'If Scene.Collide(Vector3(EndPosition.x + Sin(a2) * 5, EndPosition.y, EndPosition.z + Cos(a2) * 5), Vector3(StartPosition.x, StartPosition.y, StartPosition.z), TV_TESTTYPE_ACCURATETESTING) Then collided = True
Next
If collided = True Then
    collision = StartPosition
Else
    collision = EndPosition
End If
End Function
Function checkbounds(StartPosition As D3DVECTOR, EndPosition As D3DVECTOR) As D3DVECTOR
    checkbounds.x = collision(StartPosition, Vector3(EndPosition.x, StartPosition.y, StartPosition.z)).x
    checkbounds.z = collision(StartPosition, Vector3(StartPosition.x, StartPosition.y, EndPosition.z)).z
    checkbounds.y = EndPosition.y
    If LastNonCollidedPosition.x = 0 And LastNonCollidedPosition.y = 0 And LastNonCollidedPosition.z = 0 Then
        LastNonCollidedPosition.x = StartPosition.x
        LastNonCollidedPosition.y = StartPosition.y
        LastNonCollidedPosition.z = StartPosition.z
    End If
    If checkbounds.x = StartPosition.x And checkbounds.z = StartPosition.z And checkbounds.y = StartPosition.y Then
        If checkbounds.x = EndPosition.x And checkbounds.z = EndPosition.z And checkbounds.y = EndPosition.y Then
        Else
            checkbounds = LastNonCollidedPosition
        End If
    Else
            LastNonCollidedPosition = collision(StartPosition, EndPosition)
    End If
End Function


Sub generatemaze(horizwalls, vertwalls, width, height)
Dim walkable() As Boolean
ReDim walkable(width, height)
Dim wentleft As Boolean
Dim wentright As Boolean
Dim wentup As Boolean
Dim wenddown As Boolean
Dim roomcount As Long
Randomize Timer

For x = 1 To width
    For y = 1 To height
        horizwalls(x, y) = True
        vertwalls(x, y) = True
    Next
Next

xx = Int(Rnd * width) + 1
yy = Int(Rnd * height) + 1
walkable(xx, yy) = True
wentleft = False
wentright = False
wentup = False
wentdown = False
roomcount = 1
Do
    Direction = Int(Rnd * 4)
    If wentup And wentdown And wentright And wentleft Then
        Do
            xx = Int(Rnd * width) + 1
            yy = Int(Rnd * height) + 1
        Loop Until walkable(xx, yy)
    End If
    oxx = xx
    oyy = yy
    Select Case Direction
        Case 0 'up
            yy = yy - 1
            If yy < 1 Then yy = 1
            If walkable(xx, yy) = False Then
                roomcount = roomcount + 1
                walkable(xx, yy) = True
                horizwalls(xx, yy) = False
                wentup = True
            Else
                yy = oyy
            End If
        Case 1 'left
            xx = xx - 1
            If xx < 1 Then xx = 1
            If walkable(xx, yy) = False Then
                roomcount = roomcount + 1
                walkable(xx, yy) = True
                vertwalls(xx, yy) = False
                wentleft = True
            Else
                xx = oxx
            End If
        Case 2 'down
            yy = yy + 1
            If yy > height Then yy = height
            If walkable(xx, yy) = False Then
                roomcount = roomcount + 1
                walkable(xx, yy) = True
                horizwalls(oxx, oyy) = False
                wentdown = True
            Else
                yy = oyy
            End If
        Case 3 'right
            xx = xx + 1
            If xx > width Then xx = width
            If walkable(xx, yy) = False Then
                roomcount = roomcount + 1
                walkable(xx, yy) = True
                vertwalls(oxx, oyy) = False
                wentright = True
            Else
                xx = oxx
            End If
    End Select
    If roomcount Mod width = 0 Then
        CPU.Clear
            Scene.DrawText "Loading " & (roomcount / (width * height) * 80) & "%", 0, 0
        CPU.RenderToScreen
    End If
    DoEvents
Loop Until roomcount = width * height
For a = 1 To 20
    horizwalls(a, 0) = True
    vertwalls(0, a) = True
Next
For x = 1 To width
    For y = 1 To height
        wallcount = 0
        If horizwalls(x, y - 1) = True Then wallcount = wallcount + 1
        If horizwalls(x, y) = True Then wallcount = wallcount + 1
        If vertwalls(x - 1, y) = True Then wallcount = wallcount + 1
        If vertwalls(x, y) = True Then wallcount = wallcount + 1
        If wallcount = 3 Then DeadEnds(x, y) = True
    Next
Next
       
End Sub
Logged

BYTE-Smasher
Community Member
*
Posts: 956

vaporware makes baby jesus cry


WWW
« Reply #10 on: August 09, 2004, 08:15:54 AM »

BTW, you can shoot the floating spheres...
Logged

BYTE-Smasher
Community Member
*
Posts: 956

vaporware makes baby jesus cry


WWW
« Reply #11 on: August 09, 2004, 08:27:13 AM »

'nother screenie...

NOTE: Please mind the damned framerates... this system sux ass... I can't run doom 3 on it.... less I tweak it out to the max... then I get about 10 fps... tv3d runs at 300fps for a blank screen... so don't complain because the framerate sux for me... it'll be uber-fast for jou....
Logged

JeffWeber
Community Member
*
Posts: 1023


« Reply #12 on: August 09, 2004, 05:22:51 PM »

Looks like an orignal castle wolfenstien clone!. cool!
Logged

""Space is deep, Man is small and Time is his relentless enemy" --Orson Scott Card
Pages: [1]
  Print  
 
Jump to:  

Powered by SMF 1.1.3 | SMF © 2006-2007, Simple Machines LLC
Seo4Smf v0.2 © Webmaster's Talks