Im having trouble with a floor generation system but its currently really buggy. Right now it causes the screen to flicker when it draws the plane before instantly deleting it(I think). My end goal is to have it delete the cube and create a textured plane underneath to cover up the gap in the ground.
The bug is somwhere in here...
mx#=mousex()
my#=mousey()
mo=PICK OBJECT(mx#,my#,0,mapsize#*mapsize#)
If mouseclick()=1
if mo>0
if object exist (mo)
if Cubetype(mo)>0
Cubetype(Mo)=0
Floorx#=Object position x(mo)
Floory#=OBject position y(mo)
delete object mo
make object plane mo,100,100
position object mo,Floorx#,floory#,-50
texture object mo,1
endif
endif
endif
endif
loop
Heres the rest of the my code but you probbably wont need it.
REM Project: Dig project
REM Created: 2/10/2010 2:24:10 AM
REM
REM ***** Main Source File *****
REM
remstart
==============Notes============
Cubes take up object numbers 1 to 4096
Units start at object numbers 5000
Cube info holds all the information about the cubes
The grid contains 4096 cubes
remend
` Set up the sync rate
Sync on
Sync rate 60
`Setup the variables
X#=50
Z#=0
Cubenumber#=1
Mapsize#=64
Dwarfnumber#=5000
DIM Cubetype(Mapsize#,Mapsize#,5)
For x=1 to (Mapsize#*Mapsize#)
Cubetype(x)=1
next x
`load media
Load image "Stone texture.jpg",1
` The start menu
Rem menu
Do
if Button(20,55,"Campaign")=1 then goto Single_player
Button(20,95,"Multiplayer")
if Button(20,135,"Exit")=1 then End
sync
Loop
Rem Menu new game
Single_player:
cls
`Creates the cubes and displays the loading screen
`Creates the floor for the underground
Ink rgb (255,0,0),RGB(255,255,255)
Print "Attempting to create world"
sync
` Setup the edge of the map boxes
make object box (mapsize#*mapsize#+1),(Mapsize#*100),100,100
position object (mapsize#*mapsize#+1),((Mapsize#*100)/2),50,-100
make object box (mapsize#*mapsize#+2),(Mapsize#*100),100,100
position object (mapsize#*mapsize#+2),((Mapsize#*100)/2),50,(Mapsize#*100)
make object box (mapsize#*mapsize#+3),((Mapsize#*100)+200),100,100
yrotate object (mapsize#*mapsize#+3),90
position object (mapsize#*mapsize#+3),-50,50,((Mapsize#*100)/2)-50
make object box (mapsize#*mapsize#+4),((Mapsize#*100)+200),100,100
yrotate object (mapsize#*mapsize#+4),90
position object (mapsize#*mapsize#+4),((Mapsize#*100)+50),50,((Mapsize#*100)/2)-50
`Make the cubes inside the map edges
For a=1 to mapsize#
for b=1 to mapsize#
make object cube Cubenumber#,100
Position object Cubenumber#,X#,50,Z#
set object Cull cubenumber#,1
texture object Cubenumber#,1
inc Cubenumber#
X#=X#+100
next b
Z#=Z#+100
X#=50
next a
`Generate ore clumps
orenumber#=rnd(2)+2
for z = 1 to orenumber#
oresize#=rnd(15)+5
Oreposition#=rnd(mapsize#*mapsize#)
Row#=OrePosition# Div mapsize#
col#=OrePosition# mod mapsize#
For x# = -oresize# to oresize#
for y# =-oresize# to oresize#
g#=((Row#+y#)*mapsize#)+col#+x#
if (g#>0) and (g#<(mapsize#*MapSize#)) and (rnd(abs(x#)+abs(y#))<2) then color object g#,rgb(255,0,0)
next y
next x
next z
`Set up the player spawn
startpoint=rnd(Mapsize#*Mapsize#)
startx#=Object position X(startpoint)
startz#=Object position z(startpoint)
delete object startpoint
make object plane startpoint,100,100
position object startpoint,startx#,0,startz#
xrotate object startpoint,90
texture object startpoint,1
Cubetype(startpoint)=0
Make object sphere dwarfnumber#,50
position object dwarfnumber#,Startx#,25,startz#
inc dwarfnumber#
`make the camera for single player
Print "creating camera"
pitch camera down 25
Camx#=startx#
Camz#=startz#-300
Position camera Camx#,300,Camz#
`The main single player loop
print "Entering the main loop"
Do
`Checks and FPS and displays it on the screen
Print Screen fps()
sync
`Checks the mouse position, then moves the camera
If mousex()<10 then Camx#=Camx#-5
If mousex()>Screen width()-10 then Camx#=Camx#+5
If Mousey()<10 then Camz#=Camz#+5
If Mousey()>screen height()-50 then Camz#=Camz#-5
Position camera Camx#,300,Camz#
`If mouseclick()=1 then
mx#=mousex()
my#=mousey()
mo=PICK OBJECT(mx#,my#,0,mapsize#*mapsize#)
If mouseclick()=1
if mo>0
if object exist (mo)
if Cubetype(mo)>0
Cubetype(Mo)=0
Floorx#=Object position x(mo)
Floory#=OBject position y(mo)
delete object mo
make object plane mo,100,100
position object mo,Floorx#,floory#,-50
texture object mo,1
endif
endif
endif
endif
loop
function Button(x1,y1,WORDS$)
pressed=0
x2=Text Width(WORDS$)
y2=Text height(WORDS$)
if mousex()>x1 and mousex()<x1+x2
if mousey()>y1-y2 and mousey()<y1+y2
pressed=1
endif
endif
if pressed=1 then ink rgb(255,0,0),0 else ink rgb(255,255,255),0
if pressed=1
Pressed=Mouseclick()
else
pressed=0
endif
text x1,y1,WORDS$
endfunction pressed