Advertisement
Guest User

Callums game #2

a guest
Jan 21st, 2020
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 5.22 KB | None | 0 0
  1. #################################                               #############
  2. #           TO DO LIST          #                               #   NOTES   #
  3. #################################                               #############                    
  4. # 1. FIX COLLISION --- ORIGINAL NUMS AT 30 CHANGED TO 10        # 1. CORE GAME WORKS JUST NEEDS REFINEMENT
  5. # 2. ADD TEXTURES                                               # 2. COLLISION NUMS NEED TO BE INCREASED SLIGHTLY
  6. # 3. MENUS // OPTIONS // DIFFIULTY                              # 3. POINTS COLLISION SYSTEM NEEDS TO BE ALLIGNED WITH ACTUAL COLLISION SYSTEM (CHECKS LOGS)
  7. # 4. PAUSE OPTION                                               # 4. PIPE2 DOESNT TOUCH BOTTOM OF SCREEN
  8. # 5. CHAR CUSTOMISATION
  9. # 6. POINTS
  10. # 7. LEADERBOARD (ALREADY MADE)
  11.  
  12.  
  13.  
  14.  
  15. import turtle
  16. import time
  17.  
  18. #Screen
  19.  
  20. window = turtle.getscreen()
  21. window.title("8BitHero by Callum")
  22. window.bgcolor("blue")
  23. window.setup(width=500, height=800)
  24. window.tracer(0) #stops all updates
  25. turtle.hideturtle() #hides arrow that appears in centre of screen
  26.  
  27. pen = turtle.Turtle()
  28. pen.speed(0)
  29. pen.hideturtle()
  30. pen.penup()
  31. pen.color("white")
  32. pen.goto(0, 250)
  33. pen.write("0", move=False, align="left", font=("Arial", 32, "normal"))
  34.  
  35. #User
  36.  
  37. user = turtle.Turtle()
  38. user.speed(0)
  39. user.penup() #Removes line
  40. user.shape("circle")
  41. user.color("yellow")
  42. user.shapesize(stretch_wid=1, stretch_len=1, outline=1)
  43. user.goto(-200,0)
  44.  
  45. #Pipes
  46.  
  47. pipe1_up = turtle.Turtle()
  48. pipe1_up.speed(0)
  49. pipe1_up.penup()
  50. pipe1_up.color("green")
  51. pipe1_up.shape("square")
  52. pipe1_up.shapesize(stretch_wid=18, stretch_len=3, outline=None)
  53. pipe1_up.goto(300,250)
  54. pipe1_up.dx = -3
  55. pipe1_up.dy = 0
  56. pipe1_up.value = 1
  57.  
  58. pipe1_down = turtle.Turtle()
  59. pipe1_down.speed(0)
  60. pipe1_down.penup()
  61. pipe1_down.color("green")
  62. pipe1_down.shape("square")
  63. pipe1_down.shapesize(stretch_wid=18, stretch_len=3, outline=None)
  64. pipe1_down.goto(300,-250)
  65. pipe1_down.dx = -3
  66. pipe1_down.dy = 0
  67.  
  68. pipe2_up = turtle.Turtle()
  69. pipe2_up.speed(0)
  70. pipe2_up.penup()
  71. pipe2_up.color("green")
  72. pipe2_up.shape("square")
  73. pipe2_up.shapesize(stretch_wid=18, stretch_len=3, outline=None)
  74. pipe2_up.goto(600,300)
  75. pipe2_up.dx = -3
  76. pipe2_up.dy = 0
  77. pipe2_up.value = 1
  78.  
  79.  
  80. pipe2_down = turtle.Turtle()
  81. pipe2_down.speed(0)
  82. pipe2_down.penup()
  83. pipe2_down.color("green")
  84. pipe2_down.shape("square")
  85. pipe2_down.shapesize(stretch_wid=18, stretch_len=3, outline=None)
  86. pipe2_down.goto(600,-200)
  87. pipe2_down.dx = -3
  88. pipe2_down.dy = 0
  89.  
  90.  
  91.  
  92. #Physics
  93.  
  94. user.dx = 0
  95. user.dy = 1
  96.  
  97. phys = -0.5
  98.  
  99. def go_up(): #changes dy
  100.     user.dy += 12
  101.  
  102.     if user.dy > 12:    #caps speed at 12
  103.         user.dy = 12
  104.  
  105. #binding
  106. window.listen()
  107. window.onkeypress(go_up, "space")
  108.  
  109. #score
  110.  
  111. user.score = 0
  112. print("Score: {}".format(user.score))
  113.  
  114. #Main loop
  115. while True:
  116.     time.sleep(0.02) #so it doesnt run too fast
  117.     window.update() #updates window
  118.     user.dy += phys
  119.     y = user.ycor()
  120.     y += user.dy
  121.     user.sety(y)
  122.     if user.ycor() <-390: #stops him at bottom
  123.         user.dy = 0
  124.         user.sety(-390)
  125.     #move pipe1
  126.     x = pipe1_up.xcor()
  127.     x += pipe1_up.dx
  128.     pipe1_up.setx(x)
  129.  
  130.     x = pipe1_down.xcor()
  131.     x += pipe1_down.dx
  132.     pipe1_down.setx(x)
  133.  
  134.     #return pipes
  135.     if pipe1_up.xcor() < -350:
  136.         pipe1_up.setx(350)
  137.         pipe1_down.setx(350)
  138.         pipe1_up.value = 1
  139.        
  140.  
  141.     #move pipe2
  142.     x = pipe2_up.xcor()
  143.     x += pipe2_up.dx
  144.     pipe2_up.setx(x)
  145.  
  146.     x = pipe2_down.xcor()
  147.     x += pipe2_down.dx
  148.     pipe2_down.setx(x)
  149.  
  150.     #return pipes
  151.     if pipe2_up.xcor() < -350:
  152.         pipe2_up.setx(350)
  153.         pipe2_down.setx(350)
  154.         pipe2_down.value = 1
  155.  
  156.  
  157.     #checking for collision
  158.     #pipe1
  159.     if user.xcor() + 10 > pipe1_up.xcor() - 10 and user.xcor() - 10 < pipe1_up.xcor() +10:
  160.         if (user.ycor() + 10 > pipe1_up.ycor() - 180) or (user.ycor() - 10 < pipe1_down.ycor() + 180):
  161.             print("Game over!")
  162.             window.update()
  163.             time.sleep(3)
  164.             #reset score
  165.             user.score = 0
  166.             #move pipe1 back
  167.             pipe1_up.setx(300)
  168.             pipe1_down.setx(300)
  169.             pipe1_up.setx(600)
  170.             pipe1_down.setx(600)
  171.             #move player back (p1)
  172.             user.goto(-200,0)
  173.             user.dy = 0
  174.             #move pipe2 back
  175.             pipe2_up.setx(300)
  176.             pipe2_down.setx(300)
  177.             pipe2_up.setx(600)
  178.             pipe2_down.setx(600)
  179.             #move player back (p2)
  180.             user.goto(-200,0)
  181.             user.dy = 0
  182.  
  183.     #check score
  184.     if pipe1_up.xcor() + 30 < user.xcor() -10:
  185.         user.score += pipe1_up.value
  186.         pipe1_up.value = 0
  187.         pen.clear()
  188.         pen.write(user.score, move=False, align="left", font=("Arial", 32, "normal"))
  189.  
  190.  
  191.     #checking for collision
  192.     #pipe2
  193.     if user.xcor() + 10 > pipe2_up.xcor() - 10 and user.xcor() - 10 < pipe2_up.xcor() +10:
  194.         if (user.ycor() + 10 > pipe2_up.ycor() - 180) or (user.ycor() - 10 < pipe2_down.ycor() + 180):
  195.             print("Game Over!")
  196.  
  197.     #check score
  198.     if pipe1_up.xcor() + 10 < user.xcor() -10:
  199.         user.score += pipe2_up.value
  200.         pipe2_up.value = 0
  201.         print("Score: {} " .format(user.score))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement