Created
October 22, 2021 15:50
-
-
Save sgodycki/a2b66df8c29479cccf7bfd7d063c3cbb to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
global img | |
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 | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from Level_1 import* | |
from Level_2 import* | |
level = 1 | |
circleY = 300 | |
circleDirection = 1 | |
position = 0 | |
startTime = 0 | |
rectY = 200 | |
rectDirection =1 | |
global img | |
def setup(): | |
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 img, 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 | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
mode=Python | |
mode.id=jycessing.mode.PythonMode |
Hi @sgodycki. I forked your code so that I could make edits, and added some comments. Just to make sure you can see that, you can find it here:
https://gist.github.com/rors/daeff74a5904b435c594ff9d1ba96c80
Let me know if that helps.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@rors I keep getting an error message on all of my global variables in level 2 and I don't know how to fix it I even visited one of the new school tutors and she had no idea why I kept getting this error message:
NameError: global name 'position' is not defined
midterm_PART_2.pyde:25: SyntaxWarning: name 'img' declared global after use
fill(50,150,200)
processing.app.SketchException: NameError: global name 'position' is not defined
at jycessing.mode.run.SketchRunner.convertPythonSketchError(Unknown Source)
at jycessing.mode.run.SketchRunner.lambda$startSketch$3(Unknown Source)
at java.lang.Thread.run(Thread.java:748)
Copied to the clipboard. Use shift-click to search the web instead