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 / Projectile help.

Author
Message
Spooter
16
Years of Service
User Offline
Joined: 27th May 2008
Location:
Posted: 30th May 2008 16:55
I'm working on a basic ship game, that is currently based on something like galaga. Now, I am having trouble getting the projectile to fire correctly. First, I have a couple of questions.

1. Is it possible to draw multiple sprites off of 1 image, because when the projectile fires I don't want the current missile to disappear and then it just resets back at the ship again. I want to be able to have multiple sprites of the same image on the screen at the same time. If it is possible, can you explain to me how it is done.

2. How do you make it so that when a certain variable is reached.
Like in my later example when it hits the top of the screen. Is it possible to remove the sprite from the screen without deleting it from the game. Or does dbDeleteSprite/dbDeleteImage not delete it from the game.


Ok, back to the projectile problem. I am using this code to make a projectile fire, when the Control Key is "pressed down"

This makes the projectile fire.

This is what makes the projectile move.


The problem with this code, is that if the key is not pressed down the sprite will stop moving. Instead I would like the projectile to keep moving even if the key is not pressed down. So if you press the key the missile will fire until it hits the top of the screen, and then it will be removed from the persons view.( I couldn't think of any other way to say it.)

Anyway I appreciate any help. Thanks
jason p sage
17
Years of Service
User Offline
Joined: 10th Jun 2007
Location: Ellington, CT USA
Posted: 30th May 2008 17:48
Quote: "1. Is it possible to draw multiple sprites off of 1 image, because when the projectile fires I don't want the current missile to disappear and then it just resets back at the ship again. I want to be able to have multiple sprites of the same image on the screen at the same time. If it is possible, can you explain to me how it is done.
"





Quote: "
2. How do you make it so that when a certain variable is reached.
Like in my later example when it hits the top of the screen. Is it possible to remove the sprite from the screen without deleting it from the game. Or does dbDeleteSprite/dbDeleteImage not delete it from the game.
"




See help for sprite visible - or sprite hide. not neceaary to delete. Green computing = recycling resources

Quote: "
The problem with this code, is that if the key is not pressed down the sprite will stop moving. Instead I would like the projectile to keep moving even if the key is not pressed down. So if you press the key the missile will fire until it hits the top of the screen, and then it will be removed from the persons view.( I couldn't think of any other way to say it.)
"


Well... You need to learn how to do arrays for this to be written properly. But lets assume one bullet for the moment.

when the user hits the key, you want to fire. When the user hits the key, you should set a bool ( bool BulletFlying; ) to true. Then you should update this bullets position WHENEVER this boolean flag is true - regardless of keypress.

then wehn bullet goes off top of screen - you set flag to false and hide the sprite.

Now, this isn't perfect - but you will like the results if you implement this. What I've described will make bullets keep shooting (one bullet actually) but when you hit kit again the bullet would start over at the gun. So to get bullet to the top of screen you would need to shoot and then wait for it to travel up the screen before shooting again.

This behavior could be remedied by simply only setting the BulletFlying flagg when the user hits FIRE AND the Bulletflying flag is false. They wont be able to shoot again until the bullet goes up off the screen and you code eresets the bullet flying flag to false as it hides the sprite.

Arrays would allow you to manage a bunch of bullets the same way... but in such a manner that you write logic once, and apply that logic to the "array of bullets". Ideally, I think this is what your after.

I doon't have time to write the whole shebang for ya - but this should get you searching google, searching these forums, and giving you ideas to try etc.

After sime dilligent effort, come back and tell us how you're fairing. Maybe you'll only need another hint or two to get it working! Don't give up though! It's not easy at first - but once you get it - you'll be hooked!

Spooter
16
Years of Service
User Offline
Joined: 27th May 2008
Location:
Posted: 30th May 2008 21:55
Thanks again jason... you have helped me so much. I got the boolean to work in like 2 minutes with your help. It's easy for me to get this stuff if people just explain the concept of what I wan't instead of giving me the code. I love the way you describe things.

Ok, so now I'm working on the array for multiple bullets. I will post if i need help.

Login to post a reply

Server time is: 2024-09-29 21:22:19
Your offset time is: 2024-09-29 21:22:19