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.

Dark GDK / a shoot'em up shooting problem

Author
Message
EpicVitto23
13
Years of Service
User Offline
Joined: 23rd Dec 2010
Location:
Posted: 23rd Dec 2010 09:36
Hi everyone i am very new here i am taking a class using dark GDK next semester. anyways, i was trying to get ahead and get a little practice in with a scrolling shooter. i've got the plane moving, and he can shoot one bullet fine but i can't figure out how to be able to shoot multiple times without deleting the first bullet. i hope that makes sense.. the function im using to make the bullet is dbSprite(4, player1X, player1y); with player1X and y obviously being player1's coordinates. thanks for any information you can share.
Matty H
15
Years of Service
User Offline
Joined: 7th Oct 2008
Location: England
Posted: 23rd Dec 2010 17:32
You need to create multiple sprites, one for each bullit.
Each will have its own ID number, your code shows one sprite with an ID of 4, you can create another one with ID of 5 and so on, they can all use the same image without a problem.

TechLord
21
Years of Service
User Offline
Joined: 19th Dec 2002
Location: TheGameDevStore.com
Posted: 23rd Dec 2010 20:51
First Lesson in Game Creation: Object Management using STL Containers. Do some research into Arrays, Stacks, and List Containers (hint). Let me know what you discover and I'll be glad to answer any questions.

EpicVitto23
13
Years of Service
User Offline
Joined: 23rd Dec 2010
Location:
Posted: 23rd Dec 2010 22:24
ok so what you are saying is i could make the id for the bullet into a variable then add one to the variable every time it shoots that way it always generates a new object? i'll give that a try. as for the arrays and such, i look forward to learning them in my class but that might be a bit advanced for me right now. thanks for all your help.
DeadTomGC
13
Years of Service
User Offline
Joined: 11th Aug 2010
Location: LU
Posted: 24th Dec 2010 05:40 Edited at: 24th Dec 2010 05:42
This is just slightly advanced resourcefulness. One very effective way to do this is to make an array that is as long as the maximum number of bullets you want to have on the scene at one time.
loop through so that- oh screw it. Here is some code:

This is not advanced code just advanced method.

Basically, what this does is keep track of which objects are bullets so that it can update them appropriately.

Keep in mind that if you manage to have more than 200 bullets on the scene bullets will freeze and never be deleted, but you can change the max by changing the variable length and the length of the array. Note, array lengths cannot be altered once declared.

Also, this could be modified to keep track of multiple types of objects each with unique properties.

Finally, instead of tracking the velocity one could use the orientation to determine the velocity.

let me know if you have any questions.

I'll get a new signature someday.
EpicVitto23
13
Years of Service
User Offline
Joined: 23rd Dec 2010
Location:
Posted: 24th Dec 2010 07:52
i really appreciate your help, but i have no idea how to use your code and i don't really understand what it does...

this is what ive got so far, it makes as many bullets as i want but for some reason the bullets don't move.

//checks if space key is being pressed and for first bullet.
if (dbSpaceKey() == 1)
{
dbSprite(bullet, player1X, player1Y,4);
dbMoveSprite(bullet, 7);
bullet ++;

}

can someone tell me why there not moving? i have tried moving dbmovesprite function out of the if statement and it didnt work.
DeadTomGC
13
Years of Service
User Offline
Joined: 11th Aug 2010
Location: LU
Posted: 25th Dec 2010 23:21
oh, this is a 2d game.

Ok here is the code for a program that fires up to 200 bullets.



So, you will need a background image( I used the default for 2d projects) and a bullet sprite.

what this does is generates a new sprite every refresh you hold sown the space bar. they have a velocity of -2 in the x and -6 in the y. it stores the sprite number in the [int][0] index of the array bullets. It stores the velocity in the [int][1] and [int][2] indexes of the array.

It then reassigns the finish index of the loop that updates the bullets. I the index exceeds the max of the array 199 then it will be set back to the start. ( note, an array with length 9 has indexes 0,1,2,3,4,5,6,7,8 there are nine numbers but the indexes go from 0-8)

In the update loop if the the bullet with the index of the starting index is deleted the start will step up one, thus shortening the number of loops the program must do. This way the processor does up to 200 loops but only when necessary.

I'll get a new signature someday.

Login to post a reply

Server time is: 2024-06-28 01:46:57
Your offset time is: 2024-06-28 01:46:57