This is test code.
TPS intersect collision
// 11
// TPS intersect collision
headersection:
sync on
sync rate 60
set display mode 800,600,32
MainSection:
REM DECLARE VARIABLES
Gravity# = 1 : rem How powerful gravity is
MyPower = 20 : rem How strong the player can jump
MySpeed = 10 : rem How fast the player can run
MyScore = 0 : rem Starting score is 0
MyAcceleration# = 0.0 : rem Start without jumping or falling
REM SCREEN DISPLAY
cls 0 : backdrop on
set global collision on
Rem Player Character
make object cube 1,10 : color object 1,rgb(255,0,0) //////////////
`scale object 1,100,100,100
position object 1,0,50,0
rotate object 1,0,90,0
`make object collision box 1,-25,-35,-25,25,35,25,0
`make object collision box 1, -50,-50,-50, 50,50,50, 0
SET OBJECT COLLISION TO SPHERES 1
make object cube 101,10 //////////////
scale object 101,200,200,200
position object 101, 1500,70,800
rotate object 101,0,450,0
make object cube 102,10 /////////
`scale object 102,1000000,1000000,1000000
position object 102, 2150,-220,200
rotate object 102,0,180,0
`automatic camera collision 0,5,0
`automatic object collision 1,15,0
rem Walls
rem North Wall
make object box 12,4000,1050,10
rotate object 12,0,0,0
position object 12, 0,500,1005
texture object 12,2
rem East Wall
make object box 13,4000,1050,10
rotate object 13,0,90,0
position object 13, 2000,500,0
texture object 13,3
rem North Wall
make object box 14,4000,1050,10
rotate object 14,0,180,0
position object 14, 0,500,-1005
texture object 14,4
rem West Wall
make object box 15,2000,1050,10
rotate object 15,0,270,0
position object 15, -2000,500,0
texture object 15,4
rem front left side of house
make object box 16,800,1050,10
rotate object 16,0,270,0
texture object 16,16
position object 16,500,500,480
` make object collision box 66,500,2000,10,510,2000,10,0
rem front right side of house
make object box 17,800,1050,10
rotate object 17,0,270,0
texture object 17,16
position object 17,500,500,-480
rem top portion of house
make object box 18,175,1050,10
rotate object 18, 0,270,0
texture object 18,16
position object 18, 500,700,0
rem first layer left of house
make object box 19,1500,1050,5
rotate object 19,0,180,0
position object 19,1250,500,880
texture object 19,11
rem first layer right of house
make object box 20,1500,1050,5
rotate object 20,0,180,0
position object 20,1250,500,-880
texture object 20,11
rem outer layer left of house
make object box 21,1500,1050,5
rotate object 21,0,180,0
position object 21,1250,500,883
texture object 21,16
rem outer layer left of house
make object box 22,1500,1050,5
rotate object 22,0,180,0
position object 22,1250,500,-883
texture object 22,16
rem Floor
make object box 23,4000,1000,2000 : position object 23,0,-500,0 : color object 23,rgb(0,255,0)
make object collision box 23, -2000,-500,-1000, 2000,500,1000, 0
`texture object 6,6 : scale object texture 6,1,1
rem Make a floor and create texture for it
create bitmap 1,32,32 : cls rgb(0,155,0) : ink rgb(0,145,0),0 : box 4,4,12,12
get image 1,0,0,32,32 : delete bitmap 1 : texture object 23,1
scale object texture 23,200,200 : ink rgb(255,255,255),0
remstart
rem Steps
for t=0 to 8
make object box t+7,50,50,50
position object t+7,0,-5000,-5000
texture object t+7,6
make object collision box t+7,-30,-30,-30,30,30,30,0
next t
remend
REM LOAD MODELS
REM SET COLLISIONS
REM SET CAMERA
REM SOUND EFFECTS
REM SPECIAL EFFECTS
REM REFRESH SCREEN
sync
REM *** MAIN SECTION LOOP
do
if scancode()=0 then exit
loop
autocam off
` CAMERA object
make object cube 100,50
make object collision box 100, -25,-25,-25, 25,25,25, 1
hide object 100
x as float
y as float
z as float
smooth =2
ps as float
ps = object size(1) ` player size
//------------ gameloop -------------------------------------------------------------
do
rem *** control
if upkey()=1 then move object 1,4
if downkey()=1 then move object 1,-4
if leftkey()=1 then yrotate object 1,wrapvalue(object angle y(1)-1)
if rightkey()=1 then yrotate object 1,wrapvalue(object angle y(1)+1)
move object down 1, 0.4 :` Gravity
x=object position x(1)
y=object position y(1)
z=object position z(1)
angleY#=object angle y(1)
for map=12 to 23
` X
if INTERSECT OBJECT(map, x,y,z, x+ps,y,z)>0 then x=x-(ps-INTERSECT OBJECT(map, x,y,z, x+ps,y,z))/smooth
if INTERSECT OBJECT(map, x,y,z, x-ps,y,z)>0 then x=x+(ps-INTERSECT OBJECT(map, x,y,z, x-ps,y,z))/smooth
` Z
if INTERSECT OBJECT(map, x,y,z, x,y,z+ps)>0 then z=z-(ps-INTERSECT OBJECT(map, x,y,z, x,y,z+ps))/smooth
if INTERSECT OBJECT(map, x,y,z, x,y,z-ps)>0 then z=z+(ps-INTERSECT OBJECT(map, x,y,z, x,y,z-ps))/smooth
` Y
if INTERSECT OBJECT(map, x,y,z, x,y-ps,z)>0 then y=y+(ps-INTERSECT OBJECT(map, x,y,z, x,y-ps,z))/smooth
next map
position object 1, x,y,z
rem Track hero with camera
x#=object position x(1)
y#=object position y(1)
z#=object position z(1)
angleY#=object angle y(1)
position camera x#,y#+30,z#
yrotate camera angleY#
move camera -100
rem collision camera
position object 100, x#,y+50,z#
yrotate object 100,angleY#
move object 100,-31
hit2= object collision(100 , 0 )
if hit2>0
rem change FPS view
position camera object position x(1), object position y(1), object position z(1)
yrotate camera angleY#
endif
gosub _debug
sync
loop
/// ----------- gameloop-end ------------------------------------------------
sync
set global collision off
end
_debug:
set cursor 0,0
print "debug info"
print "TPS INTERSECT collision "
print "screen fps "+str$(screen fps())
print "move cursor-key"
print x,y,z
print x#," ",y#," ",z#
print angleY#
print hit2
return