Advertisement
dmesticg

Untitled

Jun 7th, 2018
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.92 KB | None | 0 0
  1. import random
  2. def setup():
  3. global textboxes,man,manfill,penny,pennyspeed,pennyfill,arcx,arcy
  4. global backgroundcolor
  5. global wall,ground,arcdrop
  6. global pause,clicked
  7. global randomnumber, arcsize
  8. #---objects---
  9. restart_text = [500,20,100,50,"Restart",color(50,156,69)]
  10. pause_text = [500,70,100,50,"Pause",color(69,11,200)]
  11. throw_text = [270,450,100,50,"Throw",color(255,99,71)]
  12. score_text = [500,120,100,50,"Scores",color(0,191,255)]
  13. textboxes = [restart_text,pause_text,throw_text,score_text]
  14. man = [0,350,50,100] #x,y,w,h
  15. manfill = 255
  16. penny = [50,400,10] #x,y,size
  17. pennyspeed = 2
  18. pennyfill = color(139,69,19)
  19. arcx = 0
  20. arcy = 400
  21. #---boundries---
  22. wall = [650,450,650,0]
  23. ground = [0,450,675,450]
  24. arcdrop = [0,ground[1],arcy]
  25. #---booleans---
  26. pause = False
  27. clicked = False
  28. #---other---
  29. backgroundcolor = 180
  30. #---code---
  31. size(675,500)
  32. randomnumber = random.randint(1,10)*20
  33. arcsize = randomnumber
  34.  
  35. def drawtextboxes(textboxes):
  36. textSize(30)
  37. fill(255)
  38. for i in range(len(textboxes)):
  39. fill(textboxes[i][5])
  40. rect(textboxes[i][0],textboxes[i][1],textboxes[i][2],textboxes[i][3])
  41. fill(255)
  42. text(textboxes[i][4],textboxes[i][0],textboxes[i][1]+35)
  43.  
  44. def isClicked(info):
  45. clicked = False
  46. if mousePressed and mouseButton == LEFT:
  47. if info[0] < mouseX < info[0] + info[2] and info[1] < mouseY < info[1] + info[3]:
  48. clicked = True
  49. return clicked
  50.  
  51. def throw():
  52. global penny,man,arcsize,arcx,arcy,ground,randomnumber
  53. go = True
  54. if go:
  55. if penny[0] < man[0] + man[2] + arcsize:
  56. penny[0] = penny[0] + pennyspeed
  57. penny[1] = -1 * sqrt((arcsize / 2)**2 - (penny[0] - arcx)**2) + arcy
  58. else:
  59. penny[0] = man[0] + man[2] + arcsize
  60. penny[1] = penny[1] + pennyspeed + 1
  61. if penny[0] >= ground[1]:
  62. man[0] = man[0] + randomnumber
  63. penny[0] = man[0] + man[2]
  64. penny[1] = man[1] + man[2]
  65. randomnumber = random.randint(1,10)*20
  66. arcsize = randomnumber
  67. go = False
  68.  
  69. def draw():
  70. global textboxes,man,manfill,penny,pennyspeed,pennyfill,arcx,arcy
  71. global backgroundcolor
  72. global wall,ground,arcdrop,arcsize
  73. background(backgroundcolor)
  74. arcx = man[0] + (arcsize / 2) + man[2]
  75. arcdrop[0] = arcx + (arcsize / 2)
  76. fill(manfill)
  77. rect(man[0],man[1],man[2],man[3])
  78. fill(pennyfill)
  79. ellipse(penny[0],penny[1],penny[2],penny[2])
  80. noFill()
  81. stroke(0)
  82. arc(arcx,arcy,arcsize,arcsize,PI,TWO_PI)
  83. line(arcdrop[0],arcdrop[1],arcdrop[0],arcdrop[2])
  84. line(ground[0],ground[1],ground[2],ground[3])
  85. line(wall[0],wall[1],wall[2],wall[3])
  86. drawtextboxes(textboxes)
  87. if isClicked(textboxes[2]):
  88. throw()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement