Code archives/Algorithms/2D Mountain Generation
This code has been declared by its author to be Public Domain code.
Download source code
| |||||
Generates random 2D mountains (like for old style tank games, which is exatly what I used this method for). I had been using 15 year old BASIC programming language until 3 years ago when I upgraded to BlitzBasic (I upgraded to Blitz3D in December of 2005). This code is the BlitzBasic version of the code. | |||||
Global w=1024,h=768,d=32;Modify for your system. Graphics w,h,d,1 SetBuffer BackBuffer() Cls SeedRnd MilliSecs() y=Rnd(100,h-1) sy=Rnd(-2,2) For x=0 to w-1 py=y y=py+Rnd(-1,1)+sy If y<100 Then y=100 If y>h-1 Then y=h-1 sy=y-py If Abs(sy)>2 Then sy=Sgn(sy)*2 Line x,y,x,h-1 Next Flip WaitKey() End |
Comments
None.
Code Archives Forum