i made this very simple 3d version of game of life, just as a practice, since im new to dbp.
but the patterns seems to keep moving sideways, not sure why, so, maybe someone would care to play around with it, and figure it out
press enter to "evolve" the cubes
press 1 to fill the bottom rows with cubes
press 2 to randomly fill the entire "world"
press 3 to fill the middle row of cubes
-plenty of room for improvement, its very slow if you increse the world size:b
fullscreen=0
rem SETTINGS
if fullscreen=1
rem set display mode 800,600, 32, 1
REM set display mode 1920, 1080, 32, 1
REM set display mode 1680,1050, 32, 1
set display mode desktop width(),desktop height(), 32, 1
set window off
else
set display mode 800,600, 32, 1
set window oN
endif
backdrop on
color backdrop 0
sync on
sync rate 60
hide mouse
ink rgb(255,0,0),0
fog on
fog color rgb(0,0,0)
fog distance 500
set camera range 0,0.1,100000
printinfo=1
survive_value=1
birth_min_value=3
birth_max_value=4
die_value=7
world_size=20
cubesize=10
rem make cube array
gosub make_cube_array
posx#=0
posy#=0
posz#=0
position camera 0,0,0,-300
do
run=run+1
rem if spacekey is pressed, then empty array
if spacekey()=1
for x=1 to world_size
for z=1 to world_size
for y=1 to world_size
cubes(x,z,y).alive=0
cubes(x,z,y).new_alive=0
if cubes(x,z,y).made=1
exclude object on cubes(x,z,y).objectnr
hide object cubes(x,z,y).objectnr
endif
next
next
next
endif
rem if key 1 is pressed, then fill BOTTOM of array
if keystate(2)=1
for x=1 to world_size
for z=1 to world_size
cubes(x,z,1).new_alive=1
cubes(x,z,1).alive=1
next
next
endif
rem if key 2 is pressed, then RANDOMLY fill array
if keystate(3)=1
for x=1 to world_size
for z=1 to world_size
for y=1 to world_size
IF RND(5)=0
cubes(x,z,y).new_alive=1
cubes(x,z,y).alive=1
ENDIF
next
next
next
endif
rem if key 3 is pressed, then fill the middle of the array
if keystate(4)=1
for x=1 to world_size
for z=1 to world_size
cubes(x,z,(int(world_size/2))).new_alive=1
cubes(x,z,(int(world_size/2))).alive=1
next
next
endif
rem if enterkey is pressed, calculate life
if keystate(28)=1
for x=1 to world_size
for z=1 to world_size
for y=1 to world_size
rem count living cubes in naborhood
gosub count_living_nabors
rem check if cube survives, dies, or gets reborn
gosub calculate_life
cubes(x,z,y).alive=cubes(x,z,y).new_alive
cubes(x,z,y).new_alive=0
next
next
next
endif
rem paste cubes
for x=1 to world_size
for z=1 to world_size
for y=1 to world_size
gosub _place_cube
next
next
next
if printinfo=1
rem text 0,screen height()-15, "scancode:______" + str$(scancode())
text 0,0,"fps:" + str$(screen fps()) + " scancode:" + str$(scancode()) + " frames:" + str$(run)
endif
control camera using arrowkeys 0,6,2
sync
loop
make_cube_array:
type cube_data
alive as integer
new_alive as integer
made as integer
objectnr as integer
endtype
count=1
dim cubes(world_size,world_size,world_size) as cube_data
for x=1 to world_size
for z=1 to world_size
for y=1 to world_size
cubes(x,z,y).alive=0
cubes(x,z,y).new_alive=0
cubes(x,z,y).objectnr=count
cubes(x,z,y).made=1
make object cube count,cubesize
exclude object on count
count=count+1
next
next
next
return
calculate_life:
if cubes(x-1,z-1,y).alive=1
if nabours<survive_value then cubes(x,z,y).new_alive=0
if nabours=>die_value then cubes(x,z,y).new_alive=0
else
if nabours<die_value and nabours=>birth_min_value and nabours<=birth_max_value then cubes(x,z,y).new_alive=1
endif
return
count_living_nabors:
nabours=0
if x>1 then if cubes(x-1,z,y).alive=1 then nabours=nabours+1
if x>1 and z>1 then if cubes(x-1,z-1,y).alive=1 then nabours=nabousr+1
if x>1 and z>1 and y>1 then if cubes(x-1,z-1,y-1).alive=1 then nabours=nabours+1
if x>1 and y>1 then if cubes(x-1,z,y-1).alive=1 then nabours=nabours+1
if z>1 and y>1 then if cubes(x,z-1,y-1).alive=1 then nabours=nabours+1
if y>1 then if cubes(x,z,y-1).alive=1 then nabours=nabours+1
if z>1 then if cubes(x,z-1,y).alive=1 then nabours=nabours+1
rem
if x<world_size then if cubes(x+1,z,y).alive=1 then nabours=nabours+1
if x<world_size and z<world_size then if cubes(x+1,z+1,y).alive=1 then nabours=nabours+1
if x<world_size and z<world_size and y<world_size then if cubes(x+1,z+1,y+1).alive=1 then nabours=nabours+1
if x<world_size and y<world_size then if cubes(x+1,z,y+1).alive=1 then nabours=nabours+1
if z<world_size and y<world_size then if cubes(x,z+1,y+1).alive=1 then nabours=nabours+1
if y<world_size then if cubes(x,z,y+1).alive=1 then nabour=nabours+1
if z<world_size then if cubes(x,z+1,y).alive=1 then nabour=nabours+1
return
_place_cube:
if cubes(x,z,y).alive=1
if cubes(x,z,y).made=1
exclude object off cubes(x,z,y).objectnr
position object cubes(x,z,y).objectnr,(x-(world_size/2))*cubesize,(y-(world_size/2))*cubesize,(z-(world_size/2))*cubesize
else
cubes(x,z,y).made=1
make object cube cubes(x,z,y).objectnr,cubesize
position object cubes(x,z,y).objectnr,(x-(world_size/2))*cubesize,(y-(world_size/2))*cubesize,(z-(world_size/2))*cubesize
endif
else
if cubes(x,z,y).made=1
exclude object on cubes(x,z,y).objectnr
endif
endif
return
"hello world"