He was coding a certain tower in his game and he asked me "How do I code the tower to only attack units which are within 200 pixels?" I first asked if he could draw me a picture of what he wanted, and below is computer graphic of what he drew..
I then said, "What do you have?" He then showed me that he created variables:
t_x = x value of the turret
t_y= y value of the turret
u_x= x value of the unit
u_y= y value of the unitHe had currently coded that if the following two inequalities were true the tower would attack.
He then said "Well I know that once the line from the turret to the unit is less than or equal to 200, the turret will attack but what inequality do I create?" A student, next to him, said "Would pythagorean theorem work?". The problem we had was to label the other two sides. Minutes passed while I let him think, and finally he asked if this would work
I then asked, "Why did you use the absolute value before?" Which is responded "because the code needs to take the positive value, and if the unit was to the left or below the turret I need it to become positive....but....wait....squaring is positive, so can I just remove the absolute value?" We tried and here was his final test
When tested, this worked perfectly. Keep in mind this child is in Grade 10, and completed an outcome from Gr. 12 mathematics.