Ok I have the problem above solved, But I still can't figure out the collisions..
I have a box as my collision box, follows the camera x/y/z. And a small level. I believe I need to put something in my main loop, something like oldx and newx or something.
Here I load my objects:
world=9999 : Load object "Media\world\world.dbo",world
sc_setupobject world,0,0 `collisions
Rem Create player sphere
playerCOS=9997 : Make object box playerCOS, 2.5,6.5,1
sc_setupobject playerCOS,1,2 `collisions
Now somewhere in my main loop I need to add some code right? Not sure how to go about that though. Incase some good samaritan decides to help me
, here is my code:
Sync On : Sync rate 60
Backdrop off : Hide Mouse
Set display mode 1280,720,32
`make the loading screen
Set text font "arial" : Set text size 48
Set text to bold : Set text transparent
Sync : Center text screen width()/2, screen height()/2, "Loading..." : sync
`Subroutines
Gosub _Load_Media
Gosub _Setup_Media
Gosub Ammo
`Main loop
Do
Gosub AmmoView
Gosub _Player_Movement
Gosub _Player_Shoot
sync
Loop
`subroutine "_Load_Media"
_Load_Media:
Rem Load sounds
ambient=1 : Load sound "Media\sounds\ambient.wav", ambient
Loop sound ambient
m4_shoot=2 : Load sound "Media\sounds\m4\m4.wav", m4_shoot
empty=3 : Load sound "Media\sounds\m4\empty_gun.wav", empty
reload=4 : Load sound "Media\sounds\m4\reload.wav", reload
`Player walking sound effects
step1=5 : Load sound "Media\sounds\player\step1.wav", step1
step2=6 : Load sound "Media\sounds\player\step2.wav", step2
step3=7 : Load sound "Media\sounds\player\step3.wav", step3
step4=8 : Load sound "Media\sounds\player\step4.wav", step4
Rem Load Level
sky=9998 : Load object "Media\objects\sky.3ds",sky
world=9999 : Load object "Media\world\world.dbo",world
sc_setupobject world,0,0 `collisions
Rem Create player sphere
playerCOS=9997 : Make object box playerCOS, 2.5,6.5,1
sc_setupobject playerCOS,1,2 `collisions
Rem Objects
M4=1 : Load object "Media\objects\m4.3ds",M4
Rem Textures
crosshair=1 : Load image "Media\textures\crosshair.bmp",crosshair
m4_tex=3 : Load image "Media\textures\m4.jpg",m4_tex
sky_tex=4 : Load image "Media\textures\sky.jpg",sky_tex
Return
`subroutine "_Setup_Objects"
_Setup_Media:
`sets up the crosshair & HUD
Sprite 1, screen width()/2-16, screen height()/2-16,crosshair : Set sprite 1,0,1
`positions and locks the M4
Lock object on M4
Rotate object m4,0,-85,0
`Position objects
Position Object m4,2.5,-4,6
`disable object zdepth M4
Disable object zdepth m4
`Scale Objects
Scale object world, 4,4,4
Scale object sky, 1000,750,1000
Scale Object m4,5,5,5
`texture objects
Texture Object m4,m4_tex
Texture Object sky,sky_tex
`Position camera
Position camera 0,0,0
`Create bullet object
BulletObj=9995 : Make object cube BulletObj,0.1
Return
`subroutine "_Player_Movement"
_Player_Movement:
`center mouse
position mouse 320,240
yr# = camera angle y()
x# = camera position x()
y# = camera position y()
z# = camera position z()
`forwards (w)
if keystate(17)=1
x# = newxvalue(x#,wrapvalue(camera angle y()),.35)
z# = newzvalue(z#,wrapvalue(camera angle y()),.35)
endif
`backwards (s)
if keystate(31)=1
x# = newxvalue(x#,wrapvalue(camera angle y()-180),.25)
z# = newzvalue(z#,wrapvalue(camera angle y()-180),.25)
endif
`left (a)
if keystate(30)=1
x# = newxvalue(x#,wrapvalue(camera angle y()-90),.30)
z# = newzvalue(z#,wrapvalue(camera angle y()-90),.30)
endif
`right (d)
if keystate(32)=1
x# = newxvalue(x#,wrapvalue(camera angle y()+90),.30)
z# = newzvalue(z#,wrapvalue(camera angle y()+90),.30)
endif
REM Handles if two directional keys are pressed at once:
`Forward, right:
if keystate(32) and keystate(17)=1
x# = newxvalue(x#,wrapvalue(camera angle y()+90),-.10)
z# = newzvalue(z#,wrapvalue(camera angle y()+90),-.10)
x# = newxvalue(x#,wrapvalue(camera angle y()),-.15)
z# = newzvalue(z#,wrapvalue(camera angle y()),-.15)
endif
`Forward, Left:
if keystate(30) and keystate(17)=1
x# = newxvalue(x#,wrapvalue(camera angle y()-90),-.10)
z# = newzvalue(z#,wrapvalue(camera angle y()-90),-.10)
x# = newxvalue(x#,wrapvalue(camera angle y()),-.15)
z# = newzvalue(z#,wrapvalue(camera angle y()),-.15)
endif
`Backward, right:
if keystate(32) and keystate(31)=1
x# = newxvalue(x#,wrapvalue(camera angle y()-180),-.10)
z# = newzvalue(z#,wrapvalue(camera angle y()-180),-.10)
x# = newxvalue(x#,wrapvalue(camera angle y()+90),-.10)
z# = newzvalue(z#,wrapvalue(camera angle y()+90),-.10)
endif
`Backward, Left:
if keystate(31) and keystate(30)=1
x# = newxvalue(x#,wrapvalue(camera angle y()-180),-.10)
z# = newzvalue(z#,wrapvalue(camera angle y()-180),-.10)
x# = newxvalue(x#,wrapvalue(camera angle y()-90),-.10)
z# = newzvalue(z#,wrapvalue(camera angle y()-90),-.10)
endif
`Forwards,Back:
if keystate(17) and keystate(31)=1
x# = newxvalue(x#,wrapvalue(camera angle y()),.-.4)
z# = newzvalue(z#,wrapvalue(camera angle y()),.-.4)
x# = newxvalue(x#,wrapvalue(camera angle y()-180),-.30)
z# = newzvalue(z#,wrapvalue(camera angle y()-180),-.30)
endif
`camera rotation
yrotate camera camera angle y() + mousemovex()*0.3
xrotate camera camera angle x() + mousemovey()*0.3
`stops mouse from going upside down
if wrapvalue(camera angle x(0))>70 and wrapvalue(camera angle x(0))<180 then xrotate camera 0,70
if wrapvalue(camera angle x(0))>180 and wrapvalue(camera angle x(0))<280 then xrotate camera 0,280
`camera position
position camera x#,y#,z#
`Elevates camera
position camera x#,6.5,z#
`Makes sky follow player position
Position object sky, x#,y#,z#
`Makes the player collision box follow/rotate as player
Position object playerCOS, x#,y#,z#
yRotate object playerCOS, yr#
Rem plays sound effects when walking!
`forwards (w)
if keystate(17)=1 and walkTimer <= timer()
walkTimer = Timer()+300
Play sound step1
endif
`backwards (s)
if keystate(31)=1 and walkTimer <= timer()
walkTimer = Timer()+300
Play sound step2
endif
`left (a)
if keystate(30)=1 and walkTimer <= timer()
walkTimer = Timer()+300
Play sound step3
endif
`right (d)
if keystate(32)=1 and walkTimer <= timer()
walkTimer = Timer()+300
Play sound step4
endif
_Player_Shoot:
`Reduces by 1 ammo and plays sound
if ammo > 0 and Mouseclick()=1 and ammoTimer <= timer() and reloadTimer <= timer()
dec ammo,1
ammoTimer = timer()+50
Play sound m4_shoot
`Defines Kick Variable and puts to use
KickN = -1
KickLR = (-1 and 1)
xrotate camera camera angle x() + KickN
yrotate camera camera angle y() + KickLR
`Handels the shot
bullet=100
position object BulletObj,camera position x(0),camera position y(0),camera position z(0)
rotate object BulletObj,camera angle x(0),camera angle y(0),0
move object BulletObj,5
rem Move bullet
dec bullet
move object BulletObj,0.01
endif
`If ammo less than 1 then plays clip empty sound
if ammo < 1 and Mouseclick()=1 and ammoTimer <= timer() and reloadTimer <= timer()
ammoTimer = timer()+250
Play sound empty
Endif
`Reload
if keystate(19) = 1 and reloadTimer <= timer()
reloadTimer = timer()+500
Play sound reload
Play object m4,0,20
Gosub Ammo
endif
Return
AmmoView:
Set text font "arial" : Set text size 24
SET CURSOR 10,10
Print screen fps()
SET CURSOR 1180,670
Print "Ammo: ", Ammo
Return
`Variables
Ammo:
`Sets amount of ammo
Ammo=30
Return
Gravity = -.1
ProphetHill