I was just working on a spining top and ended up with this and I thort ever one should have a look at it.
just press the left mouse key to fire a cube and see what hapens.
I hope you like it.
`******************************************
`****** Spining Top Challenge Entery ******
`****** By Sindore ************************
`******************************************
`***((( set up program )))***
gosub program_set_up
`***((( set up array & type )))***
type spin_top
speed# as float
wvoax# as float
wvoay# as float
wvoaz# as float
stpx# as float
stpy# as float
stpz# as float
col1 as Integer
col2 as Integer
IDobj as Integer
`coldat as float :`Integer :`boolean
endtype
dim SPA(1000) as spin_top
`***((( type valeuse )))***
for c = 1 to 1000
SPA(c).speed# = 25
SPA(c).wvoax# = 0
SPA(c).wvoay# = 0
SPA(c).wvoaz# = 0
SPA(c).stpx# = 0
SPA(c).stpy# = 0
SPA(c).stpz# = 0
next c
`*** make a floor object ***
make object cube 1001,1
scale object 1001,500000,10,500000
position object 1001,0,-20,0
color object 1001,rgb(10,10,10)
ghost object on 1001,4
set object specular 1001, rgb(0,0,0)
set object specular power 1001, 255
set object ambient 1001,25
phy make rigid body static box 1001
`*********************************************************************
`*********************************************************************
`******<<<<<< DO/LOOP >>>>>>******
`*********************************************************************
`*********************************************************************
`start loop
do
`***((( FPS print out )))***
set cursor 0,0 : print "FPS: ";screen fps()
`***((( scancode print out )))***
set cursor 0,20 : print "scancode: ";scancode()
`***<<< timer >>>***
currenttime = timer() :` this is for the fire timer
`*** camera contol function ***
camera_control()
`*** if escape key is pressed jump to the end of the game ***
if escapekey() > 0 then goto end_game
`*** fire the spining top ***
gosub fire_spining_top
`*** update physic sync and the loop ***
gosub physic_pause
sync
loop
`*** the destination from the escapekey ***
end_game:
`*** print ending program ***
set cursor screen width()/2.25,screen height()/2.25 : print "Exiting Program"
sync
wait 2500
`*** end physic ***
phy end
end
`*********************************************************************
`*********************************************************************
`******(((((( GOSUB`S ))))))******
`*********************************************************************
`*********************************************************************
`***((( set up program )))***
program_set_up:
`my spining top will start off as a cube
sync on : sync rate 60
phy start
`disable this for end of game print out
disable escapekey
`screen settings
set display mode 1280,800,32 :` change this if your screen setting differ
` set up backdrop
backdrop on
color backdrop rgb(0,0,0)
` set up camera
autocam off
return
`***((( Pause the physic`s )))***
physic_pause:
`*** pause physics ***
`if returnkey() = 1 and pause = 0 then pause = 1
if keystate(25) = 1 and pause = 0 then pause = 1
if pause = 1
set cursor screen width()/2.25,screen height()/2.25 :print "Physic Paused"
`phy update 0
inc count
if count >= 25
`if returnkey() = 1 then pause = 0
if keystate(25) = 1 then pause = 0
endif
else
count = 0
phy update
endif
return
`***((( fire the spining top )))***
fire_spining_top:
if mouseclick() = 1 and ID < 1001
if (currenttime-lastfiretime) > 1000
inc ID
angy# = camera angle y()
angx# = -camera angle X()
make object cube ID,1
color object ID,rgb(255,0,0)
position object ID,camera position x(),camera position y(),camera position z()
phy make rigid body dynamic box ID
phy set rigid body linear velocity ID,SPA(ID).speed#*sin(angY#)*cos(angX#),SPA(ID).speed#*sin(angX#),SPA(ID).speed#*cos(angY#)*cos(angX#)
`phy set rigid body angular momentum ID,0,10.0,0
phy set rigid body mass offset local ID, 0.0, -1.5, 0.0
`PHY SET RIGID BODY KINEMATIC ID,1
lastfiretime = timer()
SPA(ID).IDobj = ID
endif
endif
`if phy get rigid body exist(ID) = 1
for c = 1 to ID
if phy get rigid body exist(c) = 1
SPA(c).wvoax# = wrapvalue(object angle x(c)+0.5)
SPA(c).wvoay# = wrapvalue(object angle y(c)+0.5)
SPA(c).wvoaz# = wrapvalue(object angle z(c)+0.5)
PHY SET RIGID BODY angular momentum c, object angle x(c), SPA(c).wvoay#, SPA(c).wvoaz#
endif
next c
remstart
set cursor 0,120 : print ": ";phy get collision data ( )
while phy get collision data ( )
SPA(ID).col1 = phy get collision object a ( )
SPA(ID).col2 = phy get collision object b ( )
endwhile
if phy get collision data ( )
color object ID,rgb(0,255,0)
set cursor 0,100 : print "collision"
endif
set cursor 0,60 : print "collision A: ";SPA(ID).col1
set cursor 0,80 : print "collision B: ";SPA(ID).col2
SPA(c).wvoax# = wrapvalue(object angle x(c)-1.5)
SPA(c).wvoay# = wrapvalue(object angle y(c)+1.5)
SPA(c).wvoaz# = wrapvalue(object angle z(c)-1.5)
PHY SET RIGID BODY KINEMATIC ROTATION c,SPA(c).wvoax#,SPA(c).wvoay#,0.0 :`SPA(c).wvoay#,0.0 :`KINEMATIC
SPA(c).stpx# = object position x(c)
SPA(c).stpy# = object position y(c)
SPA(c).stpz# = object position z(c)
phy set rigid body KINEMATIC position c,SPA(c).stpx#,SPA(c).stpy#,SPA(c).stpz#
remend
`next c
`endif
return
`*********************************************************************
`*********************************************************************
`******[[[[[[ FUNCTION`S ]]]]]]******
`*********************************************************************
`*********************************************************************
`***((( Camera Control )))***
function camera_control()
rem camera rotation
yrotate camera camera angle y() + mousemovex()*0.3
xrotate camera camera angle x() + mousemovey()*0.3
rem stops mouse from going upside down
if wrapvalue(camera angle x(0))>100 and wrapvalue(camera angle x(0))<120 then xrotate camera 0,100
if wrapvalue(camera angle x(0))>180 and wrapvalue(camera angle x(0))<280 then xrotate camera 0,280
rem move the camera
if upkey()=1 or keystate(17) = 1 then move camera 0,1.5
if downkey()=1 or keystate(31) = 1 then move camera 0,-1.5
endfunction
soul sucking devils, twisted body of the damed, slivering slim drips from every poor, sin licking at your ears, and the smell stinging your eyes, and if you don't like it, get out of my kitchen!