""" In-class midterm questions review code Rory Solomon Code Toolkit: Python Weds, October 21, 2020 """ y = 300 direction = 0 badGuyX = 800 circleSize = 50 isHit = False growTime = 3000 def setup(): size(800,600) rectMode(CENTER) def draw(): global y, direction, badGuyX, circleSize, isHit, growTime if isHit: background(255,155,155) else: background(255) line(300,325,500,325) ellipse(400,y,circleSize,circleSize) y = y + direction # ground effect: if y > 300: y = 300 # gravity effect. large number would mean faster gravity direction = direction + 1 # draw "bad guy" rect(badGuyX,300,50,50) # move "bad guy" badGuyX = badGuyX - 1 # check for collision between circle and "bad guy" if dist(400,y, badGuyX,300) < circleSize/2 + 25: isHit = True else: isHit = False # make circle get a little bigger every 3 seconds: if millis() > growTime: circleSize = circleSize + 10 growTime = millis() + 3000 def keyPressed(): global direction # jump effect. bigger negative number means bigger jump. # the if statement only allows jump if guy is "on the ground" if y >= 300: direction = -25