OK, try sparky`s DLL. It has all of the commands you know for collision, and it is blazingly fast. I can`t find where to download it, but I will come back with a link.
Just use "load dll" to load it(it must be in the main directory), and then use the commands in the help file...
And if your darkbasic is not enhanced, work on this:
rem setup screen
sync on
sync rate 60
backdrop on
color backdrop 0
hide mouse
rem create game elements
gosub create_textures
gosub create_room
rem main loop
do
rem user help
center text 320,20,"USE ARROWS TO MOVE AND SPACE TO JUMP"
center text 320,40,"TheComet"
rem control game elements
gosub control_block
gosub control_player
rem refresh screen
sync
rem end of main loop
loop
rem end
END
rem ****************************************
rem * SUBROUTINES *
rem ****************************************
control_player:
rem player positions
x#=object position x(11)
y#=object position y(11)
z#=object position z(11)
rem move player
if upkey()=1 then move object 11,3
if downkey()=1 then move object 11,-3
if leftkey()=1 then yrotate object 11,wrapvalue(object angle y(11)+2)
if rightkey()=1 then yrotate object 11,wrapvalue(object angle y(11)+2)
if spacekey()=1 and grav#=0.0 then grav#=2
rem gravity
dec grav#,0.1
inc y#,grav#
rem collision
position object 11,x#,y#,z#
if object collision(11,0)>0
dec x#,get object collision x()
dec y#,get object collision y()
dec z#,get object collision z()
if get object collision y()<>0 then grav#=0.0
endif
rem update player positions
position object 11,x#,y#,z#
return
control_block:
rem move a block up and down
inc sine:sine=wrapvalue(sine)
sy#=(sin(sine)*120)+80
position object 10,300,sy#,0
return
create_textures:
rem generate ground texture
create bitmap 1,64,64
ink rgb(50,50,50),0
box 0,0,63,63
for t=1 to 1000
x1=rnd(64)
x2=rnd(64)
y=rnd(64)
i=rnd(50)+30
ink rgb(i,i,i),0
line x1,y,x2,y
next t
get image 2,0,0,64,64
delete bitmap 1
rem make ground texture tiles
create bitmap 1,64,64
rotate image 2,90
set current bitmap 1
paste image 2,0,0
get image 3,0,0,64,64
delete bitmap 1
create bitmap 1,128,128
paste image 3,0,0
paste image 2,64,0
paste image 3,0,64
paste image 2,64,64
get image 1,0,0,128,128
delete bitmap 1
rem clean up
delete image 2
delete image 3
rem create wall texture
create bitmap 1,64,64
ink rgb(150,150,150),0
box 0,0,32,32
box 32,32,63,63
ink rgb(60,60,60),0
box 32,0,63,32
box 0,32,32,63
get image 2,0,0,64,64
delete bitmap 1
return
create_room:
rem four walls
make object box 1,1000,500,10:position object 1,0,250,500
make object box 2,1000,500,10:position object 2,0,250,-500
make object box 3,10,500,1000:position object 3,500,250,0
make object box 4,10,500,1000:position object 4,-500,250,0
rem texture walls
for t=1 to 4
texture object t,2
scale object texture t,16,16
next t
rem make floor
make object box 5,1000,10,1000
position object 5,0,0,0
texture object 5,1
scale object texture 5,16,16
rem make some steps
for t=6 to 10
make object box t,50,8,50
texture object t,2
scale object texture t,4,4
next t
rem position steps
position object 6,100,30,0
position object 7,150,50,0
position object 8,200,80,0
position object 9,400,200,0
position object 10,300,80,0
rem make player
make object cylinder 11,10
color object 11,rgb(255,0,0)
rem setup box collision
for t=1 to 11
x#=object size x(t)/2
y#=object size y(t)/2
z#=object size z(t)/2
make object collision box t,0-x#,0-y#,0-z#,x#,y#,z#,0
next t
return
This uses sliding box collision. It is very simple to use for simple games (yeah, I even used it in "Jack in the Box" in peachy...), but for more complex levels this wont work...
If you put a rotating collision box around everything (make object collision box <object>,<-x>,<-y>,<-z>,<x>,<y>,<z>,
1), the collision box will rotate with the object, you can detect collision, but you can`t use "get object collision x(),y() or z()"...
I am not sure if this is faster, but you can check if the objects are overlapping with variables and set the collision off, and if the other objects variables is bigger or smaller than your variables, then collision=1.
rem setup screen
sync on
sync rate 60
backdrop on
color backdrop 0
hide mouse
rem make 2 boxes
make object box 1,10,20,2:color object 1,rgb(0,0,255)
make object box 2,5,10,40:color object 2,rgb(255,0,0)
rem main loop
startx=200
do
rem move object 2 towards object 1
dec startx
position object 2,startx,0,0
rem check collision
col=collision_state(1,2)
rem print state
if col=0 then center text 320,20,"OBJECTS ARE NOT OVERLAPPING"
if col=1 then center text 320,20,"OBJECT ARE OVERLAPPING!!!!!!!!"
rem refresh screen
sync
rem end of main loop
loop
rem end
END
rem functions
function collision_state(obj1,obj2)
rem get positions
x1#=object position x(obj1)
x2#=object position x(obj2)
y1#=object position y(obj1)
y2#=object position y(obj2)
z1#=object position z(obj1)
z2#=object position z(obj2)
rem get sizes
sx1#=object size x(obj1)
sx2#=object size x(obj2)
sy1#=object size y(obj1)
sy2#=object size y(obj2)
sz1#=object size z(obj1)
sz2#=object size z(obj2)
rem check for overlapping
collision=0
if x1#+sx1#>x2#-sx2# or x1#-sx1#<x2#+sx2#
if y1#+sy1#>y2#-sy2# or y1#-sy1#<y2#+sy2#
if z1#+sz1#>z2#-sz2# or z1#-sz1#<z2#+sz2#
collision=1
endif
endif
endif
endfunction collision
This will only work with boxes though, not high complex levels like in SoulHunter.
Suicide is away of telling God, You can’t fire me I quit !!!!!