Posted: 2nd Feb 2007 22:52
Hi,
I have been doing the "monster hunt" tutorial but adding in some of my own stuff as i go along. During this i encountered a few problems such as if you fire while walking the bullet goes upwards. Also i need some help on my weapon changing system and AI.
Darkhorse
mainmenu:
cls
Sync On : Sync Rate 40
Do
if Button(20,55,"New Game")=1 then Goto New_Game
if button(20,135,"Multiplayer")=1 then goto Multiplayer
If Button(20,295,"Exit")=1 then End
if button(20,215,"Options")=1 then goto menu
sync
loop
New_Game:
Sync On
Sync Rate 40
Backdrop on
Sync On
Sync Rate 40
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)
a=100
b=5
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
make object cube 7,4
XRotate Object 7,90
Fix object pivot 7
Scale object 7,100,100,500
position object 7,0,-7,15
Lock object on 7
Rem Make bullet
Make Object sphere 2,2
Hide Object 2
Rem make matrix
Make matrix 1,10000,10000,20,20
Rem texture matrix
Load image "grass1.bmp",1
Prepare matrix texture 1,1,1,1
Fill matrix 1,0,1
rem Randomize the matrix
randomize matrix 1,125
X#=5000
Z#=5000
a=1
g=1
Rem Main loop
Do
ink rgb(255,255,255),0
circle 320,240,13 : circle 320,240,4
rem a=1 - show gun 1
if a=1
show object 1
hide object 7
endif
rem a=2 - show gun 2
if a=2
show object 7
hide object 1
endif
rem when up key pressed perform a=1(show gun 1)
if keystate(2)=1
a=1
g=1
endif
rem when down key pressed perform a=2(show gun 2)
if keystate(3)=1
a=2
g=7
endif
position object g,0,-7,13
position object g,0,-7,15
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
Yrotate camera CurveAngle(CameraAngleY#,OldCamAngleY#,24)
Xrotate camera CurveAngle(CameraAngleX#,OldCamAngleX#,24)
Y# = Get ground height(1,X#,Z#)
Position Camera X#,Y#+50,Z#
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 Mouseclick()=1 and BulletLife=0
Position object 2,X#,Y#+43,Z#
Set object to camera orientation 2
BulletLife =25
Show object 2
play sound 1
a=a-1
Endif
rem hide both guns - when a=3 nboth guns hidden (see a=3 below)
if controlkey()=1
play sound 2
a=100
b=b-c
endif
If BulletLife > 0 then Gosub ShootBullet
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 Refresh Screen
Sync
Loop
function Button(x1,y1,WORDS$)
Pressed=0
x2=Text Width(WORDS$)
y2=Text Height(WORDS$)
if mousex()>x1 and mousex()<x1+x2
if mousey()>y1-y2 and mousey()<y1+y2
Pressed=1
endif
endif
if pressed=1 then ink rgb(255,0,0),0 else ink rgb(255,255,255),0
if pressed=1
Pressed=Mouseclick()
else
pressed = 0
endif
text x1,y1,WORDS$
endfunction pressed
ShootBullet:
Dec BulletLife
Move object 2,10
bX#=Object position X(2)
bY#=Object position Y(2)
bZ#=Object position Z(2)
inc Pn
if Pn=20 then Pn=10
Scale object Pn,100,100,100
Position object Pn,bX#,bY#,bZ#
point object Pn,X#,Y#,Z#
Zrotate object Pn,rnd(180)
for x = 1 to 10
scale object int((Wrapvalue((Pn-9+x)*36))/36)+10,100+x*25,100+x*25,100+x*25
next x
if bY# < Get Ground height(1,bX#,bZ#) then BulletLife=0
set cursor 10,10
if Sqrt((mX# - bX#)^2 + (mY#+25 - bY#)^2 + (mZ# - bZ#)^2) <20
print "hit hit hit hit hit hit hit hit"
BulletLife = 0
endif
if BulletLife = 0
Hide object 2
for x=10 to 20
hide object x
next x
Explode = 20
endif
Return
menu:
cls
Sync On : Sync Rate 0
do
If button(20,55,"Fog Distance")=1 then goto fogdistance
if button(20,135,"Return")=1 then goto mainmenu
sync
loop
multiplayer:
cls
Sync On : Sync Rate 0
do
If button(20,55,"Set up Game")=1 then goto mainmenu
sync
loop
fogdistance:
cls
Sync On : Sync Rate 0
do
if button(20,55,"No fog")=1 then fog off
If button(20,135,"Foggy")=1 then fog distance 4000
if button(20,215,"Very Foggy")=1 then fog distance 8000
if button(20,295,"Return")=1 then goto mainmenu
sync
loop