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 trialJustus Aberson
1,035 PointsI dont understand what the teacher is doing.
Hey guys, Im watching this video and I dont understand why Pasan gives the constant lowerBoundOfXRange = x - range and so on. What I dont understand starts at 11:18. I hope someone can explain it to me! Thanks!
3 Answers
J H
1,335 PointsHi there, Justus Aberson!
Yes, I can see why you’re confused. The video quickly glossed over the fact that he’s focusing on the 2,2 coordinate position. This is where your “tower” in the game will be positioned.
Because positioning is so important to be able to hit your attacking enemies, we need to make sure we use the center point (2,2) as our anchor.
Remember, we set the range (the reliable distance the tower can defend and hit enemies from) as 1.
func points(inRange range: Int = 1)
This corresponds with the grid-spacing shown in the video. (We can only hit enemies within 1 grid space away.)
2,2 (x,y) - [This is where our tower is positioned.]
Another important note: All of the X-coordinates are the same. And all of the Y-coordinates are the same. [See images below in this answer.]
Meaning, we can subtract 1 from the X-coordinate in the center position (2,2) and reach all of the “lowerBounds” for the enemies that choose to attack from there:
(2, ) - 1 = (1, )
(1, ) (1, ) (1, )
And we can add 1 to the X position to reach the enemies in the “upperBounds”.
(2, ) + 1 = (3, )
(3, ) (3, ) (3, )
Same for the Y-coordinates.
( ,2) - 1 = ( ,1)
( ,1) ( ,1) ( ,1)
( ,2) + 1 = ( ,3)
( ,3) ( ,3) ( ,3)
Matthew Philippi
934 PointsThank you for this explanation, I found it really helpful as well!
Shay Paustovsky
4,281 PointsYou're amazing clarifying such a scary topic, I'm coming from Java and there it's a bit more intimidating rather than swift but because I had some experience with Java it's not so scary after all , but thanks for the excellent thorough explanation
Justus Aberson
1,035 PointsJustus Aberson
1,035 PointsWow, thanks for taking the time to help me out! Im really thankful :D
Arcee Palabrica
8,100 PointsArcee Palabrica
8,100 PointsI can't see the image :) can you upload it again? thanks