Latest UploadsPlatdude SpottingJayenkaiNom nom nomJayenkaiRainbow TroutPakzKing SalmonPakzSnookerJayenkaiYou've ... o have youJayenkai
 Code Snippets > Collisions and Physics ( Created 23 November 2016 | Last Edited 24 November 2016)

 Water in 2d map by Pakz | No VotesSee water flow/flood in a level. Written inMonkey lmb = poor water - rmb = place tile - mmb = erase tile/water. Here a short video of it : https://youtu.be/vtORT4-W91k I have been spending time learning how to do water. What happens in the code basically is. In the update a random position is chosen. If that position is water then see if you can move the drop down/left or right. I added some code later to move water a little bit more sideways. It took me a while to learn this. I first used a more complex way but found this simple way was a lot better. It still probably needs more work. Code for monkey 2 'What it does is rndomly find a pos on the map (thousand times per second) 'if that map pos is water then see if you can move it down 'see if it can move left 'see if it can move right 'see if it can move left down 'replace the old position with no water and the place where to go with water value ' lmb = pour water - mmb = erase tile - rmb = make tile #Import "" #Import "" Using std.. Using mojo.. Class map Field freq:Int 'how many updates per cycle Field tw:Float,th:Float Field w:Int,h:Int Field map:= New Int[1,1] Method New(sw:float,sh:float,w:float,h:Float,freq:int) Self.freq = freq tw = sw/w th = sh/h map = New Int[w,h] Self.w = w Self.h = h For Local y:=(h/1.5) Until h For Local x:=0 Until w map[x,y] = 1 Next Next For Local y:=0 Until h map[0,y] = 1 map[w-1,y] = 1 Next makewater(20,15,10,10) End Method Method update() If Mouse.ButtonDown(MouseButton.Left) Local x:Int= Mouse.X/tw Local y:Int = Mouse.Y/th If x>0 And x0 And y0 And x0 And y0 And x0 And y 2 Then exitloop = True mx-=1 Wend map[x+1,y] = 2 Local el:Bool=False Local v:Int While el=False v=Rnd(mx+1,x) If map[v,y] = 2 Then el=True Wend map[v,y] = 0 End If End If Case 5 'swooop left If map[x-1,y] = 0 If map[x+1,y] = 2 Local exitloop:Bool=False Local mx:Int=x While exitloop = False If map[mx,y] <> 2 Then exitloop = True mx+=1 Wend map[x-1,y] = 2 map[Rnd(x,mx-1),y] = 0 End If End if End Select End If End Method Method makewater(x:Int,y:Int,w:Int,h:Int) For Local y1:=y Until y+h For Local x1:=x Until x+w map[x1,y1] = 2 Next Next End Method Method draw(canvas:Canvas) For Local y:=0 Until h For Local x:=0 Until w If map[x,y] = 0 canvas.Color = Color.Black canvas.DrawRect(x*tw,y*th,tw,th) End If If map[x,y] = 1 canvas.Color = Color.Grey canvas.DrawRect(x*tw,y*th,tw,th) End If If map[x,y] = 2 canvas.Color = Color.Blue canvas.DrawRect(x*tw,y*th,tw,th) End If Next Next End Method End Class Global mymap:map Class MyWindow Extends Window Method New() mymap = New map(Width,Height,50,50,2000) End Method Method OnRender( canvas:Canvas ) Override App.RequestRender() ' Activate this method mymap.update() mymap.draw(canvas) ' if key escape then quit If Keyboard.KeyReleased(Key.Escape) Then App.Terminate() End Method End Class Function Main() New AppInstance New MyWindow App.Run() End Function -->

Posted : Saturday, 26 November 2016, 08:05
Pakz

I combined the water code with the mining map generator with ai. Still some work to be done but it is looking more interesting now.

https://youtu.be/Qqkc3IQ7C-Y

Posted : Saturday, 26 November 2016, 20:19
Stealth

That's really slick! *pun*

-=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- (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