Latest UploadsPlatdude SpottingJayenkaiNom nom nomJayenkaiRainbow TroutPakzKing SalmonPakzSnookerJayenkaiYou've ... o have youJayenkai
 Code Snippets > Generators ( Created 27 July 2016 | Last Edited 27 July 2016)

 Dungeon/Cave Generator - Simple by Pakz | No VotesPlace random rectangles next to other rectangle (grow) Written inMonkey Very simple : Create a rectangle on the map enter loop Create random rectangle if it fits next to a previous placed rectangle place there exit if enough placed or counter hit max Import mojo Class tilemap Field tilew:Int Field tileh:Int Field width:Int Field height:Int Field map:Int[][] Method New(width:Int,height:Int,tilew:Int,tileh:Int) Self.width=width Self.height=height Self.tilew=tilew Self.tileh=tileh map = New Int[width][] For Local i=0 Until width map[i] = New Int[height] Next makemap settiles End Method ' Here we create the walls Method settiles() 'create walls For Local y=1 Until height-1 For Local x=1 Until width-1 Local t:Int=map[x][y] If t=0 And map[x+1][y] = 1 Then map[x][y] = 2 If t=0 And map[x][y+1] = 1 Then map[x][y] = 2 If t=0 And map[x-1][y] = 1 Then map[x][y] = 2 If t=0 And map[x][y-1] = 1 Then map[x][y] = 2 Next Next ' get corners For Local y=1 Until height-1 For Local x=1 Until width-1 Local t:Int=map[x][y] If t=0 And map[x+1][y] = 2 And map[x][y+1] = 2 Then map[x][y] = 3 If t=0 And map[x-1][y] = 2 And map[x][y+1] = 2 Then map[x][y] = 3 If t=0 And map[x][y-1] = 2 And map[x+1][y] = 2 Then map[x][y] = 3 If t=0 And map[x-1][y] = 2 And map[x][y-1] = 2 Then map[x][y] = 3 Next Next 'set corners to value 2 For Local y=1 Until height-1 For Local x=1 Until width-1 If map[x][y] = 3 Then map[x][y] = 2 Next Next End Method Method makemap() 'here we make random rectangles and see if they 'are placed next to another rectangle. 'This will grow a random level... Local w1:Int=Rnd(1,4) Local h1:Int=Rnd(1,4) Local x1:Int=width/2 Local y1:Int=height/2 drawmaprect(x1,y1,w1,h1) Local maxrooms:Int=(width*height)/30 Local numrooms:Int=0 Local cnt:Int=0 While numrooms < maxrooms And cnt<15000 cnt+=1 Local done:Bool=False w1=Rnd(1,4) h1=Rnd(1,4) x1=Rnd(3,width-5) y1=Rnd(3,height-5) 'check right If map[x1][y1] = 1 And map[x1+1][y1] = 0 And map[x1+1][y1-2] = 0 And map[x1+1][y1+2] = 0 drawmaprect(x1,y1,w1,h1) numrooms+=1 done=True End If 'check bottom If done=False And map[x1][y1] = 1 And map[x1][y1+1] = 0 And map[x1-2][y1+1] = 0 And map[x1+2][y1+1] = 0 drawmaprect(x1,y1,w1,h1) numrooms+=1 done=True End If 'check top If done=False And y1+h1-1 And y1>-1 And x1

There are no comments for this entry. -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- (c) WidthPadding Industries 1987 569|0 -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=-
 Latest PostsLaptop Aaargh... Jayenkai Thu 13:40 London Car/Stab Incident Jayenkai Thu 13:36 Watch Switch - Fitbit Blaze Jayenkai Thu 07:04 GamerBlock rockford Thu 06:50 Happy Birthday, Spinal spinal Thu 03:26 Happy Birthday Evil Roy Ferguson rockford Wed 16:21 Spinal's Return to Android Jayenkai Tue 13:41 AGameAWeek : 2017 - Part One Jayenkai Tue 08:10 Poll : Cooking Jayenkai Mon 05:11 Happy Birthday, TheRevillsGames Dabz Sun 23:32 More

 Latest Items Showcase : Infinitronrychan Tue 03:02 Blog : My Arduino experience.steve_ancell Mon 20:27 Dev-Diary : PS2 to N64 Adapterspinal Sun 10:49 Link : Vector Tutorials/Help page.Pakz Thu 23:00 Blog : mini projectspinal Sun 10:13 Showcase : Blockman ReturnsJayenkai Fri 03:04 Snippet : Wall Tracing on Random Maps (rpg)rskgames Wed 22:48 Snippet : Path FollowingPakz Mon 16:25 Snippet : Flowers (Jan 2017)Kuron Thu 01:13 Showcase : Clusters of Hextherevillsgames Mon 15:01 Article : Maths 101 - Episode 1: Basic Trigonometryshroom_monk Sun 14:07 Article : Maths 101 - Episode 5: Line Intersectionshroom_monk Sun 14:02 Dev-Diary : Normals and Dot productsPakz Sat 20:37 Pets : Molly On The CouchJayenkai Thu 04:32 Snippet : Additive Particle FlamesPakz Fri 18:12More

Who's Online
Evil Roy Ferguson
Thu, at 17:36
Jayenkai
Thu, at 16:45
rockford
Thu, at 16:00
spinal
Thu, at 15:12
shroom_monk
Thu, at 14:35
steve_ancell
Thu, at 14:00
HoboBen
Thu, at 13:53
Andy_A
Thu, at 11:38
Pakz
Thu, at 10:03
rskgames
Thu, at 09:43