A simple project showing how to do collision-sensing with pen. Press space to show variables/lines. Arrow keys to move the larger circle. The red line is the distance, yellow is the horizontal distance, and blue is the vertical distance.
One of the greatest problems I've encountered with programming pen engines was the issue of collision sensing. Traditional scratch sprites can bypass this by using the 'if touching__' block. Pen program s...not so easy. Here's how I solved it: qq 1. Find the positions of the two circles (x and y coordinates), as well as the size of the larger circle 2. Find the radius of the larger circle (this is because pen size does not directly correlate to distance) 3. Plug these into the pythagorean theorem to solve for the hypotenuse (this is the distance variable) 4. Check to see if the hypotenuse is smaller than the radius of the circle. If so, it triggers a collision, turning the larger circle orange. 5. Using the smaller circle's position relative to the center of the larger circle, one can trigonometrically determine the smaller circle's direction relative to the larger circle. Then a script places the smaller circle at the center of the larger, points it in the direction, and moves it until it no longer intersects.