|
I'm having trouble with challenge 2 shown on this page. It's a Fruit Ninja clone type of game that we are creating and the challenge is...
I was able to complete most of the challenge. I used the red penguin sprite from the Whack-a-Penguin project we did before, so that the player can tell the difference between the bonus penguins and the normal ones. I made the bonus penguins appear randomly, and even less frequently than the regular penguins or even bombs. I made it award 5 points instead of 1 when a player slices it. And I have made sure that the player won't lose a life if they miss one. (They are supposed to be a bonus afterall.) But I can't seem to figure out how to make them move faster than the regular penguins. I know that it probably has something to do with this function where we create all of the sliceable enemies...
It seems to me that there is probably just some property of You can see near the end of that function where I have added this...
Does anybody know what I need to put in there? |
|
I didn't include this before, but Challenge 1 of this project was to remove all the magic numbers from this function, and create constants for them instead. So, these are the constants I created.
But I also have another questions about this same project.
|
|
Ok... actually writing out those numbers helped me understand what the velocity vectors are actually doing better, and I was able to figure out an answer to my original question. Basically, the But I ended up creating 2 more constants...
I know those don't seem to be far off the screen, but remember that we are multiplying each one by 40 per Paul's instruction. These are comparable to these four constants that are used for the velocities of our regular enemies
Basically I tried to just double the maxInnerX and maxOuterX Velocities to test with, but I found that the ones with an inner starting point were still moving too slow, so I ended up quadrupling it instead. So, that 30 and 20 don't have any real significance other than they seemed to test well. There are only two variables this time because I just decided not to make the bonus enemies' speeds vary based on a random number generator. They don't need a min and a max. But I still wanted the ones that start near the center of the screen to move a little bit slower since they only have to move across about half of the screen before they are gone, while the ones that start near the edges have to move across the full screen, giving the player more time to react to them. Then I just had to modify my code shown above where the velocity values were set like this...
There might be a cleaner way to write that, but it gets the job done for now. |
SPONSORED Join a FREE crash course for mid/senior iOS devs who want to achieve an expert level of technical and practical skills – it’s the fast track to being a complete senior developer! Hurry up because it'll be available only until April 28th.
Sponsor Hacking with Swift and reach the world's largest Swift community!
This topic has been closed due to inactivity, so you can't reply. Please create a new topic if you need to.
All interactions here are governed by our code of conduct.
Link copied to your pasteboard.