I am trying to make an fps game. However after spending hours trying to figure out how to code:
1.collision detection
2.enemy ai
ive ended up with a headache and a simple game half complete.
i would greatly appreciate any help with the coding.
`Setup
sync on
sync rate 30
draw to front
backdrop on
set camera range 1,5000
autocam off
hide mouse
fog on
fog distance 4000
fog color rgb(128,128,128)
color backdrop rgb(128,128,128)
`Sound
load sound "environment.wav",1
load sound "gunfire.wav",2
loop sound 1
`Texture
load image "Ground.jpg",1
load image "Wall.jpg",2
load bitmap "Radar.bmp",3
`Hud
make object plain 200,1,1
position object 200,-2.6,1.8,4
lock object on 200
ghost object on 200
make object plain 201,1,1
position object 201,2.6,1.8,4
lock object on 201
ghost object on 201
create bitmap 1,50,50
set current bitmap 0
`Matrix
make matrix 1,1000,1000,20,20
prepare matrix texture 1,1,1,1
fill matrix 1,0,1
randomize matrix 1,5
X#=100
Z#=100
`Gun
make object cylinder 1,2
Xrotate object 1,90
fix object pivot 1
scale object 1,100,100,500
position object 1,0,-7,15
lock object on 1
`Bullet
make object sphere 2,1
hide object 2
`Target
load object "idle.x",99
mX#=900
mY#= get ground height(1,900,900)-1
mZ#=900
position object 99,900,mY#,900
loop Object 99,0,20
`Wall
make object box 10,50,50,50
position object 10,500,30,500
texture object 10,2
`Main
do
oldcAY# = cAY#
oldcAX# = cAX#
cAY# = wrapvalue(cAY#+mousemoveX()*0.2)
cAX# = wrapvalue(cAX#+mousemoveY()*0.2)
caZ# = camera angle Z()
`Control
If upkey()=1
Xtest# = newxvalue(X#,cAY#,5)
Ztest# = newzvalue(Z#,cAY#,5)
if Xtest#>0 and Xtest#<1000 and Ztest#>0 and Ztest#<1000
X#=Xtest#
Z#=Ztest#
endif
endif
if downkey()=1
Xtest# = newxvalue(X#,wrapvalue(cAY#-180),5)
Ztest# = newzvalue(Z#,wrapvalue(cAY#-180),5)
if Xtest#>0 and Xtest#<1000 and Ztest#>0 and Ztest#<1000
X#=Xtest#
Z#=Ztest#
endif
endif
if leftkey()=1
Xtest# = newxvalue(X#,wrapvalue(cAY#-90),5)
Ztest# = newzvalue(Z#,wrapvalue(cAY#-90),5)
if Xtest#>0 and Xtest#<1000 and Ztest#>0 and Ztest#<1000
X#=Xtest#
Z#=Ztest#
endif
endif
if rightkey()=1
Xtest# = newxvalue(X#,wrapvalue(cAY#+90),5)
Ztest# = newzvalue(Z#,wrapvalue(cAY#+90),5)
if Xtest#>0 and Xtest#<1000 and Ztest#>0 and Ztest#<1000
X#=Xtest#
Z#=Ztest#
endif
endif
`Rotate Camera
if cAX#>180
if cAX#-270 > 90 then cAX#=270
else
if cAX# > 90 and cAX#-270<270 then cAX#=90
endif
Yrotate camera curveangle(cAY#,oldcAY#,24)
Xrotate camera curveangle(cAX#,oldcAX#,24)
`Position Camera
Y# = get ground height(1,X#,Z#)
position camera X#,Y#+35,Z#
`Position Listener
position listener X#,Y#+35,Z#
rotate listener 0,cAY#,0
`Shoot
if mouseclick()=1 and bulletlife=0
position object 2,X#,Y#+28,Z#
set object to camera orientation 2
bulletlife =25
show object 2
loop sound 2
endif
If bulletlife > 0
dec bulletlife
move object 2,20
bX#=object position X(2)
bY#=object position Y(2)
bZ#=object position Z(2)
position sound 2,bX#,bY#,bZ#
set cursor 10,10
if bulletlife = 0
hide object 2
stop sound 2
endif
endif
`Radar
copy bitmap 3,1
set current bitmap 1
ink rgb(0,0,255),rgb(0,0,0)
PRX#=X#/20
PRZ#=50-(Z#/20)
Circle PRX#,PRZ#,1
Get image 200,0,0,50,50
set current bitmap 0
texture object 200,200
ink rgb(255,128,128),rgb(0,0,0)
`Refresh
sync
loop