Computer Science Canada Help with spawning enemies |
| Author: | Tamaranian [ Tue Jun 11, 2013 7:22 pm ] | ||
| Post subject: | Help with spawning enemies | ||
What is it you are trying to achieve? I'm attempting to spawn enemies from the right of the screen. They should come in from a random y coordinate then move out of the screen from the left side (x decreases) What is the problem you are having? I'm fairly new with working with turing sprites and games and I have no idea how to do this. I know my code is completely wrong, but I hope it gives you guys an idea of what I'm trying to do. I'm not sure where to put the loops and other lines and the sprite won't show up at all :/ Post any relevant code (You may choose to attach the file instead of posting the code if it is too long)
Please specify what version of Turing you are using Turing 4.1.1 |
|||
| Author: | evildaddy911 [ Tue Jun 11, 2013 7:52 pm ] |
| Post subject: | RE:Help with spawning enemies |
what you are doing every loop is setting the enemyY to something random, then putting that sprite at the random location. hundreds of times per second. what you want to do is set the y-coord, move it until its offscreen, THEN randomize the y-coord and reset the X. What you have is pretty close, you just need an inner loop to move the sprite, exiting when its offscreen |
|
| Author: | Tamaranian [ Tue Jun 11, 2013 8:03 pm ] |
| Post subject: | Re: RE:Help with spawning enemies |
evildaddy911 @ Tue Jun 11, 2013 7:52 pm wrote: what you are doing every loop is setting the enemyY to something random, then putting that sprite at the random location. hundreds of times per second. what you want to do is set the y-coord, move it until its offscreen, THEN randomize the y-coord and reset the X.
What you have is pretty close, you just need an inner loop to move the sprite, exiting when its offscreen Sorry, could you show me an example or something? I don't really follow.. |
|
| Author: | evildaddy911 [ Tue Jun 11, 2013 8:11 pm ] | ||||
| Post subject: | RE:Help with spawning enemies | ||||
what you have:
What you need:
|
|||||
| Author: | Tamaranian [ Tue Jun 11, 2013 8:32 pm ] | ||||||
| Post subject: | Re: RE:Help with spawning enemies | ||||||
evildaddy911 @ Tue Jun 11, 2013 8:11 pm wrote: what you have:
What you need:
Nothing shows up on the screen, but if I put a delay before the first loop it does weird jumps before disappearing. It's randomizing the same enemies Y coordinate instead of different enemy's Y coordinates right? |
|||||||
| Author: | Raknarg [ Tue Jun 11, 2013 9:31 pm ] | ||
| Post subject: | RE:Help with spawning enemies | ||
Here's the same code with slight adjustments:
First, you need to understand that the first loop is where the initial parameters are set. The second loop is where all the updating happens. In the second loop you tell it to update the position and draw it on screen Next, you forgot to set the enemy's x position. Then, you're subracting way too much from x for smooth movement, anbd because there's no delay (even slight) the program just whizzes by rediculously fast, so you can't see anything. Try running this instead. |
|||
| Author: | Tamaranian [ Tue Jun 11, 2013 9:49 pm ] | ||
| Post subject: | Re: RE:Help with spawning enemies | ||
Raknarg @ Tue Jun 11, 2013 9:31 pm wrote: Here's the same code with slight adjustments:
First, you need to understand that the first loop is where the initial parameters are set. The second loop is where all the updating happens. In the second loop you tell it to update the position and draw it on screen Next, you forgot to set the enemy's x position. Then, you're subracting way too much from x for smooth movement, anbd because there's no delay (even slight) the program just whizzes by rediculously fast, so you can't see anything. Try running this instead. Thank you, that worked perfectly |
|||
| Author: | Raknarg [ Wed Jun 12, 2013 5:36 pm ] |
| Post subject: | RE:Help with spawning enemies |
The important thing is that you understand what you did wrong. |
|