Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DarkBASIC Discussion / Need Help Making FPS!!

Author
Message
Darkhorse 186
18
Years of Service
User Offline
Joined: 2nd Sep 2006
Location: Scotland
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
luke810
18
Years of Service
User Offline
Joined: 4th Sep 2006
Location: United States
Posted: 3rd Feb 2007 02:15 Edited at: 3rd Feb 2007 02:15
Here is a gun control system I made for one of my games. Each of the second subsets in the gun array stands for a different variable such as gun rate of fire, max ammo capacity, current ammo capacity. To use the accuracy subset you need to set the angle of the bullet for the x and y axis to

(rnd( accuracy_level )/1000.0)-(( accuracy_level )/2)


P.S. Try to use the code snippet button when posting code.

Attachments

Login to view attachments
Vequor
20
Years of Service
User Offline
Joined: 27th Apr 2005
Location: Mars
Posted: 3rd Feb 2007 02:45 Edited at: 3rd Feb 2007 02:49
Well, they are many different ways for weapon changing. One common way is to hide the old weapon and then unhide the new weapon like so.



Naturally you could add some movement and rotation commands to make it look better. As for A.I., you might want to look up the point object and/or pathfinding commands.

However, I highly suggest you do some more tutorials before you attempt to finish your fps.

Finish the Monster Hunt Tutorial
Finish the Binary Moon Tutorial
Finish TDK's Tutorials. http://forum.thegamecreators.com/?m=forum_view&t=96010&b=7

After you've done all that then you should do some simple games like pong. A lot of people rush into making their dream game right away, but you should have DB for a number of years before you do. Otherwise your likely to give up on it.

P.S. The Newsletter has some tutorials to.

P.P.S. Gotos are evil.

Stay calm and keep a cool head
Darkhorse 186
18
Years of Service
User Offline
Joined: 2nd Sep 2006
Location: Scotland
Posted: 3rd Feb 2007 03:15
Thanks


Darkhorse
NanoGamez guy
18
Years of Service
User Offline
Joined: 13th Jan 2007
Location: Closer than you think...
Posted: 3rd Feb 2007 14:02
Quote: "P.P.S. Gotos are evil."


I agree they are very annoying when you're tracing back our code. But if you are a beginer then they are the easyist option. Then you can move on to gosubs and finally functions

I can see you...

Login to post a reply

Server time is: 2025-05-26 03:38:42
Your offset time is: 2025-05-26 03:38:42