Computer Science Canada Shooting Multiple Shots |
Author: | chaos [ Mon Aug 15, 2011 4:08 pm ] |
Post subject: | Shooting Multiple Shots |
I want to be able to fire multiple shots, but I can only figure out how to shoot one shot at a time. I was wondering what ways there are to do this (ie. a particle engine)? |
Author: | crossley7 [ Mon Aug 15, 2011 4:22 pm ] |
Post subject: | RE:Shooting Multiple Shots |
a simple way is to duplicate your variables or convert them to arrays and have an array of boolean that will say whether it is in the air or not. Then just loop around your array and depending on how you do it, you can have up to n shots if n is the size of the array. It really depends how you have it set up to help you much with getting multiples |
Author: | Insectoid [ Mon Aug 15, 2011 5:01 pm ] |
Post subject: | RE:Shooting Multiple Shots |
You'll want an array of bullets, yeah. I suggest you calculate the maximum possible number of bullets on the screen at a time. This is how big your array should be. |
Author: | chaos [ Mon Aug 15, 2011 5:09 pm ] |
Post subject: | Re: Shooting Multiple Shots |
I want to limit it to about 10 bullets on screen at a time. Also, is it possible to do this using a particle engine for bullets? |
Author: | Insectoid [ Mon Aug 15, 2011 5:23 pm ] |
Post subject: | RE:Shooting Multiple Shots |
Uh, why? Bullets move just like characters. Particle engines are for like, smoke & stuff like that. |
Author: | chaos [ Mon Aug 15, 2011 5:28 pm ] |
Post subject: | Re: Shooting Multiple Shots |
So, is creating an array each for the number if bullets, the bullet's x-coordinate, and the bullet's y-coordinate the correct way to go? |
Author: | Insectoid [ Mon Aug 15, 2011 6:08 pm ] |
Post subject: | RE:Shooting Multiple Shots |
Have a look at records. There should be something about them in the Turing Walkthrough. |
Author: | chaos [ Tue Aug 16, 2011 8:08 pm ] | ||
Post subject: | Re: Shooting Multiple Shots | ||
I took a look at records and this is what I have come up with. I have one problem. The error message says there is no value for the variable in the line where the bullet is drawn.
|
Author: | mirhagk [ Wed Aug 17, 2011 7:43 am ] |
Post subject: | RE:Shooting Multiple Shots |
You have this organized very strangely. When you shoot you want to do all that setting of it's values and stuff in one section, and in a different section you check if it's alive and draw it if it is. Right now your drawing all the bullets that don't exist as soon as you hit the space bar. |
Author: | chaos [ Wed Aug 17, 2011 11:14 am ] | ||
Post subject: | Re: Shooting Multiple Shots | ||
@mirhagk: Thanks. I fixed the problem. Here is the fixed code. Though I need some help on delaying the movement of the bullet from the movement of the ship.
|
Author: | mirhagk [ Wed Aug 17, 2011 12:10 pm ] |
Post subject: | RE:Shooting Multiple Shots |
I might be confused as to what you want, but couldn't you just decrease the speed? |
Author: | Raknarg [ Sat Aug 27, 2011 7:43 pm ] | ||||
Post subject: | Re: Shooting Multiple Shots | ||||
This xan be shortened to:
since that's whats going to happen anyways. And as for your most recent quetion, there's no need to delya them seperately. Just move them at different speeds. Also, you're going to encounter one more problem in the future, depending on how you do it. But to make it easier, I'd move every dead bullet to a ludicrous position so they do not get in the way. When I did my spaceship game, it took me a while to figure out why ships were disappearing at random, and its because (again, depending on how you do it) the dead bullets kill ships though they dont move and are not drawn. |
Author: | chaos [ Mon Aug 29, 2011 10:24 pm ] | ||
Post subject: | Re: Shooting Multiple Shots | ||
I have now included enemies and collision detection (somewhat). The problem is that after you kill the enemy and shoot bullets again in the same location, the bullets disappear without the the presence of an enemy for some time--about less than a second, but noticeable. How can I fix this? Any help is appreciated. I have attached the enemy ship below. Here is my code:
|
Author: | [Gandalf] [ Mon Aug 29, 2011 10:45 pm ] |
Post subject: | Re: Shooting Multiple Shots |
You'll want your array of bullets to be a flexible array. That way, you can increase or decrease the amount of bullets you keep track of depending on whether the bullet still exists. You can find information on flexible arrays in Part III of the Arrays tutorial from the Turing Walkthrough. |
Author: | Insectoid [ Tue Aug 30, 2011 7:53 am ] |
Post subject: | RE:Shooting Multiple Shots |
I don't think that's strictly necessary [Gandalf]. Flexible arrays are slow. Better to calculate the number of bullets a given character can shoot in the time it takes for a bullet to move across the maximum distance across the screen. If it takes 3 seconds to cross the screen, and you fire one bullet every second, your array needs to be 3 cells (or 4, to be safe). Then you give every character its own bullet array, and you'll have access to as many bullets as you'll need. |
Author: | Raknarg [ Tue Aug 30, 2011 3:17 pm ] |
Post subject: | RE:Shooting Multiple Shots |
I believe the issue is that the position of your enemy stays in the same place after it gets hit until the enemy is reused again. To fix that, you can place the enemy in a rediculous spot while it is not being used, like 1000, 2000 or something. And @[Gandalf] flexible arrays are much less effective, having tried to use them myself. Using a regular array works fine as long as you have a large enough array. |
Author: | [Gandalf] [ Thu Sep 01, 2011 1:43 am ] |
Post subject: | RE:Shooting Multiple Shots |
Using flexible arrays would conceptually remove some of your worries about keeping track of active bullets, which it sounds like is one of the issues here. Performance is secondary to having a working program. If you're concerned about the performance of Turing's implementation of flexible arrays to the point where it stops you from using them, you might as well not be using Turing. Other languages can do this far better. |