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.

Newcomers DBPro Corner / Help With Shooting Multiple Bullets (Would Arrays Help)???

Author
Message
lickuidstylz
20
Years of Service
User Offline
Joined: 13th Aug 2004
Location: MD in USA
Posted: 15th Aug 2004 10:48
Ok, Here's my first post, I'm making a small fps. I'm doing well with it all until I hit a small snag...
*******************************
What I need to do is this:
Load the bullet
Copy the bullet several times
When I click the mouse, fire each bullet in succession starting with bullet #1
each bullet has its own individual coordinates (of course)
*******************************
I'm working on a few methods but I figured I'd ask while I'm trying to figure it out. Any and all help is appreciated, and You're all saints


Am I a nerd just cuz I wanna make videogames to beat my friends in??
lickuidstylz
20
Years of Service
User Offline
Joined: 13th Aug 2004
Location: MD in USA
Posted: 15th Aug 2004 13:10
I've even tried using the gosub routine to create a bullet each time it's called....I'm so lost..

Am I a nerd just cuz I wanna make videogames to beat my friends in??
Physics coder
20
Years of Service
User Offline
Joined: 25th May 2004
Location: United States
Posted: 15th Aug 2004 13:43 Edited at: 15th Aug 2004 13:54
here's some pesudo-code that should help, the code isn't executable, just take the idea and adapt it to your game:

(make an array of bullets)
dim bullet(100)

`define the speed of the bullets
global bullet_speed=4
(so there can be up to 100 bullets at a time.
give each bullet in the array an object, like this)

for n=1 to 100
bullet(n)=n
next n

(NOTE, if there are any other objects in the game from 1 to 100, like a level object, player object, or the objects of what you want to shoot at, like ai players, then offset the bullets objects like this)

for n=1 to 100
bullet(n)=n+1000
next n

(that way the first bullet's object is 1001, the second bullet's object is 1002, etc.)

(and then the main loop)
do

(so if the player presses space, and at least a 10th of a second as gone by, shoot a bullet. change the 100 to 1000 for one bullet per second, or to 50 for 20 bullets per secon etc.)
if spacebar()=1 and timer()>last_shot+100
last_shot=timer()
shoot_bullet()
endif

`call this every frame to update the positions of all the bullets
update_bullet()

sync
loop

`this is called when the user shoots a bullet by pressing space
function shoot_bullet()
n=0
repeat
inc n
until object exist(n)=0
make object cube n,1
`this makes a cube for a bullet, but any object can be a bullet
`and then position object n at player, rotate it in the direction of the player.
endfunction

`this is called every frame to update the position of all the bullets
function update_bullets()
for n=1 to 100
if object exist(bullet(n))=1
move object n,bullet_speed
`check collisions with the boundaries of the game and anything else the bullets can colide into like other walls, like:
if object position x(bullet(n))<0 then delete object bullet(n)
`etc
endif
next n
endfunction

-----------------------------------
To delete the bug, delete the code.
Specs: Sony VAIO Laptop, Windows XP, P4 2.8Ghz, 512MB RAM, ATI Radeon 64MB video memory, DBP Upgrade 5.3.
lickuidstylz
20
Years of Service
User Offline
Joined: 13th Aug 2004
Location: MD in USA
Posted: 15th Aug 2004 13:54
Thanks!! I'll Try that out!!!

Oh! And seriously, (even if you wanted to) thanks for not typing out fully functional code. I like to understand the concepts behind working code, plus I like the challenge.
If i pull it off correctly, i'll upload my source code.

-Thanks again Physics Coder!

Am I a nerd just cuz I wanna make videogames to beat my friends in??
lickuidstylz
20
Years of Service
User Offline
Joined: 13th Aug 2004
Location: MD in USA
Posted: 15th Aug 2004 15:05
Well, I worked in the code, and I'm getting some pretty funky results..Although it seems as if the fire interval is down, and the functions *want* to work, there just seems to be something missing or in the wrong place.... Here's the code snippet, which just happens to be the entire program..heheh It's relatively short.

Am I a nerd just cuz I wanna make videogames to beat my friends in??
lickuidstylz
20
Years of Service
User Offline
Joined: 13th Aug 2004
Location: MD in USA
Posted: 15th Aug 2004 15:06


Am I a nerd just cuz I wanna make videogames to beat my friends in??
SandraD
20
Years of Service
User Offline
Joined: 30th May 2004
Location: Down on the corner, out in the street.
Posted: 16th Aug 2004 15:20
Okay....

In order for the function to use X#, Y# and Z# for positioning of the bullets when you fire them, the values must be either a) passed to the function, or b) be defined as global. Right now, everytime you hit the shoot_bullet() function, the values are at zero (because functions use local values,) so the easiest change would be;

if mouseclick... yada-ya-ya
shoot_bullet(x#, y#, z#)
...yada-ya

function shoot_bullet(X3, Y#, z#)
...yada-yo

Good luck!
S.

Any truly great code should be indisguishable from magic.
lickuidstylz
20
Years of Service
User Offline
Joined: 13th Aug 2004
Location: MD in USA
Posted: 17th Aug 2004 00:29
It's always some minute detail....BIG DUH ON MY PART!! I'm getting back into coding after about 1 1/2 years of neglect... I couldn't possibly express my appreciation for everyone's help. I'm at work right now, but I'll try that out when i get home.

Listen (IF ANYONE'S STILL VIEWING THIS POST) I have a question for future reference: Would anyone know how to detect collision/intersection of a line with an object? Or even how to curve a line...I know this is simple graphing and such, but if only I could get my eyes on a small sample or two .. As always It's much appreciated.

Oh and if anyone needs an experienced modeler to do scenery or objects(i don't feel like modeling people [lazy but I may change my mind]lol), just ask and I'll be more than happy to help out. Instant MSG me if you want to see screenshots...

Hack the GIBSON!!! Hahaha What a corny movie!! But it was the Shiznitobam Snip Snap Sack..What did I just say?
Physics coder
20
Years of Service
User Offline
Joined: 25th May 2004
Location: United States
Posted: 17th Aug 2004 10:35 Edited at: 17th Aug 2004 10:36
try this, it also moves the player and objects per second, not per frame, so it works at any frame rate. Also I like to keep everything at one scale, so I like to have 1 unit= 1 meter, so a100x100 matrix is 100 meters x 100 meters.



-----------------------------------
To delete the bug, delete the code.
Specs: Sony VAIO Laptop, Windows XP, P4 2.8Ghz, 512MB RAM, ATI Radeon 64MB video memory, DBP Upgrade 5.3.
lickuidstylz
20
Years of Service
User Offline
Joined: 13th Aug 2004
Location: MD in USA
Posted: 18th Aug 2004 01:27
Thanks Physics Coder,
You’ve amazed me once again man…If you ever need any models done for your tank game(or whatever for that matter), just lemme know. Oh and do you have an aim or yahoo name so I can ask a couple questions in real time about that code you just sent? I'll end up spending most(if not the rest) of my work day analyzing this code as to minimize questions...especially the dumb ones.

Hopefully by tomorrow I'll have a playable demo for everyone to fart around with. Sadly, all the objects will have no texture. (I'm getting around to that, but one thing at a time) Eventually, I'd like to learn how to use pixel/vertex shaders, a friend suggested 3DS Max and Photoshp(though i doubt he was sure). But if that is the case, making shaders won't be a prob.

Hack the GIBSON!!! Hahaha What a corny movie!! But it was the Shiznitobam Snip Snap Sack..What did I just say?

Login to post a reply

Server time is: 2024-11-27 06:53:23
Your offset time is: 2024-11-27 06:53:23