Book
Module 5 - Section 2 - Mouse control
Module 5 - Section 2 - Mouse control
Completion requirements
View
5.2.4 - Moving the Stick Figure
Download the code for the Stick Figure from here and open it to Thonny.
We will use the mouse to move the Stick Figure.
Uncomment lines 52 to 55, taking care of indentation, to read the position of the mouse.
Run the code and you should see the position of the mouse printed in CLI area.
Change lines 65 to 79 to add movement to the drawings.
# Draw stick figure
# Head
pygame.draw.circle(screen, BLACK, [100 + x, 100 + y], 15)
# Body
pygame.draw.line(screen, ORANGE, [100 + x, 115 + y], [100 + x , 180 + y], 5)
# Legs
pygame.draw.line(screen, BLUE, [100 + x , 180 + y ], [80 + x, 250 + y], 5)
pygame.draw.line(screen, BLUE, [100 + x, 180 + y], [120 + x, 250 + y], 5)
# Arms
pygame.draw.line(screen, RED, [100 + x, 125 + y], [50 + x, 140 + y], 5)
pygame.draw.line(screen, RED, [100 + x, 125 + y], [150 + x, 140 + y], 5)
Don't forget to check the indentation.
You can download the code from here to test it