Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- humanXVelocity = 0
- humanYVelocity = 0
- humanX = 200
- humanY = 200
- humanState = "gaar"
- lives = 1
- rectangelVelocity = 3
- rectangelX = 400
- rectangelY = 100
- rectangel2X = 500
- rectangel3X = 600
- rectangel2Y = 300
- rectangel3Y = 200
- score = 0
- upPressed = False
- rightPressed = False
- leftPressed = False
- downPressed = False
- def difficulty():
- global rectangelVelocity
- rectangelVelocity = rectangelVelocity + 0.001
- text(str(rectangelVelocity), 380, 20)
- def highScore():
- global score
- if lives > 0:
- if frameCount % 60 == 0:
- score = score + 1
- text("highscore" + str(score), 20, 20)
- def playerWallCollission():
- global lives, rectangelX, rectangelY, rectangel2X, rectangel2Y, rectangel3X, rectangel3Y
- if humanX > rectangelX and humanX < rectangelX + 20 and humanY > rectangelY and humanY < rectangelY + 70:
- lives = 0
- if humanX > rectangel2X and humanX < rectangel2X + 20 and humanY > rectangel2Y and humanY < rectangel2Y + 70:
- lives = 0
- if humanX > rectangel3X and humanX < rectangel3X + 20 and humanY > rectangel3Y and humanY < rectangel3Y + 70:
- lives = 0
- def gameOver():
- if lives == 0:
- fill(0,0,0)
- rect(0, 0, 400, 400)
- fill(255, 0, 0)
- text("du har tabt..... din kaempe taber", 150 ,200)
- text("press 'R' for restart", 150, 220)
- def drawRectangel3(X):
- global rectangel3X
- global rectangel3Y
- rect(X, rectangel3Y, 20, 70)
- if X <= 0:
- rectangel3X = 400
- rectangel3Y = random(100, 334)
- rectangel3X = rectangel3X - rectangelVelocity
- def drawRectangel2(X):
- global rectangel2X
- global rectangel2Y
- rect(X, rectangel2Y, 20, 70)
- if X <= 0:
- rectangel2X = 400
- rectangel2Y = random(100, 334)
- rectangel2X = rectangel2X - rectangelVelocity
- def drawRectangel(X):
- global rectangelX
- global rectangelY
- rect(X, rectangelY, 20, 70)
- if X <= 0:
- rectangelX = 400
- rectangelY = random(100, 334)
- rectangelX = rectangelX - rectangelVelocity
- def drawScene():
- background(255,255,255)
- noStroke()
- fill(0, 100, 0)
- rect(0, 350, 400, 50)
- def drawMan(x,y):
- noStroke()
- fill(0, 0, 0)
- ellipse(x, y-2, 10, 10)
- stroke(0,0,0)
- strokeWeight(2)
- line(x,y-7, x, y+8)
- line(x, y+8, x+5, y+15)
- line(x, y+8, x-5, y+15)
- line(x, y, x+7, y+7)
- line(x, y, x-7, y+7)
- def motion():
- global humanXVelocity
- global humanYVelocity
- global upPressed
- global rightPressed
- global leftPressed
- global humanState
- if upPressed:
- if humanState == "gaar":
- humanYVelocity = 12
- if humanState == "gaar":
- humanState = "hopper"
- #left
- if leftPressed:
- humanXVelocity = humanXVelocity - 0.8
- #right
- if rightPressed:
- humanXVelocity = humanXVelocity + 0.8
- if downPressed:
- humanYVelocity = humanYVelocity - 1
- def setup():
- size(400, 400)
- def draw():
- global humanXVelocity, humanYVelocity, humanX, humanY
- global humanState
- # Friktion
- humanXVelocity = humanXVelocity * 0.91
- # Bevæg mand
- humanX = humanX + humanXVelocity
- humanY = humanY - humanYVelocity
- if humanX >= 399:
- humanX = 0
- if humanX <= 0:
- humanX = 400
- # Landing efter hop
- if humanY >= 334:
- humanYVelocity = 0
- humanY = 334
- humanState = "gaar"
- else:
- # Tyngdekraft
- humanYVelocity = humanYVelocity - 0.45
- motion()
- drawScene()
- drawMan(humanX, humanY)
- drawRectangel(rectangelX)
- drawRectangel2(rectangel2X)
- drawRectangel3(rectangel3X)
- playerWallCollission()
- gameOver()
- difficulty()
- highScore()
- print(lives)
- def keyPressed():
- global humanXVelocity, humanYVelocity
- global humanState
- global lives
- global rectangelVelocity
- global score
- global rectangelX
- global rectangel2X
- global rectangel3X
- global humanX
- global upPressed
- global rightPressed
- global leftPressed
- global downPressed
- # hop
- if keyCode == UP:
- upPressed = True
- # Gå til venstre
- if keyCode == LEFT:
- leftPressed = True
- # Gå til højre
- if keyCode == RIGHT:
- rightPressed = True
- if key == "r":
- if lives == 0:
- lives = 1
- score = 0
- rectangelVelocity = 3
- rectangelX = 400
- rectangel2X = 500
- rectangel3X = 600
- humanX = 200
- if keyCode == DOWN:
- downPressed = True
- def keyReleased():
- global upPressed
- global rightPressed
- global leftPressed
- global downPressed
- if keyCode == UP:
- upPressed = False
- if keyCode == RIGHT:
- rightPressed = False
- if keyCode == LEFT:
- leftPressed = False
- if keyCode == DOWN:
- downPressed = FalsehumanXVelocity = 0
- humanYVelocity = 0
- humanX = 200
- humanY = 200
- humanState = "gaar"
- lives = 1
- rectangelVelocity = 3
- rectangelX = 400
- rectangelY = 100
- rectangel2X = 500
- rectangel3X = 600
- rectangel2Y = 300
- rectangel3Y = 200
- score = 0
- upPressed = False
- rightPressed = False
- leftPressed = False
- downPressed = False
- def difficulty():
- global rectangelVelocity
- rectangelVelocity = rectangelVelocity + 0.001
- text(str(rectangelVelocity), 380, 20)
- def highScore():
- global score
- if lives > 0:
- if frameCount % 60 == 0:
- score = score + 1
- text("highscore" + str(score), 20, 20)
- def playerWallCollission():
- global lives, rectangelX, rectangelY, rectangel2X, rectangel2Y, rectangel3X, rectangel3Y
- if humanX > rectangelX and humanX < rectangelX + 20 and humanY > rectangelY and humanY < rectangelY + 70:
- lives = 0
- if humanX > rectangel2X and humanX < rectangel2X + 20 and humanY > rectangel2Y and humanY < rectangel2Y + 70:
- lives = 0
- if humanX > rectangel3X and humanX < rectangel3X + 20 and humanY > rectangel3Y and humanY < rectangel3Y + 70:
- lives = 0
- def gameOver():
- if lives == 0:
- fill(0,0,0)
- rect(0, 0, 400, 400)
- fill(255, 0, 0)
- text("du har tabt..... din kaempe taber", 150 ,200)
- text("press 'R' for restart", 150, 220)
- def drawRectangel3(X):
- global rectangel3X
- global rectangel3Y
- rect(X, rectangel3Y, 20, 70)
- if X <= 0:
- rectangel3X = 400
- rectangel3Y = random(100, 334)
- rectangel3X = rectangel3X - rectangelVelocity
- def drawRectangel2(X):
- global rectangel2X
- global rectangel2Y
- rect(X, rectangel2Y, 20, 70)
- if X <= 0:
- rectangel2X = 400
- rectangel2Y = random(100, 334)
- rectangel2X = rectangel2X - rectangelVelocity
- def drawRectangel(X):
- global rectangelX
- global rectangelY
- rect(X, rectangelY, 20, 70)
- if X <= 0:
- rectangelX = 400
- rectangelY = random(100, 334)
- rectangelX = rectangelX - rectangelVelocity
- def drawScene():
- background(255,255,255)
- noStroke()
- fill(0, 100, 0)
- rect(0, 350, 400, 50)
- def drawMan(x,y):
- noStroke()
- fill(0, 0, 0)
- ellipse(x, y-2, 10, 10)
- stroke(0,0,0)
- strokeWeight(2)
- line(x,y-7, x, y+8)
- line(x, y+8, x+5, y+15)
- line(x, y+8, x-5, y+15)
- line(x, y, x+7, y+7)
- line(x, y, x-7, y+7)
- def motion():
- global humanXVelocity
- global humanYVelocity
- global upPressed
- global rightPressed
- global leftPressed
- global humanState
- if upPressed:
- if humanState == "gaar":
- humanYVelocity = 12
- if humanState == "gaar":
- humanState = "hopper"
- #left
- if leftPressed:
- humanXVelocity = humanXVelocity - 0.8
- #right
- if rightPressed:
- humanXVelocity = humanXVelocity + 0.8
- if downPressed:
- humanYVelocity = humanYVelocity - 1
- def setup():
- size(400, 400)
- def draw():
- global humanXVelocity, humanYVelocity, humanX, humanY
- global humanState
- # Friktion
- humanXVelocity = humanXVelocity * 0.91
- # Bevæg mand
- humanX = humanX + humanXVelocity
- humanY = humanY - humanYVelocity
- if humanX >= 399:
- humanX = 0
- if humanX <= 0:
- humanX = 400
- # Landing efter hop
- if humanY >= 334:
- humanYVelocity = 0
- humanY = 334
- humanState = "gaar"
- else:
- # Tyngdekraft
- humanYVelocity = humanYVelocity - 0.45
- motion()
- drawScene()
- drawMan(humanX, humanY)
- drawRectangel(rectangelX)
- drawRectangel2(rectangel2X)
- drawRectangel3(rectangel3X)
- playerWallCollission()
- gameOver()
- difficulty()
- highScore()
- print(lives)
- def keyPressed():
- global humanXVelocity, humanYVelocity
- global humanState
- global lives
- global rectangelVelocity
- global score
- global rectangelX
- global rectangel2X
- global rectangel3X
- global humanX
- global upPressed
- global rightPressed
- global leftPressed
- global downPressed
- # hop
- if keyCode == UP:
- upPressed = True
- # Gå til venstre
- if keyCode == LEFT:
- leftPressed = True
- # Gå til højre
- if keyCode == RIGHT:
- rightPressed = True
- if key == "r":
- if lives == 0:
- lives = 1
- score = 0
- rectangelVelocity = 3
- rectangelX = 400
- rectangel2X = 500
- rectangel3X = 600
- humanX = 200
- if keyCode == DOWN:
- downPressed = True
- def keyReleased():
- global upPressed
- global rightPressed
- global leftPressed
- global downPressed
- if keyCode == UP:
- upPressed = False
- if keyCode == RIGHT:
- rightPressed = False
- if keyCode == LEFT:
- leftPressed = False
- if keyCode == DOWN:
- downPressed = False
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement