Advertisement
dmesticg

Untitled

Feb 26th, 2018
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.56 KB | None | 0 0
  1. import random
  2. def setup():
  3. global manx,many,manh,manw,manfill,pennyx,pennyy,pennysize,pennyspeed,pennyfill,arcx,arcy,arcsize,arccolor
  4. global wallx,wally1,wally2,floorx1,floorx2,floory,arcdropx,arcdropy1,arcdropy2
  5. global throw,pause,menu
  6. global counter,backgroundcolor,textcolor,textsize,randomnumber,scores
  7. global restartx,restarty,restarth,restartw,pausex,pausey,pauseh,pausew,clickx,clicky,clickh,clickw,scorex,scorey,scorew,scoreh
  8. #---objects---
  9. manx = 0
  10. many = 350
  11. manh = 100
  12. manw = 50
  13. manfill = 255
  14. pennyx = 50
  15. pennyy = 400
  16. pennysize = 10
  17. pennyspeed = 2
  18. pennyfill = color(139,69,19)
  19. arcx = 0
  20. arcy = 400
  21. arccolor = 0
  22. #---boundries---
  23. wallx = 650
  24. wally1 = 450
  25. wally2 = 0
  26. floorx1 = 0
  27. floorx2 = 675
  28. floory = 450
  29. arcdropx = 0
  30. arcdropy1 = floory
  31. arcdropy2 = arcy
  32. restartx = 500
  33. restarty = 20
  34. restarth = 50
  35. restartw = 100
  36. pausex = restartx
  37. pausey = restarty + restarth
  38. pausew = restartw
  39. pauseh = restarth
  40. clickx = 270
  41. clicky = 450
  42. clickh = restarth
  43. clickw = restartw
  44. scorex = restartx
  45. scorey = restarty + (restarth*2)
  46. scoreh = restarth
  47. scorew = restartw
  48. #---booleans---
  49. throw = False
  50. pause = False
  51. menu = "game"
  52. #---other---
  53. counter = 0
  54. backgroundcolor = 180
  55. textcolor = color(255,0,0)
  56. textsize = 40
  57. randomnumber = 0
  58. scorefile = open("highscores.txt")
  59. words = scorefile.readlines()
  60. #---code---
  61. size(675,500)
  62. randomnumber = random.randint(1,10)*20
  63. arcsize = randomnumber
  64.  
  65.  
  66. def draw():
  67. global wallx,wally1,wally2,floorx1,floorx2,floory,arcdropx,arcdropy1,arcdropy2
  68. global manx,many,manh,manw,manfill,pennyx,pennyy,pennysize,pennyspeed,pennyfill,arcx,arcy,arcsize,arccolor
  69. global throw,pause,randomnumber
  70. global counter,backgroundcolor,textcolor,textsize,randomnumber,scores
  71. global restartx,restarty,restarth,restartw,pausex,pausey,pauseh,pausew,clickx,clicky,clickh,clickw,scorex,scorey,scorew,scoreh
  72. if menu == "game":
  73. background(backgroundcolor)
  74. textSize(30)
  75. fill(textcolor)
  76. text(("Clicks: " + str(counter)),0,30)
  77. arcx = manx + (arcsize / 2) + manw
  78. arcdropx = arcx + (arcsize / 2)
  79. fill(50,156,69)
  80. rect(restartx,restarty,restartw,restarth)
  81. fill(69,11,200)
  82. rect(pausex,pausey,pausew,pauseh)
  83. fill(255,99,71)
  84. rect(clickx,clicky,clickw,clickh)
  85. fill(0,191,255)
  86. rect(scorex,scorey,scorew,scoreh)
  87. fill(255)
  88. text("Restart",499,56)
  89. text("Pause",508,56+pauseh)
  90. text("Throw",273,485)
  91. text("Scores",503,56+(pauseh*2))
  92. line(arcdropx,arcdropy1,arcdropx,arcdropy2)
  93. line(floorx1,floory,floorx2,floory)
  94. line(wallx,wally1,wallx,wally2)
  95. fill(manfill)
  96. rect(manx,many,manw,manh)
  97. fill(pennyfill)
  98. ellipse(pennyx,pennyy,pennysize,pennysize)
  99. noFill()
  100. stroke(arccolor)
  101. arc(arcx,arcy,arcsize,arcsize,PI,TWO_PI)
  102. if throw:
  103. if pennyx < manx + manw + arcsize:
  104. pennyx = pennyx + pennyspeed
  105. pennyy = -1 * sqrt((arcsize / 2)**2 - (pennyx - arcx)**2) + arcy
  106. else:
  107. pennyx = manx + manw + arcsize
  108. pennyy = pennyy + pennyspeed + 1
  109. if pennyy >= floory:
  110. manx = manx + randomnumber
  111. pennyx = manx + manw
  112. pennyy = many + manw
  113. randomnumber = random.randint(1,10)*20
  114. arcsize = randomnumber
  115. throw = False
  116. if pennyx >= wallx:
  117. throw = False
  118. gameover = True
  119. pennyx = wallx
  120. pennyy = pennyy + pennyspeed + 1
  121. fill(textcolor)
  122. textSize(textsize)
  123. text(("You Win! You finished in "+ str(counter) + " clicks"),15,300)
  124. if pennyy >= floory:
  125. pennyy = floory
  126. arcy = 10000
  127. if menu == "scores":
  128. scorelist = get_scores(scorelist)
  129. background(70,130,180)
  130. fill(0,191,255)
  131. rect(scorex,scorey,scorew,scoreh)
  132. fill(255)
  133. text("Return",503,56+(pauseh*2))
  134. for i in range(5):
  135. text(str(i+1) + ".",100,(i*100)+300)
  136. text(scorelist[i][0],200,(i*100)+300)
  137. text("(" + scorelist[i][1] + ")",400,(i*100)+300)
  138.  
  139. def mouseClicked():
  140. global pennyx,throw,counter,pause,menu
  141. global restartx,restarty,restarth,restartw
  142. global scorex,scorey,scorew,scoreh
  143. if menu == "game":
  144. if pausex < mouseX < pausex + pausew and pausey < mouseY < pausey + pauseh:
  145. if pause:
  146. pause = False
  147. else:
  148. pause = True
  149. if pennyx < 650 and pause != True and clickx < mouseX < clickx + clickw and clicky < mouseY < clicky + clickh:
  150. if throw != True:
  151. counter = counter + 1
  152. throw = True
  153. if scorex < mouseX < scorex + scorew and scorey < mouseY < scorey + scoreh:
  154. menu = "scores"
  155. if restartx < mouseX < restartx + restartw and restarty < mouseY < restarty + restarth:
  156. setup()
  157.  
  158. def plzsort(what):
  159. for i in range(len(what) - 1):
  160. for j in range(len(what) - 1 - i):
  161. if what[j] > what[j+1]:
  162. what[j], what[j+1] = what[j+1],what[j]
  163. return what
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement