Building an imaginary triangle, continued
Now lets add some code for the vertical distance.
The diagram below shows how we calculate the vertical side of the triangle.
This time you subtract the y position of the monkey from the y position of the target (where you pressed).
Now let's write the code.
> Open Sensing and drag x position of mouse
into the work space. Click on x
text and change it to y
.
> Then open Operators and the drag the numeric __+__
block into the work space. Click the +
and change it to -
.
> Drag y position of mouse
into the left side of the subtraction block.
> Open Transform and place x position of myself
in the second slot of the -
block. Click on x
and change it to y
.
Your code should look like this:
Now you will save the vertical distance as a variable and name the variable dy
.
> Open Variables and drag set true/false i to __
the work space.
> Then connect this block beneath the set number dx
block. Like so:
> Click on i
and rename the variable to dy
.
> Click on true/false
and change it to number
.
> Drag your subtraction blocks inside of this variable block. Your code should look like this:
Now you have written code for the dx
and dy
values. With these values you can calculate the angle need to shoot the dart where you clicked.
> Click NEXT STEP below.