Breakout

Calvin (Deutschbein)

W7Wed: 09 Oct

Announcements

  • Problem Set 4: Graphics for today Monday, 14 October, 11:59 PM.
  • Project 2: Breakout for next Monday, 21 October, 11:59 PM.

Today

  • Breakout
  • Timers

Breakout Milestones

  • Breakout is broken up over 5 milestones
  • You have already seen or written pieces of similar code to many of the milestones!
    • Milestone 1: PS4 brick pyramid
    • Milestone 3: Section this week

Milestone 0

  • It's called milestone 1 here. shhhh.

Milestone 1

Milestone 2

Milestone 3

Milestone 4

Today

  • ✓ Breakout
  • Timers

Events

    from pgl import * # same click func def click_func(e): x = e.get_x() y = e.get_y() gw.box.set_location(x,y) gw = GWindow(400,400) # same as my rect, but on "gw.box" gw.box = GRect(400,400,50,50) gw.box.set_filled(True) gw.box.set_color('pink') gw.add(gw.box) gw.add_event_listener("click",click_func)

Timers

  • For Breakout, we need something to move on its own. Rather than going where we click, let's have "floaty box".
    • Box moves some number of pixels every time a timer runs.
    • Box bounces off walls.

Events

  • First, just move the box, or now a ball (why not).
  • That 20 is "milliseconds" I think. from pgl import * def time_func(): # like click_func gw.x += 1 gw.ball.set_location(gw.x,200) gw = GWindow(400,400) gw.x = 0 # store ball and it's x location gw.ball = GOval(gw.x,200,50,50) # like rect gw.add(gw.ball) gw.set_interval(time_func,20) # like listener

Events

  • Go fast + bounce off far wall
  • 350 is window size less shape size. def time_func(): gw.x += gw.vx if gw.x > 350: gw.vx = -gw.vx gw.box.set_location(gw.x,200) gw = GWindow(400,400) gw.vx = 1 gw.x = 0 gw.box = GOval(gw.x,200,50,50) gw.add(gw.box) gw.set_interval(time_func,5)

Events

  • Keep bouncing, faster again.
  • 350 is window size less shape size. def time_func(): gw.x += gw.vx if gw.x > 350 or gw.x < 0: gw.vx = -gw.vx gw.box.set_location(gw.x,200) gw = GWindow(400,400) gw.vx = 1 gw.x = 0 gw.box = GOval(gw.x,200,50,50) gw.add(gw.box) gw.set_interval(time_func,2)

Events

  • Move not-only-horizontally. from pgl import * def time_func(): gw.x += gw.vx gw.y += gw.vy if gw.x > 350 or gw.x < 0: gw.vx = -gw.vx if gw.y > 350 or gw.y < 0: gw.vy = -gw.vy gw.box.set_location(gw.x,gw.y) gw = GWindow(400,400) gw.vx = 3 gw.x = 0 gw.vy = 7 gw.y = 0 gw.box = GOval(gw.x,200,50,50) gw.add(gw.box) gw.set_interval(time_func,20)

Today

  • ✓ Breakout
  • ✓ Timers
  • Free bonus: Mousemove

Events

  • Follow cursor without clicking. from pgl import * # same click func def move_func(e): x = e.get_x() y = e.get_y() gw.box.set_location(x,y) gw = GWindow(400,400) # same as my rect, but on "gw.box" gw.box = GRect(400,400,50,50) gw.box.set_filled(True) gw.box.set_color('pink') gw.add(gw.box) gw.add_event_listener("mousemove",move_func)

Announcements

  • Problem Set 4: Graphics for today Monday, 14 October, 11:59 PM.
  • Project 2: Breakout for next Monday, 21 October, 11:59 PM.