ill post this in case some1 might actually be interested :
i did find out how to make my bullets move,
basic collision detection is working too
this is my code so far :
sync on
hide mouse
sync rate 60
set display mode 1024,768,32
rem set these vars as globals
rem they or called in loop function and come from a copied funtion
rem to determine mouse position in 3d
global mouse3d_x#
global mouse3d_y#
global mouse3d_z#
rem -------- make rnd texture for testing
for a=1 to 3
for b=1 to 3
ink rgb(rnd(255),rnd(255),rnd(255)),1
box -64+a*64,-64+b*64,a*64,b*64
next a
next b
get image 1,0,0,256,256
rem ------ make matrix
make matrix 1,2000,2000,25,25
' randomize matrix 1,10
prepare matrix texture 1,1,1,1
rem --- setup some vars
rem cam focal
FOV#=60
rem cam range
camr#=10000
rem original speed, user for turbo/shift key
rem should be identical to speed#, since bad coding
original_speed#=5
rem actual speed
speed#=5
rem player start pos
posx#=500.0
posz#=500.0
rem font color
ink rgb(255,0,0),rgb(0,0,0)
REM ------ bullets setup
max_bullets_on_screen# = 99
bullets_on_screen# = 0
bullets_until_reload# = 25
bullets_until_reload_count# = 0
time_between_bullets# = 200
bullet_life# = 15000
time_since_last_bullet# = timer()
bullet_id# = 0
dim bullet$(100,6)
rem make bullets and put them in objects 100 to 199
for i=0 to max_bullets_on_screen#
objid# = 100+bullet_id#
make object cube objid#,5
ghost object on objid#,0
bullet_id# = bullet_id# + 1
bullet$(i,0) = str$(0)
bullet$(i,1) = "setup"
bullet$(i,2) = "niks"
bullet$(i,3) = "x"
bullet$(i,4) = "y"
bullet$(i,5) = "z"
set object collision on objid#
set object collision to boxes objid#
next i
rem bullet_id setting to zero again just to be safe
bullet_id# = 0
rem ------- end bullets setup
rem Make walls
make object box 10, 2000, 100, 5
position object 10, 1000, 0, 0
make object box 11, 2000, 100, 5
position object 11, 1000, 0, 2000
make object box 12, 5, 100, 2000
position object 12, 2000, 0, 1000
make object box 13, 5, 100, 2000
position object 13, 0, 0, 1000
rem Make enemies
dim enemy$(100,3)
for i=0 to 99
objid# = 900+i
make object cube objid#,50
color object objid#,rgb(rnd(255),rnd(255),rnd(255))
position object objid#, rnd(2000),25,rnd(2000)
enemy$(i,1) = "alive"
set object collision on objid#
set object collision to boxes objid#
next i
rem Make player
make object box 1,30,10,100
color object 1,rgb(0,0,255)
rem front
make object box 50,15,5,15
MAKE MESH FROM OBJECT 20, 50
delete object 50
ADD LIMB 1, 1, 20
delete mesh 20
show limb 1, 1
SCALE LIMB 1, 1, 100, 100, 100
OFFSET LIMB 1, 1, 0,0,50
rem back
make object box 50,25,4,4
MAKE MESH FROM OBJECT 20, 50
delete object 50
ADD LIMB 1, 2, 20
delete mesh 20
show limb 1, 2
SCALE LIMB 1, 2, 100, 100, 100
OFFSET LIMB 1, 2, 0,5,-50
rem Make turret
make object box 2,10,10,15
color object 2,rgb(255,0,0)
make object box 50,5,5,40
MAKE MESH FROM OBJECT 20, 50
delete object 50
ADD LIMB 2, 1, 20
delete mesh 20
show limb 2, 1
SCALE LIMB 2, 1, 100, 100, 100
OFFSET LIMB 2, 1, 0,0,25
rem make mouse
make object sphere 3,20
rem make pointer outside of matrix, extending turret
make object sphere 4,1
hide object 4
rem hud font
SET TEXT SIZE 20
set text to bold
rem ------- cam setup
set camera fov FOV#
rem pov cam
MAKE CAMERA 2
SET CAMERA VIEW 2, 40, screen height()-100, 165, screen height()-5
rem turret cam
MAKE CAMERA 3
SET CAMERA VIEW 3, 190, screen height()-100, 315, screen height()-5
rem mouse cam
MAKE CAMERA 4
SET CAMERA VIEW 4, 340, screen height()-100, 465, screen height()-5
rem overview cam
MAKE CAMERA 5
SET CAMERA VIEW 5, 490, screen height()-100, 615, screen height()-5
rem Begin main loop
rem -------------------------------------------
do
rem call 3dmouse positioning function, copied from codebase
mmcoord(mousex(),mousey(),1,camr#,FOV#)
rem ------- Controls
rem forwards (z) (azerty layout)
if keystate(17)=1 or upkey()=1
posx#=newxvalue(posx#, angle#, speed#)
posz#=newzvalue(posz#, angle#, speed#)
endif
rem backwards (s) (azerty layout)
if keystate(31)=1 or downkey()=1
posx#=newxvalue(posx#, angle#, 0-(speed#/3))
posz#=newzvalue(posz#, angle#, 0-(speed#/3))
endif
rem left (q) (azerty layout)
if keystate(30)=1 or leftkey()=1
angle#=wrapvalue(angle#-(speed#/2))
endif
rem right (d) (azerty layout)
if keystate(32)=1 or rightkey()=1
angle#=wrapvalue(angle#+(speed#/2))
endif
rem strafe links (a) (azerty layout)
if keystate(16)=1
posx#=newxvalue(posx#, angle#-90, speed#/3)
posz#=newzvalue(posz#, angle#-90, speed#/3)
endif
rem strafe rechts (e) (azerty layout)
if keystate(18)=1
posx#=newxvalue(posx#, angle#+90, speed#/3)
posz#=newzvalue(posz#, angle#+90, speed#/3)
endif
REM start shift/turbo check
if shiftkey()=1
if turbo# = 0
speed# = speed#*2
turbo# = 1
endif
endif
if shiftkey()=0
turbo# = 0
speed# = original_speed#
endif
REM end shift/turbo check
rem end controls
rem a temp solution for rightmouse+space bug
if bullets_on_screen# > max_bullets_on_screen#
bullets_on_screen# = max_bullets_on_screen#
endif
if bullets_on_screen# < 0
bullets_on_screen# = 0
endif
rem start bullet check
for i=0 to max_bullets_on_screen#
objid# = 100+i
if object exist(objid#) = 1
if bullet$(i,1) = "fired"
if val(bullet$(i,0)) < timer() - bullet_life#
hide object objid#
bullets_on_screen# = bullets_on_screen# - 1
bullet$(i,1) = "hidden"
else
move object objid#, 20
if object collision (objid#,0)
obj_hit# = object collision (objid#,0)
if 1000 > obj_hit# > 899
obj_hit_id = obj_hit# - 900
enemy$(obj_hit_id,1) = "dead"
enemy$(obj_hit_id,2) = str$(timer())
hide object objid#
set object collision off objid#
bullet$(i,1) = "hidden"
endif
if 14 > obj_hit# > 9
hide object objid#
set object collision off objid#
bullet$(i,1) = "hidden"
endif
endif
if object position x(objid#) > 2000
hide object objid#
set object collision off objid#
endif
if object position z(objid#) > 2000
hide object objid#
set object collision off objid#
endif
if object position x(objid#) < 0
hide object objid#
set object collision off objid#
endif
if object position z(objid#) < 0
hide object objid#
set object collision off objid#
endif
endif
endif
if bullet$(i,1) = "setup"
hide object objid#
bullet$(i,1) = "hidden"
endif
endif
next i
rem end bullet check
rem start enemy check
for i=0 to 99
objid# = 900+i
if object exist(objid#) = 1
if enemy$(i,1) = "dead"
hide object objid#
set object collision off objid#
if val(enemy$(i,2)) < timer() - 30000
show object objid#
set object collision on objid#
position object objid#, rnd(2000),25,rnd(2000)
enemy$(i,1) = "alive"
endif
endif
if enemy$(i,1) = "alive"
point object objid#, object position x(2),object position y(2),object position z(2)
move object objid#, speed#/20
endif
endif
next i
rem end enemy check
rem mouseclick for bullets
if mouseclick()=1 or spacekey()=1
text 400,0, "left mouse button"
if bullets_until_reload_count# < bullets_until_reload#
if time_since_last_bullet_fired# < timer() - time_between_bullets#
bullet_id# = bullet_id# + 1
bullets_on_screen# = bullets_on_screen# + 1
if bullet_id# > max_bullets_on_screen#
bullet_id# = 0
endif
objid# = 100+bullet_id#
crap = bullet_id#
if bullet$(crap,1) = "fired"
rem search for next non-fired bullet
endif
bullet$(crap,0) = str$(timer())
bullet$(crap,1) = "fired"
bullet$(crap,3) = str$(object position x(4))
bullet$(crap,4) = str$(object position y(4))
bullet$(crap,5) = str$(object position z(4))
show object objid#
set object collision on objid#
position object objid#, object position x(2),object position y(2),object position z(2)
point object objid#, mouse3d_x#,object position y(2),mouse3d_z#
remstart check between turret and mousepointer
for i=900 to 999
if intersect object (i, object position x(2),object position y(2),object position z(2), mouse3d_x#,mouse3d_y#,mouse3d_z#) > 0
text 10, 240, "HIT : "+str$(i)+" at : "+str$(intersect object (i, object position x(2),object position y(2),object position z(2), mouse3d_x#,mouse3d_y#,mouse3d_z#))
hide object i
endif
next i
remend
remstart check between turret and obj4 being extended turret outside of matrix
for i=900 to 999
if enemy$(i-900,1) = "alive"
if intersect object (i, object position x(2),object position y(2),object position z(2), object position x(4),object position y(4),object position z(4)) > 0
text 10, 240, "HIT : "+str$(i)+" at : "+str$(intersect object (i, object position x(2),object position y(2),object position z(2), object position x(4),object position y(4),object position z(4)))
hide object i
enemy$(i-900,1) = "dead"
enemy$(i-900,2) = str$(timer())
endif
endif
next i
remend
time_since_last_bullet_fired# = timer()
bullets_until_reload_count# = bullets_until_reload_count# + 1
endif
endif
endif
if mouseclick()=2
text 400,0, "right mouse button"
rem rightmouse button reload
bullets_until_reload_count# = 0
endif
if mouseclick()=4
text 400,0, "middle mouse button"
endif
rem groundheight under player
ground#=get ground height(1,posx#,posz#)+5
rem update player
if posx# >= 2000 then posx# = 2000
if posx# <= 0 then posx# = 0
if posz# >= 2000 then posz# = 2000
if posz# <= 0 then posz# = 0
position object 1,posx#,ground#+5,posz#
yrotate object 1,angle#
rem update turret
position object 2,object position x(1),ground#+15,object position z(1)
point object 2, mouse3d_x#,ground#+15,mouse3d_z#
rem update mousebox
border_mouse3d_x# = mouse3d_x#
border_mouse3d_y# = mouse3d_y#
border_mouse3d_z# = mouse3d_z#
if border_mouse3d_x# >= 2000 then border_mouse3d_x# = 2000
if border_mouse3d_x# <= 0 then border_mouse3d_x# = 0
if border_mouse3d_z# >= 2000 then border_mouse3d_z# = 2000
if border_mouse3d_z# <= 0 then border_mouse3d_z# = 0
position object 3, border_mouse3d_x#,border_mouse3d_y#,border_mouse3d_z#
circle mousex(),mousey(),2
rem pointer_border_mouse3d_x# = mouse3d_x#
rem pointer_border_mouse3d_y# = mouse3d_y#
rem pointer_border_mouse3d_z# = mouse3d_z#
rem if pointer_border_mouse3d_x# >= 2000 then pointer_border_mouse3d_x# = 2000
rem if pointer_border_mouse3d_x# <= 0 then pointer_border_mouse3d_x# = 0
rem if pointer_border_mouse3d_z# >= 2000 then pointer_border_mouse3d_z# = 2000
rem if pointer_border_mouse3d_z# <= 0 then pointer_border_mouse3d_z# = 0
rem position object 4, pointer_border_mouse3d_x#,pointer_border_mouse3d_y#,pointer_border_mouse3d_z#
position object 4,object position x(1),ground#+15,object position z(1)
point object 4, mouse3d_x#,ground#+15,mouse3d_z#
move object 4, 2000+50
rem cam1
camposition# = mousez()
if camposition# < -240 then camposition# = -240
if camposition# = -240
new_cam1x# = 200
new_cam1y# = 100
new_cam1z# = 200
endif
if camposition# = -120
new_cam1x# = 200
new_cam1y# = 200
new_cam1z# = 200
endif
if camposition# = 0
new_cam1x# = 200
new_cam1y# = 400
new_cam1z# = 200
endif
if camposition# = 120
new_cam1x# = 200
new_cam1y# = 600
new_cam1z# = 200
endif
if camposition# = 240
new_cam1x# = 200
new_cam1y# = 800
new_cam1z# = 200
endif
if camposition# = 360
new_cam1x# = 200
new_cam1y# = 1000
new_cam1z# = 200
endif
if camposition# = 480
new_cam1x# = 200
new_cam1y# = 1200
new_cam1z# = 200
endif
if camposition# = 600
new_cam1x# = 200
new_cam1y# = 1400
new_cam1z# = 200
endif
if camposition# = 720
new_cam1x# = 1000
new_cam1y# = 100
new_cam1z# = 1000
endif
if camposition# = 840
new_cam1x# = 1000
new_cam1y# = 200
new_cam1z# = 1000
endif
if camposition# = 960
new_cam1x# = 1000
new_cam1y# = 400
new_cam1z# = 1000
endif
if camposition# = 1080
new_cam1x# = 1000
new_cam1y# = 600
new_cam1z# = 1000
endif
if camposition# = 1200
new_cam1x# = 1000
new_cam1y# = 800
new_cam1z# = 1000
endif
if camposition# = 1320
new_cam1x# = 1000
new_cam1y# = 1000
new_cam1z# = 1000
endif
if camposition# = 1480
new_cam1x# = 1000
new_cam1y# = 1200
new_cam1z# = 1000
endif
if camposition# > 1320
new_cam1x# = 1000
new_cam1y# = camposition#
new_cam1z# = 1000
endif
if camposition# > 2640
new_cam1x# = 1000
new_cam1y# = 2640
new_cam1z# = 1000
endif
position camera new_cam1x#,new_cam1y#,new_cam1z#
POINT CAMERA posx#,posy#,posz#
rem cam2
text 50, screen height()-100, "pov cam"
position camera 2,object position x(1),object position y(1)+20,object position z(1)
point camera 2, object position x(2)+LIMB OFFSET X(2,1),object position y(2)+LIMB OFFSET Y(2,1),object position z(2)+LIMB OFFSET Z(2,1)
rem cam3
position camera 3,posx#,posy#+ground#+40,posz#
point camera 3, mouse3d_x#,mouse3d_y#+10,mouse3d_z#
text 200, screen height()-100, "turret cam"
rem cam4
position camera 4, mouse3d_x#,250,mouse3d_z#
POINT CAMERA 4, mouse3d_x#,mouse3d_y#+10,mouse3d_z#
text 500, screen height()-100, "overview cam"
rem cam5
position camera 5, 1000,500,1000
POINT CAMERA 5, posx#,posy#,posz#
text 350, screen height()-100, "mouse cam"
text 10, 0, "fps : "+STR$(SCREEN FPS())
text 10, 15, "max_bullets_on_screen: "+str$(bullets_on_screen#)+"/"+str$(max_bullets_on_screen#)
text 10, 30, "reload: "+str$(bullets_until_reload_count#)+"/"+str$(bullets_until_reload#)
text 10, 45, "bullet_id#: "+str$(bullet_id#)
text 10, 60, ""
text 10, 75, ""
text 10, 90, "mousex: "+str$(mousex())
text 10, 105, "mousey: "+str$(mousey())
text 10, 120, "mousez: "+str$(mousez())
text 10, 135, "mouse3d_x: "+str$(mouse3d_x#)
text 10, 150, "mouse3d_y: "+str$(mouse3d_y#)
text 10, 165, "mouse3d_z: "+str$(mouse3d_z#)
text 10, 180, "posx: "+str$(posx#)
text 10, 195, "posy: "+str$(posy#)
text 10, 210, "posz: "+str$(posz#)
text 10, 225, "timer: "+str$(timer())
rem Update Screen
sync
loop
function mmcoord(scrx#,scry#,matnum,r#,FOV#)
ax#=camera angle x()
ay#=camera angle y()
scrw#=screen width()
scrh#=screen height()
hmax# = r#*tan(FOV#/2)
mh# = (((scrh#/2-scry#)*2)/scrh#)*hmax#
wmax# = r#*scrw#/scrh#*tan(FOV#/2)
mw# = (((scrx#-scrw#/2)*2)/scrw#)*wmax#
cl# = r#*cos(ax#)
ch# = -r#*sin(ax#)
sl# = mh#*cos(90-ax#)
sh# = mh#*sin(90-ax#)
ox# = camera position x() + (cl#+sl#)*sin(ay#) + mw#*cos(ay#)
oy# = camera position y() + (ch#+sh#)
oz# = camera position z() + (cl#+sl#)*cos(ay#) - mw#*sin(ay#)
for i#=0 to 1 step (1.0/r#)
x# = camera position x() + (ox#-camera position x())*i#
y# = camera position y() + (oy#-camera position y())*i#
z# = camera position z() + (oz#-camera position z())*i#
if y#-get ground height(matnum,x#,z#)<=0
mouse3d_x#=x#
mouse3d_y#=y#
mouse3d_z#=z#
exitfunction
endif
next i#
endfunction
sqdz (azerty layout), use cursorkeys for qwerty
q=left
d=right
z=up
s=down
leftmouse=shoot
rightmouse=reload
scrollwheel = cam height
if anyone would like to make a comment/suggestion on my code, they're more then welcome to...