sandbox games - how???

Blitz3D Forums/Blitz3D Beginners Area/sandbox games - how???

This might be more like what you're looking for, unlike water that seeks the lowest path, this sand can be piled up in spots.

SeedRnd MilliSecs()
SetBuffer BackBuffer()

Type sand
	Field x%
	Field y%
	Field colors%
	Field kind
End Type 

Graphics3D 1024, 768, 32, 2

Cls 

LockBuffer BackBuffer()
Global black = ReadPixel (0, 0)
UnlockBuffer BackBuffer()

Repeat
Line 0, 100, 200, 300
Line 200, 300, 400, 100

;Line 100,200,400,200
   If MouseDown(1) Then

	s.sand = New sand 
	s\x = MouseX()
	s\y = MouseY()
	s\kind = 1
	s\colors = Rnd(0, 100000) 

   End If 

   If frame Mod 2 Then 
	LockBuffer BackBuffer()
	For s.sand = Each sand

		WritePixelFast s\x, s\y, s\colors
		
		If ReadPixelFast (s\x, s\y+1) = black Then 
		 s\y = s\y + 1
		EndIf
		
		If ReadPixelFast (s\x+1, s\y) = black And ReadPixelFast (s\x+1, s\y+1)=black Then 
		s\x = s\x+1:s\y = s\y + 1
		EndIf
		
		If ReadPixelFast (s\x-1, s\y) = black And ReadPixelFast (s\x-1, s\y+1)=black Then 
		s\x = s\x-1:s\y = s\y + 1
		EndIf 

		If s\y > GraphicsHeight()-1 Then Delete s
		 
	Next 
	UnlockBuffer BackBuffer()
	Flip False
	Cls 
   End If

   frame=frame +1
   If frame > 1 Then frame=0

For s.sand = Each sand
n=n+1
Next
	
	Text 0, 0, n
n=0

Until KeyHit(1)
End