Advertisement
CatNamedWill

rocket

May 11th, 2024
172
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 12.17 KB | None | 0 0
  1. #1.4 but 10x bigger
  2. from tphysics import *
  3. #tphysics is found on github
  4. from random import randint
  5. import math
  6. yspeed=0
  7. xspeed=0
  8. myspeed=0
  9. mxspeed=0
  10. score=1
  11. fuel=5000
  12. stfuel=0
  13. fuel_storage=5000
  14. bullet_x_speed = 0
  15. bullet_y_speed = 0
  16. bullet_speed = 10
  17. d = 0
  18. pyspeed = 0
  19. pxspeed = 0
  20. p1p = False
  21. p2p = False
  22. p3p = False
  23. p4p = False
  24. p5p = False
  25. p6p = False
  26. p7p = False
  27. p8p = False
  28. p9p = False
  29. p10p = False
  30. p11p = False
  31. p12p = False
  32. p13p = False
  33. p14p = False
  34. p15p = False
  35. p16p = False
  36. p17p = False
  37. p18p = False
  38. p19p = False
  39. p20p = False
  40. p21p = False
  41. p22p = False
  42. p23p = False
  43. p24p = False
  44. p25p = False
  45. p26p = False
  46. p27p = False
  47. p28p = False
  48. p29p = False
  49. p30p = False
  50. p31p = False
  51. p32p = False
  52. p33p = False
  53. p34p = False
  54. p35p = False
  55. p36p = False
  56. game = Game("Rocket Game", "black", fullscreen=True)
  57. planets = []
  58. others = []
  59. p1 = Circle(0, 0, 1250)
  60. p1.fill_colour="yellow"
  61. others.append(p1)
  62. p2 = Circle(3500, 3000, 500)
  63. p2.fill_colour="grey"
  64. planets.append(p2)
  65. p3 = Circle(-3500, 3000, 500)
  66. p3.fill_colour="grey"
  67. planets.append(p3)
  68. p4 = Circle(3500, -2600, 390)
  69. p4.fill_colour="grey"
  70. planets.append(p4)
  71. p5 = Circle(-3500, -2600, 570)
  72. p5.fill_colour="grey"
  73. planets.append(p5)
  74. p6 = Circle(0, 3000, 750)
  75. p6.fill_colour="grey"
  76. planets.append(p6)
  77. p7 = Circle(6500, 6000, 500)
  78. p7.fill_colour="grey"
  79. planets.append(p7)
  80. p8 = Circle(-3500, 6000, 500)
  81. p8.fill_colour="grey"
  82. planets.append(p8)
  83. p9 = Circle(6500, -5600, 390)
  84. p9.fill_colour="blue"
  85. others.append(p9)
  86. p10 = Circle(-6500, -5600, 570)
  87. p10.fill_colour="grey"
  88. planets.append(p10)
  89. p11 = Circle(0, 6000, 750)
  90. p11.fill_colour="grey"
  91. planets.append(p11)
  92. p12 = Circle(9500, 9000, 500)
  93. p12.fill_colour="grey"
  94. planets.append(p12)
  95. p13 = Circle(-6500, 9000, 500)
  96. p13.fill_colour="grey"
  97. planets.append(p13)
  98. p14 = Circle(9500, -8600, 390)
  99. p14.fill_colour="grey"
  100. planets.append(p14)
  101. p15 = Circle(-9500, -8600, 570)
  102. p15.fill_colour="grey"
  103. planets.append(p15)
  104. p16 = Circle(0, 9000, 750)
  105. p16.fill_colour="grey"
  106. planets.append(p16)
  107. p17 = Circle(12500, 12000, 500)
  108. p17.fill_colour="grey"
  109. planets.append(p17)
  110. p18 = Circle(-9500, 12000, 500)
  111. p18.fill_colour="grey"
  112. planets.append(p18)
  113. p19 = Circle(12500, -11600, 390)
  114. p19.fill_colour="grey"
  115. planets.append(p19)
  116. p20 = Circle(-12500, -11600, 570)
  117. p20.fill_colour="grey"
  118. planets.append(p20)
  119. p21 = Circle(0, 12000, 750)
  120. p21.fill_colour="grey"
  121. planets.append(p21)
  122. p22 = Circle(15500, 15000, 500)
  123. p22.fill_colour="grey"
  124. planets.append(p22)
  125. p23 = Circle(-12500, 15000, 500)
  126. p23.fill_colour="grey"
  127. planets.append(p23)
  128. p24 = Circle(15500, -14600, 390)
  129. p24.fill_colour="grey"
  130. planets.append(p24)
  131. p25 = Circle(-15500, -14600, 570)
  132. p25.fill_colour="grey"
  133. planets.append(p25)
  134. p26 = Circle(0, 15000, 750)
  135. p26.fill_colour="grey"
  136. planets.append(p26)
  137. p27 = Circle(18500, 18000, 500)
  138. p27.fill_colour="grey"
  139. planets.append(p27)
  140. p28 = Circle(-15500, 18000, 500)
  141. p28.fill_colour="grey"
  142. planets.append(p28)
  143. p29 = Circle(18500, -17600, 390)
  144. p29.fill_colour="blue"
  145. others.append(p29)
  146. p30 = Circle(-15500, -17600, 570)
  147. p30.fill_colour="grey"
  148. planets.append(p30)
  149. p31 = Circle(00, -3000, 750)
  150. p31.fill_colour="grey"
  151. planets.append(p31)
  152. p32 = Circle(0, -6000, 750)
  153. p32.fill_colour="grey"
  154. planets.append(p32)
  155. p33 = Circle(0, -9000, 750)
  156. p33.fill_colour="grey"
  157. planets.append(p33)
  158. p34 = Circle(0, -12000, 750)
  159. p34.fill_colour="grey"
  160. planets.append(p34)
  161. p35 = Circle(0, -18000, 750)
  162. p35.fill_colour="grey"
  163. planets.append(p35)
  164. a1 = Circle(0, -23000, 1500)
  165. a1.fill_colour="blue"
  166. others.append(a1)
  167. a2 = Circle(0, -23000, 1250)
  168. a2.fill_colour="cyan"
  169. others.append(a2)
  170. p36 = Circle(0, -23000, 750)
  171. p36.fill_colour="green"
  172. missile = Rectangle(0, 0, 8, 18)
  173. planets.append(p36)
  174. station = Rectangle(0, 0, 20, 105)
  175. rocket = Rectangle(0, 0, 15, 45)
  176. bullet = Circle(0, 0, 10, "red")
  177. piratesy = Rectangle(249, 0, 15, 55, "white")
  178. piratesx = Rectangle(0, 0, 45, 15, "white")
  179. pirates = []
  180. pirates.append(piratesy)
  181. pirates.append(piratesx)
  182. for other in others:
  183.     game.add_shape(other)
  184. for planet in planets:
  185.     game.add_shape(planet)
  186. for pirate in pirates:
  187.     game.add_shape(pirate)
  188. game.add_shape(rocket)
  189. game.add_shape(station)
  190. for other in others:
  191.     other.y += 1275
  192. for planet in planets:
  193.     planet.y += 1275
  194.  
  195. def distance(x1, x2, y1, y2):
  196.     dy = y1 - y2
  197.     dx = x1 - x2
  198.     d = math.sqrt(dx **2 + dy **2)
  199.     return d
  200.  
  201. def click(x,y):
  202.     global bullet_x_speed
  203.     global bullet_y_speed
  204.    
  205.     dx = rocket.x - x
  206.     dy = rocket.y - y
  207.  
  208.     v = math.sqrt(math.pow(dx,2) + math.pow(dy,2))
  209.     ratio = bullet_speed / v
  210.  
  211.     bullet_x_speed = -(dx * ratio)
  212.     bullet_y_speed = -(dy * ratio)
  213.  
  214.     game.add_shape(bullet)
  215.     bullet.x = rocket.x
  216.     bullet.y = rocket.y
  217.    
  218. game.addclick(click)    
  219. while True:
  220.     game.write(200, 100, f"fuel: {fuel}", "white", 20)
  221.     game.write(200, 80, f"fuel_storage: {fuel_storage}", "white", 20)
  222.     piratesx.y = piratesy.y
  223.     piratesx.x = piratesy.x
  224.     for planet in planets:
  225.         if planet.collide(bullet):
  226.             bullet_x_speed *= -1
  227.             bullet_y_speed *= -1
  228.     if game.ispressed("1"):
  229.         game.add_shape(station)
  230.         station.y = rocket.y
  231.         station.x = rocket.x
  232.         fuel -= 150
  233.     if rocket.collide(p1) and(p1p == False):
  234.         score += 1
  235.         fuel_storage += 50
  236.         p1p = True
  237.     if rocket.collide(p2) and(p2p == False):
  238.         score += 1
  239.         fuel_storage += 50
  240.         p2p = True
  241.     if rocket.collide(p3) and(p3p == False):
  242.         score += 1
  243.         fuel_storage += 50
  244.         p3p = True
  245.     if rocket.collide(p4) and(p4p == False):
  246.         score += 1
  247.         fuel_storage += 50
  248.         p4p = True
  249.     if rocket.collide(p5) and(p5p == False):
  250.         score += 1
  251.         fuel_storage += 50
  252.         p5p = True
  253.     if rocket.collide(p6) and(p6p == False):
  254.         score += 1
  255.         fuel_storage += 50
  256.         p6p = True
  257.     if rocket.collide(p7) and(p7p == False):
  258.         score += 1
  259.         fuel_storage += 50
  260.         p7p = True
  261.     if rocket.collide(p8) and(p8p == False):
  262.         score += 1
  263.         fuel_storage += 50
  264.         p8p = True
  265.     if rocket.collide(p9) and(p9p == False):
  266.         score += 1
  267.         fuel_storage += 50
  268.         p9p = True
  269.     if rocket.collide(p10) and(p10p == False):
  270.         score += 1
  271.         fuel_storage += 50
  272.         p10p = True
  273.     if rocket.collide(p11) and(p11p == False):
  274.         score += 1
  275.         fuel_storage += 100
  276.         p11p = True
  277.     if rocket.collide(p12) and(p12p == False):
  278.         score += 1
  279.         fuel_storage += 100
  280.         p12p = True
  281.     if rocket.collide(p13) and(p13p == False):
  282.         score += 1
  283.         fuel_storage += 100
  284.         p13p = True
  285.     if rocket.collide(p14) and(p14p == False):
  286.         score += 1
  287.         fuel_storage += 100
  288.         p14p = True
  289.     if rocket.collide(p15) and(p15p == False):
  290.         score += 1
  291.         fuel_storage += 100
  292.         p15p = True
  293.     if rocket.collide(p16) and(p16p == False):
  294.         score += 1
  295.         fuel_storage += 100
  296.         p16p = True
  297.     if rocket.collide(p17) and(p17p == False):
  298.         score += 1
  299.         fuel_storage += 100
  300.         p17p = True
  301.     if rocket.collide(p18) and(p18p == False):
  302.         score += 1
  303.         fuel_storage += 100
  304.         p18p = True
  305.     if rocket.collide(p19) and(p19p == False):
  306.         score += 1
  307.         fuel_storage += 100
  308.         p19p = True
  309.     if rocket.collide(p20) and(p20p == False):
  310.         score += 1
  311.         fuel_storage += 100
  312.         p20p = True
  313.     if rocket.collide(p21) and(p21p == False):
  314.         score += 1
  315.         fuel_storage += 150
  316.         p21p = True
  317.     if rocket.collide(p22) and(p22p == False):
  318.         score += 1
  319.         fuel_storage += 150
  320.         p22p = True
  321.     if rocket.collide(p23) and(p23p == False):
  322.         score += 1
  323.         fuel_storage += 150
  324.         p23p = True
  325.     if rocket.collide(p24) and(p24p == False):
  326.         score += 1
  327.         fuel_storage += 150
  328.         p24p = True
  329.     if rocket.collide(p25) and(p25p == False):
  330.         score += 1
  331.         fuel_storage += 150
  332.         p25p = True
  333.     if rocket.collide(p26) and(p26p == False):
  334.         score += 1
  335.         fuel_storage += 150
  336.         p26p = True
  337.     if rocket.collide(p27) and(p27p == False):
  338.         score += 1
  339.         fuel_storage += 150
  340.         p27p = True
  341.     if rocket.collide(p28) and(p28p == False):
  342.         score += 1
  343.         fuel_storage += 150
  344.         p28p = True
  345.     if rocket.collide(p29) and(p29p == False):
  346.         score += 1
  347.         fuel_storage += 150
  348.         p29p = True
  349.     if rocket.collide(p30) and(p30p == False):
  350.         score += 1
  351.         fuel_storage += 150
  352.         p30p = True
  353.     if rocket.collide(p31) and(p31p == False):
  354.         score += 1
  355.         fuel_storage += 50
  356.         p31p = True
  357.     if rocket.collide(p32) and(p32p == False):
  358.         score += 1
  359.         fuel_storage += 50
  360.         p32p = True
  361.     if rocket.collide(p33) and(p33p == False):
  362.         score += 1
  363.         fuel_storage += 50
  364.         p33p = True
  365.     if rocket.collide(p34) and(p34p == False):
  366.         score += 1
  367.         fuel_storage += 50
  368.         p34p = True
  369.     if rocket.collide(p35) and(p35p == False):
  370.         score += 1
  371.         fuel_storage += 50
  372.         p35p = True
  373.     if rocket.collide(p36) and(p36p == False):
  374.         score += 1
  375.         fuel_storage += 50
  376.         p36p = True
  377.     if station.collide(rocket)and(not(fuel == fuel_storage)):
  378.         fuel += 1
  379.     if game.ispressed("w") and(not(fuel == 0 or (fuel < 0))):
  380.         yspeed -= 0.3 * score
  381.     if game.ispressed("d") and(not(fuel == 0 or (fuel < 0))):
  382.         xspeed -= 0.3 * score
  383.         fuel -= 1
  384.     if game.ispressed("a") and(not(fuel == 0 or (fuel < 0))):
  385.         xspeed += 0.3 * score
  386.         fuel -= 1
  387.     if game.ispressed("s") and(not(fuel == 0 or (fuel < 0))):
  388.         yspeed += 0.3 * score
  389.         fuel -= 1
  390.     if game.ispressed("b") and(not(fuel == 0 or (fuel < 0))):
  391.         yspeed /= 2
  392.         xspeed /= 2
  393.         fuel -= 2
  394.     if rocket.collide(p1):
  395.         xspeed *= 1.5
  396.         yspeed *= 1.5    
  397.     for planet in planets:
  398.         if rocket.collide(planet):
  399.             xspeed *= -1
  400.             yspeed *= -1            
  401.     if rocket.collide(a1):
  402.         xspeed = xspeed *0.99
  403.         yspeed = yspeed *0.99
  404.     if rocket.collide(a2):
  405.         xspeed = xspeed *0.94
  406.         yspeed = yspeed *0.94    
  407.     if rocket.collide(p9):
  408.         for planet in planets:
  409.             planet.x -= 1200 - xspeed * 30
  410.             planet.y += 1200 + yspeed * 30
  411.         for other in others:
  412.             other.x -= 1200 - xspeed * 30
  413.             other.y += 1200 + yspeed * 30
  414.             station.x -= 1200
  415.             station.y += 1200
  416.     if rocket.collide(p29):
  417.         for planet in planets:
  418.             planet. x += 1200 + xspeed * 30
  419.             planet.y -= 1200 - yspeed * 30
  420.         for other in others:
  421.             other.x += 1200 + xspeed * 30
  422.             other.y -= 1200 - yspeed * 30
  423.     distance(piratesy.x, rocket.x, piratesy.y, rocket.y)        
  424.     if d < 250:
  425.         if piratesy.x < rocket.x:
  426.             pxspeed += 0.25
  427.         elif piratesy.x > rocket.x:
  428.             pxspeed -= 0.25
  429.         if piratesy.y < rocket.y:
  430.             pyspeed += 0.15
  431.         elif piratesy.y > rocket.y:
  432.             pyspeed -= 0.15
  433.         if randint(1,75) == 1:
  434.             game.add_shape(missile)
  435.             missile.x = piratesy.x
  436.             missile.y = piratesy.y
  437.     if missile.x < rocket.x:
  438.         mxspeed += 0.5
  439.     elif missile.x > rocket.x:
  440.         mxspeed -= 0.5
  441.     if missile.y < rocket.y:
  442.         myspeed += 0.5
  443.     elif missile.y > rocket.y:
  444.         myspeed -= 0.5            
  445.     for planet in planets:
  446.         planet.y += yspeed
  447.         planet.x += xspeed
  448.     for other in others:
  449.         other.y += yspeed
  450.         other.x += xspeed
  451.     for pirate in pirates:
  452.         pirate.y += yspeed
  453.         pirate.x += xspeed
  454.         pirate.y += pyspeed
  455.         pirate.x += pxspeed
  456.     missile.y += yspeed
  457.     missile.x += xspeed
  458.     missile.y += myspeed
  459.     missile.x += mxspeed
  460.     station.y += yspeed
  461.     station.x += xspeed
  462.     bullet.x += xspeed
  463.     bullet.y += yspeed
  464.     bullet.x += bullet_x_speed + 5
  465.     bullet.y += bullet_y_speed + 5
  466.     game.update()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement