Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialNatalie Carlson
3,727 PointsEnemy Speed
If we change minSpeed depending on gameTime, shouldn't we also update THSpaceDogMinSpeed when we spawn the dog? We set minSpeed but then we never actually do anything with it. Or did I miss something?
Thanks! I love these videos!
1 Answer
Enara L. Otaegi
13,107 PointsYou're right. But we can't update the constant THSpaceDogMinSpeed. What I did:
if (self.totalGameTime > 480) {
// 480 / 60 = 8 minutes
self.addEnemyTimeInterval = 0.5;
self.minSpeed = THSpaceDogMinSpeed - 60;
self.maxSpeed = THSpaceDogMaxSpeed - 60;
}
I created a maxSpeed variable because when calculating the random Speed I wanted it to increase evenly.
So in the random method we pass:
float dy = [THUtil randomWithMin:self.minSpeed max:self.maxSpeed];
Natalie Carlson
3,727 PointsNatalie Carlson
3,727 PointsThanks for the recommendation with declaring a maxSpeed too. I actually changed the THSpaceDogMinSpeed to exclude the const property. I think I'll take your recommendation and return to the program, include the const for THSpaceDogMinSpeed, set self.minSpeed = THSpaceDogMinSpeed and then include self.minSpeed and self.maxSpeed as the variables for the random value for the velocity. This programmatically is better code.
Thanks for your time!