EL/LAK - Python Course

worksheet 05

  1. What's wrong with this code that uses a function to draw a stick figure? Assume the colors are already defined and the rest of the program is ok. What is wrong with the code?
    # Head
    pygame.draw.circle(screen, BLACK, [96,83,10,10], 0)
    # Legs
    pygame.draw.line(screen, BLACK, [100,100], [105,110], 2)
    pygame.draw.line(screen, BLACK, [100,100], [95,110], 2)
    # Body
    pygame.draw.line(screen, RED, [100,100], [100,90], 2)
    # Arms
    pygame.draw.line(screen, RED, [100,90], [104,100], 2)
    pygame.draw.line(screen, RED, [100,90], [96,100], 2)
  2. Show how to grab the mouse coordinates, and then grab just the x coordinate of where the mouse is.
  3. Why is it important to keep the event processing loop ``together'' and only have one of them? It is more than organization, there will be subtle hard-to-detect errors. What are they and why will they happen without the event processing loop together? ( If needed review the event processing loop)
  4. When we created a bouncing rectangle, we multiplied the speed times -1 when the rectangle hit the edge of the screen. Explain why that technique won't work for moving an object with the keyboard.
  5. Why does movement with the keyboard or game controller need to have a starting x, y location, but the mouse doesn't?