Hi, there!
I am in need of help urgently.
I am trying to make a 3D game that generates the player vehicle (a "tank" made of cubes randomly positioned) but it doesn't work properly.
I made a test program to show what is happening: when you hit CTRL, it returns to the beginning and generates another random model, but... It FREEZES and CRASHES randomly about 3 or 4 times CTRL is pressed.
I don't know what to do!
remstart
this is the model generator that i gonna
use in a future game, it simulates the
possibility of the player choosing one
among dozens (billions, in fact) of
different models (tanks)
remend
color backdrop rgb(0,0,0)
do
drawtank() ''prepare and draw object
position camera 0,0,10,-50
repeat
yrotate object 1,wrapvalue(object angle y(1)+2) ''rotates object on screen
until controlkey() = 1 ''when pressing CTRL, generate another model
deleteall() ''delete used object and flushes vram
loop
function drawtank()
dim tank(5,7) as integer
for y = 1 to 7 ''this loop makes the database to produce the object
for x = 1 to 3
tank(x,y) = rnd(2)
NEXT
tank(4,y) = tank(2,y) ''these two assignments are for the simmetry
tank(5,y) = tank(1,y)
next
make object cube 1,10 ''make the core object to glue the rest of the model onto
position object 1,0,0,0
obj = 2 ''the object counter
for x = 1 to 5
for y = 1 to 7
if tank(x,y) > 0
make object cube obj,10
if tank(x,y) = 1 then h = 0 ''uses the array data to decide the height of each cube
if tank(x,y) = 2 then h = 5
position object obj,(x - 2) * 5,h,(y - 3) * 5 ''position the objects with 5 pixels of spacing
inc obj
ENDIF
NEXT
NEXT
for o = 2 to obj-1
perform csg union 1,o ''merge each cube to the core cube
delete object o ''delete the brush object
NEXT
undim tank() ''undim the array to free memory
ENDFUNCTION
function deleteall()
delete object 1
flush video memory
ENDFUNCTION
<b><i>The mind is the compiler of dreams.</i></b>