try this new code :
Rem * Title : Learning The Basic
Rem * Author : Per Porserot
Rem * Date : 1337 ?? 1337 ? the YEAR 1337 ? lol :)
Sync On
Sync Rate 30
Hide Mouse
Backdrop on
Set camera range 1,5000
Fog on
Fog distance 4000
Fog color RGB(128,128,128)
Color Backdrop RGB(128,128,128)
REM Make matrix
Make matrix 1,10000,10000,20,20
REM texture matrix
create bitmap 1,128,128
set current bitmap 1
for x = 1 to 128
for y = 1 to 128
dot x,y,rgb(0,rnd(255),0)
next y
next x
get image 1,1,1,128,128
set current bitmap 0
rem Load image "grass09.bmp",1
Prepare matrix texture 1,1,1,1
Fill matrix 1,0,1
REM Randomize the matrix
randomize matrix 1,125
update matrix 1
X#=5000
Z#=5000
REM Make 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
REM Make Bullet
Make Object sphere 2,2
Hide Object 2
REM Load Sound
rem Load Sound "crickets.wav",1
rem Loop Sound 1
Load 3Dsound "fireball2.wav",2
rem loading an other sound.... :)
load 3dsound "C:\Program Files\Dark Basic Software\Dark Basic\media\sounds\impact\strike.wav",3
REM Main loop
Do
set cursor 0,0
print bulletlife
OldCamAngleY# = CameraAngleY#
OldCamAngleX# = CameraAngleX#
CameraAngleY# = WrapValue(CameraAngleY#+MousemoveX()*0.2)
CameraAngleX# = WrapValue(CameraAngleX#+MousemoveY()*0.2)
REM Control input for camera
If Upkey()=1
XTest# = newxvalue(X#,CameraAngleY#,10)
ZTest# = newzvalue(Z#,CameraAngleY#,10)
If XTest#>0 and XTest#<10000 and ZTest#>0 and ZTest#<10000
X#=XTest#
Z#=ZTest#
Endif
Endif
If Downkey()=1
XTest# = Newxvalue(X#,Wrapvalue(CameraAngleY#-180),10)
ZTest# = Newzvalue(Z#,Wrapvalue(CameraAngleY#-180),10)
If XTest#>0 and XTest#<10000 and ZTest#>0 and ZTest#<10000
X#=XTest#
Z#=ZTest#
Endif
Endif
If Leftkey()=1
XTest# = Newxvalue(X#,Wrapvalue(CameraAngleY#-90),10)
ZTest# = Newzvalue(Z#,Wrapvalue(CameraAngleY#-90),10)
If XTest#>0 and XTest#<10000 and ZTest#>0 and ZTest#<10000
X#=XTest#
Z#=ZTest#
Endif
Endif
If Rightkey()=1
XTest# = Newxvalue(X#,Wrapvalue(CameraAngleY#+90),10)
ZTest# = Newzvalue(Z#,Wrapvalue(CameraAngleY#+90),10)
If XTest#>0 and XTest#<10000 and ZTest#>0 and ZTest#<10000
X#=XTest#
Z#=ZTest#
Endif
Endif
REM Shoot bullet
If Mouseclick()=1 and BulletLife=0
rem position the bullet y#+43 ? why do you position it above the camera ?? the gun is inder the cam => position it under ;)
Position object 2,X#,Y#+43,Z#
Set Object to camera orientation 2
Bulletlife =25
Show Object 2
play sound 2
impact = 0
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#,b#Y,bZ#
set cursor 10,10
if Sqrt((mX# - bX#)^2 + (mY#+25 - bY#)^2 + (mZ# - bZ#)^2) <20
Text 240,220 ,"Hit hit hit hit hit hit hit"
If BulletLife = 0
Endif
Hide object 2
Stop sound 2
Endif
Endif
rem when the bulletlife=0 then we hide the bullet and we position it where it can't touch an enemy :)
if bulletlife=0
hide object 2
position object 2,-1000,-1000,-1000
endif
rem when the bullet is inder the matrix, we hide it and position ... you know where ^^ ; it stop the sound 'cause the object is very far of the listener ; we position another sound there
if by# < get ground height(1,bx#,bz#)
position object 2,-1000,-1000,-1000
if impact = 0 then position sound 3,bx#,by#,bz#
if impact = 0 then play sound 3
impact = 1
endif
REM Rotate Camera
if CameraAngleX#>270
if CameraAngleX#-270 > 90 then CameraAngleX#=270
else
if CameraAngleX# > 90 and CameraAngleX#-270<270 then CameraAngleX#=90
endif
Yrotate camera CurveAngle(CameraAngleY#,OldCamAngleY#,24)
Xrotate camera CurveAngle(CameraAngleX#,OldCamAngleX#,24)
REM Position Listener
Position Listener X#,Y#+50,Z#
Rotate Listener 0,CameraAngleY#,0
Y# = Get Ground Height(1,X#,Z#)
Position Camera X#,Y#+50,Z#
REM Refresh Screen
Sync
Loop
'cause there wasn't the texture of the ground in the zip, I made one with create bitmap
i added a sound ; the sound 3, look at it ^^
the var. impact is used to know if the sound 3 is positionned and played
the var. impact become 0 when you shoot again
I'm following John, but I'm not john.
Lol, it is funnier in french