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 / Bullet Question

Author
Message
G_Unit
21
Years of Service
User Offline
Joined: 30th Aug 2003
Location: Sacramento, California
Posted: 31st Aug 2003 00:40
Hello my Name is Zach and I recently , Id say about 2 months ago , started using DBC and I am quickly getting used to the language. Before i start making a game , which would be a First Person Shooter probably , I want to soak in all the basic mechanics I need to know to make it an acceptable and playable game. What I am trying to soak in right now , is bullet mechanics. I am trying to figure out how to simply make bullets.

Ive had success with only one bullet being able to appear on the screen untill that same bullet runs out of life.(BulletLife = 0 )

This is the code I use

make object sphere 2,2
hide object 2

If mouseclick()=1 and BulletLife=0
Position object 2,X#,Y#+35,Z# (Camera angles)
Set object to camera orientation 2
BulletLife=25
Show object 2
EndIf

If bulletlife > 0
Dec bulletlife,0.5
Move object 2,30
If bulletlife=0 then hide object 2
EndIf

What I am trying to figure out is how to fire bullets not using the same bullet object over and over , but by creating a new sphere(bullet) everytime the fire button is pressed and deleting it once a certain condition is met such as (collision detection with the bullet on a matrix or wall).

If tried to use this code but it works with no sucess

If mouseclick()=1
make object sphere 2,2
set object to camera orientation 2
Position object 2,X#,Y#+35,Z#
BulletLife=25
End If

If BulletLife > 0
move object 2,30
Dec BulletLife
If BulletLife=0 then delete object 2
EndIf

I am using this code in a Do loop and it always has an error that says "object has already been created" and I cannot find a way to get around this. I know I am doin something wrong because I am not that bright lol , If someone has any tips ,suggestions or TUTORIALS , I would glady appreciate it.

Thx Zach

HaHaHa, Its G-Unit Baby...
Damokles
21
Years of Service
User Offline
Joined: 28th May 2003
Location: Belgium
Posted: 1st Sep 2003 00:08 Edited at: 1st Sep 2003 00:10
You simply recreate the object number 2 when you do that. And to create a new bullet It must be another number than 2.
Here is a code that shall work :



Don't forget to dim the BulletLife(i) array and get the last block repeated for each i

"Begin at the beginning, and go on till you come to the end: then stop." - Lewis Carroll
Pricey
22
Years of Service
User Offline
Joined: 22nd Feb 2003
Location:
Posted: 4th Sep 2003 16:28
i have some code for this but i don't know where it is... i was using it yesterday and i don't know the exact syntax but the basics of it is:

you create & hide 20 bullets using a for / next loop
when the player fires it looks to see if there is a bullet which is not being used
when it finds one it marks it as being used (in an array probaly) and fires it. when its life runs out it marks it as not being used (in an array) and it can be used again.

simple... yet effective!

My programs don't crash... your computer does

http://johnsgamesuk.topcities.com
David T
Retired Moderator
22
Years of Service
User Offline
Joined: 27th Aug 2002
Location: England
Posted: 4th Sep 2003 20:49 Edited at: 4th Sep 2003 20:50
Your code is pretty solid, you just need to convert eveything to arrays:



Hopefully that should be easy to understand. Create bullet, run through all bullets checking if the have been fired. If so move it and if it's exceeded it's life then kill it.

Theres no place like 127.0.0.1
There are 10 people in this world, those who understand binary and those who don't
Bus station = where bus stops. Train station = where train stops. Workstation = ?

Login to post a reply

Server time is: 2025-05-19 23:41:38
Your offset time is: 2025-05-19 23:41:38