Skip to content

Instantly share code, notes, and snippets.

@rors
Forked from sgodycki/Level_1.py
Last active October 22, 2021 16:33
Show Gist options
  • Save rors/daeff74a5904b435c594ff9d1ba96c80 to your computer and use it in GitHub Desktop.
Save rors/daeff74a5904b435c594ff9d1ba96c80 to your computer and use it in GitHub Desktop.
Sasha midterm
# global img
circleY = 300
circleDirection = 1
position = 0
startTime = 0
rectY = 200
rectDirection =1
def drawLevel1():
global circleY, circleDirection, startTime, position
# image(img,0,0)
fill(50,150,200)
rect(position,200, 50,50)
# move for a little while, then stop
if millis() > startTime and millis() < startTime + 2000:
position = position + 1
# wait a little while, then reset the startTime variable,
# so the above timing starts over:
if millis() > startTime + 4000:
startTime = millis()
global rectY
fill(200,50,150)
rect(200,rectY,50,50)
global rectDirection
rectY= rectY + rectDirection
if rectY > width:
rectDirection = -1
fill(102,51,0)
ellipse(300,circleY, 50,50)
circleY = circleY + circleDirection
if circleY > width:
circleDirection = -1
if circleY < 0:
circleDirection = 1
if keyPressed:
if key == 'j':
circleDirection = -1
if key == 'l':
circleDirection =1
def drawLevel2():
global img, circleY, circleDirection, startTime, position
image(img,0,0)
fill(50,150,200)
rect(position,200, 50,50)
# move for a little while, then stop
if millis() > startTime and millis() < startTime + 1000:
position = position + 1
# wait a little while, then reset the startTime variable,
# so the above timing starts over:
if millis() > startTime + 3000:
startTime = millis()
global rectY
fill(150,50,200)
rect(200,rectY,50,50)
global rectDirection
rectY= rectY + rectDirection
if rectY > width:
rectDirection = -1
fill(102,51,0)
ellipse(300,circleY, 50,50)
circleY = circleY + circleDirection
if circleY > width:
circleDirection = -1
if circleY < 0:
circleDirection = 1
if keyPressed:
if key == 'j':
circleDirection = -1
if key == 'l':
circleDirection =1
from Level_1 import*
from Level_2 import*
level = 1
circleY = 300
circleDirection = 1
position = 0
startTime = 0
rectY = 200
rectDirection =1
def setup():
global img
size(576,720)
img = loadImage("grass background.png")
stroke(50,50,150)
def draw():
if level == 1:
drawLevel1()
elif level ==2:
drawLevel2()
image(img,0,0)
global circleY, circleDirection, startTime, position
fill(50,150,200)
rect(position,200, 50,50)
# move for a little while, then stop
if millis() > startTime and millis() < startTime + 2000:
position = position + 1
# wait a little while, then reset the startTime variable,
# so the above timing starts over:
if millis() > startTime + 4000:
startTime = millis()
global rectY
fill(200,50,150)
rect(200,rectY,50,50)
global rectDirection
rectY= rectY + rectDirection
if rectY > width:
rectDirection = -1
fill(102,51,0)
ellipse(300,circleY, 50,50)
circleY = circleY + circleDirection
if circleY > width:
circleDirection = -1
if circleY < 0:
circleDirection = 1
if keyPressed:
if key == 'j':
circleDirection = -1
if key == 'l':
circleDirection =1
@rors
Copy link
Author

rors commented Oct 22, 2021

By the way, click Revisions above if you would like to see a side-by-side view of my edits.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment