Skip to content

Instantly share code, notes, and snippets.

@sgodycki
Created October 24, 2021 18:08
Show Gist options
  • Save sgodycki/a83cea5b1896833e0e9ba6a3281382de to your computer and use it in GitHub Desktop.
Save sgodycki/a83cea5b1896833e0e9ba6a3281382de to your computer and use it in GitHub Desktop.
# 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(150,50,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(200,50,100)
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
"""
Sasha Godycki
CD Toolkit Python Fall 2021
Midterm 10.26.21
"""
from Level_1 import*
from Level_2 import*
level = 1
circleY = 300
circleX = 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
global circleX
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(circleX,circleY, 50,50)
circleY = circleY + circleDirection
circleX = circleX + circleDirection
if circleX > width:
circleDirection = 1
if keyPressed:
if key == 'j':
circleDirection = -1
if key == 'l':
circleDirection =1
if circleY > width:
circleDirection = -1
if keyPressed:
if key == 'a':
circleDirection = 1
if key == 'b':
circleDirection = -1
if keyPressed:
if key == 'j':
circleDirection = -1
if key == 'l':
circleDirection =1
mode=Python
mode.id=jycessing.mode.PythonMode
@sgodycki
Copy link
Author

@rors im trying to get my circle to move right to left as well as up and down and it isnt working. Also I don't know how to get the level to change to level 2 ? I wanted to get it so that once the brown circle got to the top of the screen it would load to level 2 but I havent found anything that would help with that so far.

@rors
Copy link

rors commented Oct 24, 2021

Hi @sgodycki. I can help you with all this but before we get into the questions here, could I ask if you resolved the issues from the other Gist that you sent me? Were the comments that I posted (linked here) helpful? Did that fix the problems?

@sgodycki
Copy link
Author

Hi @sgodycki. I can help you with all this but before we get into the questions here, could I ask if you resolved the issues from the other Gist that you sent me? Were the comments that I posted (linked here) helpful? Did that fix the problems?

Yes it did fix the previous bug

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