Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ################################# #############
- # TO DO LIST # # NOTES #
- ################################# #############
- # 1. FIX COLLISION --- ORIGINAL NUMS AT 30 CHANGED TO 10 # 1. CORE GAME WORKS JUST NEEDS REFINEMENT
- # 2. ADD TEXTURES # 2. COLLISION NUMS NEED TO BE INCREASED SLIGHTLY
- # 3. MENUS // OPTIONS // DIFFIULTY # 3. POINTS COLLISION SYSTEM NEEDS TO BE ALLIGNED WITH ACTUAL COLLISION SYSTEM (CHECKS LOGS)
- # 4. PAUSE OPTION # 4. PIPE2 DOESNT TOUCH BOTTOM OF SCREEN
- # 5. CHAR CUSTOMISATION
- # 6. POINTS
- # 7. LEADERBOARD (ALREADY MADE)
- import turtle
- import time
- #Screen
- window = turtle.getscreen()
- window.title("8BitHero by Callum")
- window.bgcolor("blue")
- window.setup(width=500, height=800)
- window.tracer(0) #stops all updates
- turtle.hideturtle() #hides arrow that appears in centre of screen
- pen = turtle.Turtle()
- pen.speed(0)
- pen.hideturtle()
- pen.penup()
- pen.color("white")
- pen.goto(0, 250)
- pen.write("0", move=False, align="left", font=("Arial", 32, "normal"))
- #User
- user = turtle.Turtle()
- user.speed(0)
- user.penup() #Removes line
- user.shape("circle")
- user.color("yellow")
- user.shapesize(stretch_wid=1, stretch_len=1, outline=1)
- user.goto(-200,0)
- #Pipes
- pipe1_up = turtle.Turtle()
- pipe1_up.speed(0)
- pipe1_up.penup()
- pipe1_up.color("green")
- pipe1_up.shape("square")
- pipe1_up.shapesize(stretch_wid=18, stretch_len=3, outline=None)
- pipe1_up.goto(300,250)
- pipe1_up.dx = -3
- pipe1_up.dy = 0
- pipe1_up.value = 1
- pipe1_down = turtle.Turtle()
- pipe1_down.speed(0)
- pipe1_down.penup()
- pipe1_down.color("green")
- pipe1_down.shape("square")
- pipe1_down.shapesize(stretch_wid=18, stretch_len=3, outline=None)
- pipe1_down.goto(300,-250)
- pipe1_down.dx = -3
- pipe1_down.dy = 0
- pipe2_up = turtle.Turtle()
- pipe2_up.speed(0)
- pipe2_up.penup()
- pipe2_up.color("green")
- pipe2_up.shape("square")
- pipe2_up.shapesize(stretch_wid=18, stretch_len=3, outline=None)
- pipe2_up.goto(600,300)
- pipe2_up.dx = -3
- pipe2_up.dy = 0
- pipe2_up.value = 1
- pipe2_down = turtle.Turtle()
- pipe2_down.speed(0)
- pipe2_down.penup()
- pipe2_down.color("green")
- pipe2_down.shape("square")
- pipe2_down.shapesize(stretch_wid=18, stretch_len=3, outline=None)
- pipe2_down.goto(600,-200)
- pipe2_down.dx = -3
- pipe2_down.dy = 0
- #Physics
- user.dx = 0
- user.dy = 1
- phys = -0.5
- def go_up(): #changes dy
- user.dy += 12
- if user.dy > 12: #caps speed at 12
- user.dy = 12
- #binding
- window.listen()
- window.onkeypress(go_up, "space")
- #score
- user.score = 0
- print("Score: {}".format(user.score))
- #Main loop
- while True:
- time.sleep(0.02) #so it doesnt run too fast
- window.update() #updates window
- user.dy += phys
- y = user.ycor()
- y += user.dy
- user.sety(y)
- if user.ycor() <-390: #stops him at bottom
- user.dy = 0
- user.sety(-390)
- #move pipe1
- x = pipe1_up.xcor()
- x += pipe1_up.dx
- pipe1_up.setx(x)
- x = pipe1_down.xcor()
- x += pipe1_down.dx
- pipe1_down.setx(x)
- #return pipes
- if pipe1_up.xcor() < -350:
- pipe1_up.setx(350)
- pipe1_down.setx(350)
- pipe1_up.value = 1
- #move pipe2
- x = pipe2_up.xcor()
- x += pipe2_up.dx
- pipe2_up.setx(x)
- x = pipe2_down.xcor()
- x += pipe2_down.dx
- pipe2_down.setx(x)
- #return pipes
- if pipe2_up.xcor() < -350:
- pipe2_up.setx(350)
- pipe2_down.setx(350)
- pipe2_down.value = 1
- #checking for collision
- #pipe1
- if user.xcor() + 10 > pipe1_up.xcor() - 10 and user.xcor() - 10 < pipe1_up.xcor() +10:
- if (user.ycor() + 10 > pipe1_up.ycor() - 180) or (user.ycor() - 10 < pipe1_down.ycor() + 180):
- print("Game over!")
- window.update()
- time.sleep(3)
- #reset score
- user.score = 0
- #move pipe1 back
- pipe1_up.setx(300)
- pipe1_down.setx(300)
- pipe1_up.setx(600)
- pipe1_down.setx(600)
- #move player back (p1)
- user.goto(-200,0)
- user.dy = 0
- #move pipe2 back
- pipe2_up.setx(300)
- pipe2_down.setx(300)
- pipe2_up.setx(600)
- pipe2_down.setx(600)
- #move player back (p2)
- user.goto(-200,0)
- user.dy = 0
- #check score
- if pipe1_up.xcor() + 30 < user.xcor() -10:
- user.score += pipe1_up.value
- pipe1_up.value = 0
- pen.clear()
- pen.write(user.score, move=False, align="left", font=("Arial", 32, "normal"))
- #checking for collision
- #pipe2
- if user.xcor() + 10 > pipe2_up.xcor() - 10 and user.xcor() - 10 < pipe2_up.xcor() +10:
- if (user.ycor() + 10 > pipe2_up.ycor() - 180) or (user.ycor() - 10 < pipe2_down.ycor() + 180):
- print("Game Over!")
- #check score
- if pipe1_up.xcor() + 10 < user.xcor() -10:
- user.score += pipe2_up.value
- pipe2_up.value = 0
- print("Score: {} " .format(user.score))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement