This practice will be retired on May 31, 2020.
Bummer! This is just a preview. You need to be signed in with a Basic account to view the entire video.
Solution: Tower Defense Game1:12 with Pasan Premaratne
Okay, so I said there were two ways to do this.
One was, we can break this down into the individual steps and
that makes it fairly easy.
So here I got the distance between x, I use the subtraction operator to get that
distance, and then we square the distance so we multiply this value by itself.
We repeat that for the y values.
We add those two together.
And then we put them here in the square root, between these parenthesis here,
like I mentioned to get the final value.
So the distance between our two points is 4.47 whatever the units.
Now, the other way to do it was all in one single line using the correct precedence
and using parentheses to define that precedence accordingly.
So, I've added a comment here so it doesn't execute but
if I remove this, you'll see that the code runs and it is the exact same value but
this is all in one line.
Now obviously, I would go with this approach if I were you,
because this is a bit more readable.
So until you understand what's going on here, this is all unnecessary.
And there's ways down the road, once you learn how to write more code,
there's ways to improve this, so it's not so unreadable, basically.
Okay, so hopefully, you got that right.
You need to sign up for Treehouse in order to download course files.Sign up