Advertisement
dmesticg

Untitled

Feb 26th, 2018
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.05 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,count,lastkey
  7. global restartx,restarty,restarth,restartw,pausex,pausey,pauseh,pausew,clickx,clicky,clickh,clickw,scorex,scorey,scorew,scoreh,p1name
  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 = "start"
  52. #---other---
  53. counter = 0
  54. backgroundcolor = 180
  55. textcolor = color(255,0,0)
  56. textsize = 40
  57. randomnumber = 0
  58. scorefile = "highscores.txt"
  59. scores = {}
  60. scores = filetodict(scorefile)
  61. p1name = ""
  62. #---code---
  63. size(675,500)
  64. randomnumber = random.randint(1,10)*20
  65. arcsize = randomnumber
  66. lastkey = ""
  67.  
  68.  
  69. def draw():
  70. global wallx,wally1,wally2,floorx1,floorx2,floory,arcdropx,arcdropy1,arcdropy2
  71. global manx,many,manh,manw,manfill,pennyx,pennyy,pennysize,pennyspeed,pennyfill,arcx,arcy,arcsize,arccolor
  72. global throw,pause,randomnumber,p1name,menu,lastkey
  73. global counter,backgroundcolor,textcolor,textsize,randomnumber,scores,count
  74. global restartx,restarty,restarth,restartw,pausex,pausey,pauseh,pausew,clickx,clicky,clickh,clickw,scorex,scorey,scorew,scoreh
  75. # if menu == "start":
  76. # background(0)
  77. # textSize(20)
  78. # text("please enter your name: "+p1name,50,100)
  79. if menu == "game":
  80. background(backgroundcolor)
  81. textSize(30)
  82. fill(textcolor)
  83. text(("Clicks: " + str(counter)),0,30)
  84. arcx = manx + (arcsize / 2) + manw
  85. arcdropx = arcx + (arcsize / 2)
  86. fill(50,156,69)
  87. rect(restartx,restarty,restartw,restarth)
  88. fill(69,11,200)
  89. rect(pausex,pausey,pausew,pauseh)
  90. fill(255,99,71)
  91. rect(clickx,clicky,clickw,clickh)
  92. fill(0,191,255)
  93. rect(scorex,scorey,scorew,scoreh)
  94. fill(255)
  95. text("Restart",499,56)
  96. text("Pause",508,56+pauseh)
  97. text("Throw",273,485)
  98. text("Scores",503,56+(pauseh*2))
  99. line(arcdropx,arcdropy1,arcdropx,arcdropy2)
  100. line(floorx1,floory,floorx2,floory)
  101. line(wallx,wally1,wallx,wally2)
  102. fill(manfill)
  103. rect(manx,many,manw,manh)
  104. fill(pennyfill)
  105. ellipse(pennyx,pennyy,pennysize,pennysize)
  106. noFill()
  107. stroke(arccolor)
  108. arc(arcx,arcy,arcsize,arcsize,PI,TWO_PI)
  109. if throw:
  110. if pennyx < manx + manw + arcsize:
  111. pennyx = pennyx + pennyspeed
  112. pennyy = -1 * sqrt((arcsize / 2)**2 - (pennyx - arcx)**2) + arcy
  113. else:
  114. pennyx = manx + manw + arcsize
  115. pennyy = pennyy + pennyspeed + 1
  116. if pennyy >= floory:
  117. manx = manx + randomnumber
  118. pennyx = manx + manw
  119. pennyy = many + manw
  120. randomnumber = random.randint(1,10)*20
  121. arcsize = randomnumber
  122. throw = False
  123. if pennyx >= wallx:
  124. throw = False
  125. gameover = True
  126. pennyx = wallx
  127. pennyy = pennyy + pennyspeed + 1
  128. fill(textcolor)
  129. textSize(textsize)
  130. text(("You Win! You finished in "+ str(counter) + " clicks"),15,300)
  131. if pennyy >= floory:
  132. pennyy = floory
  133. arcy = 10000
  134. if menu == "scores":
  135. background(70,130,180)
  136. fill(0,191,255)
  137. rect(pausex,pausey,pausew,pauseh)
  138. fill(255)
  139. textSize(30)
  140. text("Return",503,56+(pauseh))
  141. count = 0
  142. for keys,values in scores.items():
  143. count = count + 1
  144. text((keys+" : "+values),200,100+(count*50))
  145.  
  146. def mouseClicked():
  147. global pennyx,throw,counter,pause,menu
  148. global restartx,restarty,restarth,restartw
  149. global scorex,scorey,scorew,scoreh
  150. if menu == "game":
  151. if pausex < mouseX < pausex + pausew and pausey < mouseY < pausey + pauseh:
  152. if pause:
  153. pause = False
  154. else:
  155. pause = True
  156. if pennyx < 650 and pause != True and clickx < mouseX < clickx + clickw and clicky < mouseY < clicky + clickh:
  157. if throw != True:
  158. counter = counter + 1
  159. throw = True
  160. if scorex < mouseX < scorex + scorew and scorey < mouseY < scorey + scoreh:
  161. menu = "scores"
  162. if restartx < mouseX < restartx + restartw and restarty < mouseY < restarty + restarth:
  163. setup()
  164. if menu == "scores":
  165. if pausex < mouseX < pausex + pausew and pausey < mouseY < pausey + pauseh:
  166. menu = "game"
  167.  
  168.  
  169. def plzsort(what):
  170. for i in range(len(what) - 1):
  171. for j in range(len(what) - 1 - i):
  172. if what[j] > what[j+1]:
  173. what[j], what[j+1] = what[j+1],what[j]
  174. return what
  175.  
  176. def filetodict(file):
  177. dictionary = {}
  178. with open(file) as a:
  179. for line in a:
  180. (name,score) = line.split()
  181. dictionary[name] = score
  182. return dictionary
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement