Alright, now i have a strange error when i added 1D of physics, gravity.....
When i select an object from the toolbar and place it onto the map, it starts falling, but it also creates a copy of itself which doesnt move, but if i get rid of the physics part it doesnt, can anyone help me figure out why? right now i dont have access to a zip program, so the code is posted, note of warning, it is long. The models needed are in the original file uploads of my previous post.
The part of the code where the glitch happened is after i added gosub applyNPhys.
`runs the program in windowed mode
set window on
`clears the screen, stops weird white flashes
cls
`stops the camera from automatically positioning itself
autocam off
`Turns on the refresh rate
sync on
`Sets the refresh rate
sync rate 30
`randomizes the random
randomize timer()
`Hides the mouse from the player
hide mouse
`Variable used to keep track of what tools to display
totalobjects=0
toolN=1
toolselected=0
`Array for all physical objects; object number; weight,elasticity,position x,position y,angle z, velx,vely
dim object#(100,9)
`Array for the tools, tool name and model name
dim tools$(10,2)
`positions the camera to center the box
position camera 0,75,-300
`rotates the camera so that the box fills the screen
`rotate camera 15,0,0
`startup subroutine,creates the level
Startup:
`load image "grid.bmp",1
gosub loadarray
gosub loadMap
gosub loadBar
`main loop
do
toolN=checkMouse(toolN)
gosub rotatetools
gosub toolplacement
toolselected=objectSelection(toolselected,toolN)
gosub applyNPhys
`debug, shows the FPS
center text 240,100,str$(screen fps() )+" vel:"+str$(object#(1,7))
sync
loop
applyNPhys:
for x=1 to 100
if object exist(x+1000)
object#(x,7)=object#(x,7)-(9.8/(screen fps() ))
object#(x,4)=object#(x,4)+object#(x,7)
position object x+1000,object#(x,3),object#(x,4),0
endif
next x
return
toolplacement:
mxg= mousex()
myg= mousey()
mxg=round(mxg)
myg=round(myg)+20
if mouseheld=1
if mouseclick()=0
mouseheld=0
endif
endif
if mouseheld=0
if mouseclick()=1
mouseheld=1
if toolselected = 0
else
load object tools$(toolselected,2),totalobjects+1001
scale object totalobjects+1001,25,25,25
position object totalobjects+1001,mxg-320,0-(myg-320),0
object#(totalobjects+1,1)=1
object#(totalobjects+1,2)=0.75
object#(totalobjects+1,3)=mxg-320
object#(totalobjects+1,4)=0-(myg-320)
object#(totalobjects+1,5)=0
object#(totalobjects+1,6)=0
object#(totalobjects+1,7)=0
totalobjects=totalobjects+1
if shiftkey()=0
toolselected=0
endif
endif
endif
endif
if toolselected = 0
if object exist(totalobjects+500)=1
delete object totalobjects+500
endif
else
if object exist(totalobjects+500)=0
load object tools$(toolselected,2),totalobjects+500
scale object totalobjects+500,25,25,25
position object totalobjects+500,mxg-320,0-(myg-320),0
endif
position object totalobjects+500,mxg-320,0-(myg-320),0
endif
return
function objectSelection(toolselected,toolN)
`centers the mouse variables so that 0,0 is the middle of the screen
mx=mousex()-320
my=0-(mousey()-240)
if mouseclick()=2
toolselected=0
endif
`First tool in toolbar
if mx<-125 and mx>-175 and my<-145 and my>-215
if tools$(toolN,1) = ""
center text 170,365,"Block"
else
center text 170,365,tools$(toolN,1)
if mouseclick()=1
toolselected=toolN
endif
endif
endif
`Second tool in toolbar
if mx<-25 and mx>-75 and my<-145 and my>-215
if tools$(toolN+1,1) = ""
center text 270,365,"Block"
else
center text 270,365,tools$(toolN+1,1)
if mouseclick()=1
toolselected=toolN+1
endif
endif
endif
`Third tool in toolbar
if mx<75 and mx>25 and my<-145 and my>-215
if tools$(toolN+2,1) = ""
center text 370,365,"Block"
else
center text 370,365,tools$(toolN+2,1)
if mouseclick()=1
toolselected=toolN+2
endif
endif
endif
`Fourth tool in toolbar
if mx<175 and mx>125 and my<-145 and my>-215
if tools$(toolN+3,1) = ""
center text 470,365,"Block"
else
center text 470,365,tools$(toolN+3,1)
if mouseclick()=1
toolselected=toolN+3
endif
endif
endif
if toolselected>0
if object visible(6)
mxg= mousex()
myg= mousey()
mxg=round(mxg)
myg=round(myg)+20
center text mxg,myg,tools$(toolselected,1)
endif
endif
endfunction toolselected
loadarray:
if file exist("toolbar.txt")
load array "toolbar.txt",tools$(0)
else
tools$(1,1)="Brick"
tools$(1,2)="modelsbrick100.x"
tools$(2,1)="Ball"
tools$(2,2)="modelsball100.x"
tools$(3,1)="Cone"
tools$(3,2)="modelscone100.x"
tools$(4,1)="Cylinder"
tools$(4,2)="modelscylinder100.x"
tools$(5,1)="Cylinder"
tools$(5,2)="modelscylinder100.x"
tools$(6,1)="Cone"
tools$(6,2)="modelscone100.x"
tools$(7,1)="Ball"
tools$(7,2)="modelsball100.x"
tools$(8,1)="Brick"
tools$(8,2)="modelsbrick100.x"
for x=9 to 10
for y=1 to 2
tools$(x,y)=""
next y
next x
save array "toolbar.txt",tools$(0)
endif
return
`rotates all tools displayed in the toolbar
rotatetools:
for x=toolN to toolN+3
if object exist(x+300)
zrotate object x+300,wrapvalue(object angle z(x+300)+2)
yrotate object x+300,wrapvalue(object angle y(x+300)+1)
endif
next x
return
`loads the default map and lights
loadMap:
set ambient light 50
loadBox(1,300,1,300,0,0,0)
loadBox(2,300,400,1,0,200,150)
loadBox(3,1,400,300,150,200,0)
loadBox(4,1,400,300,-150,200,0)
`loadBox(5,1000,1000,1,0,75,-259)
`position object 5,0,10,400
`texture object 5,1
`scale object texture 5,5,5
`set object texture 5,0,0
`set object 5,1,0,1,1,1,1,0
`lock object on 5
`creates the mouse pointer
loadCone(6,50,50,15,0,0,359)
rotate object 6,0,45,30
lock object on 6
`test of secondary pointer
`loadBox(7,25,25,25,0,0,-50)
`rotate object 7,45,45,0
for x=1 to 4
set object x,1,1,1,1,1,1,0
next x
set spot light 0,0,120
position light 0,0,75,-300
rotate light 0,0,0,0
remstart
for x=1 to 4
make light x
next x
for x=0 to 3
set spot light x,0,90
color light x,rgb(250/(x+1),175/(x+1),115/(x+1))
next x
set spot light 4,0,22
color light 4,-125,-125,-125
position light 0,150,300,150
position light 1,-150,300,150
position light 2,-150,300,-150
position light 3,150,300,-150
position light 4,0,300,0
point light 0,0,0,0
point light 1,0,0,0
point light 2,0,0,0
point light 3,0,0,0
point light 4,0,0,0
remend
return
`creates the toolbar
loadBar:
loadbox(11,680,100,30,0,-180,400)
color object 11,rgb(250,200,90)
lock object on 11
loadcone(12,75,75,25,-260,-180,400)
rotate object 12,0,0,90
color object 12,rgb(255,0,0)
lock object on 12
loadcone(13,75,75,25,260,-180,400)
rotate object 13,0,180,90
color object 13,rgb(255,0,0)
lock object on 13
for x=1 to 4
if object exist(x+300)
position object x+300,-150+(100*(x-toolN)),-180,400
lock object on x+300
else
if tools$(x,2) = ""
loadbox(x+300,50,50,50,1000,1000,1000)
else
load object tools$(x,2),x+300
scale object x+300,50,50,50
position object x+300,1000,1000,1000
endif
color object x+300,rgb(rnd(255),rnd(255),rnd(255))
endif
lock object on 300+x
color object x+300,rgb(rnd(255),rnd(255),rnd(255))
next x
return
`Handles all of the toolbar display
function checkmouse(toolN)
`centers the mouse variables so that 0,0 is the middle of the screen
mx=mousex()-320
my=0-(mousey()-240)
`debug command, aids in locating the mouse pointer
center text 320,240,"mx:"+str$(mx)+" : my:"+str$(my)+" : toolN:"+str$(toolN)
`limits how fast the tools scroll
if mouseheld=1
if mouseclick()=0
mouseheld=0
endif
endif
`The left arrow, scrolls through the tools
if mouseheld=0
if mx<-215 and mx>-300 and my<-145 and my>-215
if mouseclick()=1
mouseheld=1
if toolN>1
if object exist(toolN+3+300)
delete object toolN+3+300
endif
toolN=toolN-1
endif
endif
color object 12,rgb(0,255,0)
else
color object 12,rgb(255,0,0)
endif
endif
`the right arrow, scrolls through the tools
if mouseheld=0
if mx>215 and mx<300 and my<-145 and my>-215
if mouseclick()=1
mouseheld=1
if toolN<7
if object exist(toolN+300)
delete object toolN+300
endif
toolN=toolN+1
endif
endif
color object 13,rgb(0,255,0)
else
color object 13,rgb(255,0,0)
endif
endif
`positions the tools
for x=toolN to toolN+3
if object exist(x+300)
position object x+300,-150+(100*(x-toolN)),-180,400
lock object on x+300
else
if tools$(x,2) = ""
loadbox(x+300,50,50,50,1000,1000,1000)
else
load object tools$(x,2),x+300
scale object x+300,50,50,50
position object x+300,1000,1000,1000
endif
color object x+300,rgb(rnd(255),rnd(255),rnd(255))
endif
next x
`if my>-125
if object visible(6)=1
mxg= mousex()
myg= mousey()
mxg=round(mxg)
myg=round(myg)+25
position object 6,mxg-320,0-(myg-240),359
`position object 7,(mxg-320)*0.65625,(0-(myg-240))*0.83333,-50
center text 320,300,"mx: "+str$(mxg)+"my: "+str$(myg)
else
show object 6
endif
`else
`if object visible(6)=1
`hide object 6
`endif
`endif
endfunction toolN
function round(integer)
if integer<0
integer= 0-abs(((integer+3)/5)*5)
endif
if integer>0
integer=abs(((integer+3)/5)*5)
endif
endfunction integer
`loads a 100 by 100 by 100 box model
function loadBox(objectN,xscale,yscale,zscale,xpos,ypos,zpos)
load object "modelscube100.x",objectN
scale object objectN,xscale,yscale,zscale
position object objectN,xpos,ypos,zpos
endfunction
`loads a 100 by 100 by 100 cone model
function loadCone(objectN,xscale,yscale,zscale,xpos,ypos,zpos)
load object "modelscone100.x",objectN
scale object objectN,xscale,yscale,zscale
position object objectN,xpos,ypos,zpos
endfunction
I am Beelzebub, funny name for a satanic being...