with force :
sync on
sync rate 60
backdrop on
autocam off
color backdrop rgb(219,220,253)
Randomize Timer()
Set Normalization On
set camera range 0.1,9000
phy start
phy set gravity 0.0,-20.0,0.0
phy make material 1,"player"
phy set material restitution 1, 0.0
phy set material dynamic friction 1, 0.1
phy set material static friction 1, 0.1
phy build material 1
`make room
make object box 10,10,0.5,10
position object 10,0,0,0
make object box 11,10,5,0.5
position object 11,0,0,-5
make object box 12,10,5,0.5
position object 12,0,0,5
make object box 13,0.5,5,10
position object 13,-5,0,0
make object box 14,0.5,5,10
position object 14,5,0,0
for room = 10 to 14
phy make rigid body static box room
color object room,rgb(0,0,255)
next room
`make player
make object sphere 2,1
position object 2,0,5,0
make object sphere 3,1
position object 3,0,5,0
phy make rigid body dynamic sphere 3,1
phy set rigid body mass 3,100
`make dynamic box
make object cube 4,0.5
position object 4,2,10,2
phy make rigid body dynamic box 4
phy set rigid body mass 4,3
decal_bullet = 20
do
position mouse Screen Width()/2.0,Screen Height()/2.0
phy set rigid body linear damping 3,8
position object 2,object position x(3),object position y(3),object position z(3)
` rotate and position camera
OldCamAngleY# = CameraAngleY#
OldCamAngleX# = CameraAngleX#
CameraAngleY# = wrapvalue ( CameraAngleY# + mousemovex ( ) * 0.4 )
CameraAngleX# = wrapvalue ( CameraAngleX# + mousemovey ( ) * 0.4 )
yrotate object 2, curveangle ( CameraAngleY#, OldCamAngleY#, 24 )
xrotate camera curveangle ( CameraAnglex#, OldCamAnglex#, 24 )
if keystate(42)=1
speed#=0.02
else
speed#=0.04
endif
if keystate(17)=1
move object 2, speed#
endif
if keystate(31)=1
move object 2, -speed#
endif
if keystate(30)=1
move object left 2, speed#
endif
if keystate(32)=1
move object right 2, speed#
endif
player_x#=object position x(2)
player_y#=object position y(2)
player_z#=object position z(2)
phy set rigid body position 3, player_x#, player_y#+1, player_z#
`-------------chooting-----------------
if mouseclick()=1 and MOUSE =0
MOUSE = 1
x# = camera position x()
y# = camera position y()
z# = camera position z()
move camera 1
xvec# = camera position x() - x#
yvec# = camera position y() - y#
zvec# = camera position z() - z#
move camera -1
`ray cast
temp = phy ray cast all shapes(x#,y#,z#,xvec#,yvec#,zvec#)
if phy get ray cast hit()
hitObject = phy get ray cast object()
hitmass# =PHY GET RIGID BODY MASS(hitObject)
x1# = phy get ray cast hit point x()
y1# = phy get ray cast hit point y()
z1# = phy get ray cast hit point z()
xn1# = phy get ray cast hit normal x()
yn1# = phy get ray cast hit normal y()
zn1# = phy get ray cast hit normal z()
decal_bullet = decal_bullet+1
make object box decal_bullet,0.05,0.05,0.001
position object decal_bullet,x1#,y1#,z1#
color object decal_bullet,rgb(214,22,22)
point object decal_bullet,xn1#+x1#,yn1#+y1#,zn1#+z1#
if hitmass# > 0.0
Phy Add Rigid Body Force hitObject,Sin(object angle y(2))*30,0.0,cos(object angle y(2))*30,2
endif
endif
endif
mouseclick() = 0
if mouseclick() = 0 then MOUSE = 0
` screen info
text 20,20,str$( screen fps())
text 20,45,"hitObject: "+str$(hitObject)
position camera object position x(2),object position y(2),object position z(2)
rotate camera camera angle x(),object angle y(2),object angle z(2)
phy set rigid body position 3, object position x(2),object position y(2),object position z(2)
phy set rigid body rotation 3, object angle x(2),object angle y(2),object angle z(2)
phy update
sync
loop