Computer Science Canada Need solution - need to shoot at the same time i move |
Author: | pttptppt [ Sat Feb 25, 2017 4:41 pm ] | ||
Post subject: | Need solution - need to shoot at the same time i move | ||
What is it you are trying to achieve? The mouse moves an object, as that object moves, clicking is supposed to shoot. What is the problem you are having? <Answer Here> The object has to pause while the shooting happens because the shooting is in a loop. But i dont know how to fix this and keep the program working. Describe what you have tried to solve this problem Ive taken out the "Projectile" part of the code and taken it out of a loop but then nothing happened anymore. Post any relevant code (You may choose to attach the file instead of posting the code if it is too long) Problem is at the "Projectile" procedure, specifically to do with the loop
Please specify what version of Turing you are using Latest |
Author: | Insectoid [ Sat Feb 25, 2017 7:03 pm ] | ||||
Post subject: | RE:Need solution - need to shoot at the same time i move | ||||
You need the bullet to be in a loop, or else it will travel for one frame and then stop. But when it's in its own loop, everything else has to pause and wait for the bullet to hit something. So what's the solution? Put it in a different loop! Everything that needs to move at the same time should be in the same loop. The code will look more or less like this:
You'll probably want more than one bullet on screen at a time though, right? So we'll store all our bullets in an array. If a bullet is fired, we add it to the array. If it hits something, we delete it.
|
Author: | pttptppt [ Sat Feb 25, 2017 7:55 pm ] | ||||
Post subject: | Re: RE:Need solution - need to shoot at the same time i move | ||||
Insectoid @ Sat Feb 25, 2017 7:03 pm wrote: You need the bullet to be in a loop, or else it will travel for one frame and then stop. But when it's in its own loop, everything else has to pause and wait for the bullet to hit something. So what's the solution?
Put it in a different loop! Everything that needs to move at the same time should be in the same loop. The code will look more or less like this:
You'll probably want more than one bullet on screen at a time though, right? So we'll store all our bullets in an array. If a bullet is fired, we add it to the array. If it hits something, we delete it.
I get that, kinda. Can you try showing with an example from my code. Try running my code on Turing and you'll see the problem |