Advertisement
Guest User

Untitled

a guest
Aug 17th, 2018
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.30 KB | None | 0 0
  1. #### GLOBAL VARIABLES ####
  2. carX=200
  3. carXVelocity = 2
  4. carBattery = 100
  5. cloud1X=400
  6. cloud2X=430
  7. v=0
  8. v2=0
  9. radius=25
  10. radius2=235
  11. carBatteryLoss = 0.1
  12. windSpeed = 0
  13. carState = "FORWARD"
  14. carParkingTimer = 600
  15. ############################
  16.  
  17.  
  18. #### DRAWING FUNCTIONS ####
  19. def drawTree(treeX,treeY):
  20. noStroke()
  21. fill(244, 181, 65)
  22. rect(treeX,treeY,10,20)
  23. fill(146, 244, 66)
  24. ellipse(treeX+5,treeY-15,30,40)
  25.  
  26. def drawPowerplant():
  27. stroke(0,0,0)
  28. fill(150, 144, 133)
  29. rect(200,215,60,30)
  30. fill(0,0,0)
  31. rect(240,185,10,30)
  32. fill(117, 113, 107)
  33. triangle(200,215,216,205,216,215)
  34. triangle(216,215,232,205,232,215)
  35.  
  36. def drawWindmill(windmillX,windmillY):
  37. stroke(255,255,255)
  38. # line(windmillX,windmillY,windmillX+20,windmillY+1)
  39. # line(windmillX,windmillY,windmillX-11,windmillY+17)
  40. # line(windmillX,windmillY,windmillX-9,windmillY-18)
  41. line(windmillX,windmillY,windmillX,windmillY+40)
  42.  
  43. def drawCar(carX, velocity):
  44. #Kører mod højre
  45. if carState == "FORWARD" or carState == "OUT_OF_FUEL" or carState == "PARKING":
  46. stroke(0,0,0)
  47. fill(237, 14, 14)
  48. rect(carX,275,60,17)
  49. fill(196, 7, 7)
  50. rect(carX-20,290,110,15)
  51. fill(0,0,0)
  52. ellipse(carX+3,305,15,15)
  53. ellipse(carX+60,305,15,15)
  54.  
  55. #Kører mod venstre
  56. if carState == "BACKWARD":
  57. stroke(0,0,0)
  58. fill(237, 14, 14)
  59. rect(carX,275,60,17)
  60. fill(196, 7, 7)
  61. rect(carX-30,290,110,15)
  62. fill(0,0,0)
  63. ellipse(carX+3,305,15,15)
  64. ellipse(carX+60,305,15,15)
  65.  
  66. def drawCloud(cloudX,cloudY):
  67. noStroke()
  68. fill(255,255,255)
  69. ellipse(cloudX,cloudY,20,15)
  70. ellipse(cloudX+35,cloudY,20,15)
  71. ellipse(cloudX+17,cloudY,40,25)
  72.  
  73.  
  74. def drawScene():
  75. noStroke()
  76. #Himmel
  77. background(128, 191, 237)
  78.  
  79. #Græs
  80. fill(18, 158, 21)
  81. rect(0,230,400,170)
  82.  
  83. #Vej
  84. fill(111, 119, 111)
  85. rect(0,260,400,70)
  86.  
  87. #Vejlinjer
  88. stroke(255,255,255)
  89. line(0,290,30,290)
  90. line(40,290,70,290)
  91. line(80,290,110,290)
  92. line(120,290,150,290)
  93. line(160,290,190,290)
  94. line(200,290,230,290)
  95. line(240,290,270,290)
  96. line(280,290,310,290)
  97. line(320,290,350,290)
  98. line(360,290,390,290)
  99.  
  100. def drawEverything():
  101. drawScene()
  102. drawCloud(cloud1X,70)
  103. drawCloud(cloud2X,100)
  104. drawCar(carX,1)
  105. drawTree(55,215)
  106. drawTree(85,230)
  107. drawPowerplant()
  108. drawWindmill(350,320)
  109. drawWindmill(300,340)
  110.  
  111. ########## END DRAWING FUNCTIONS ##########
  112.  
  113.  
  114. ############ CONTROL FUNCTIONS ############
  115. def moveSun():
  116. global v2
  117.  
  118. x= 200+cos(v2)*radius2
  119. y= 300-sin(v2)*radius2
  120.  
  121. noStroke()
  122. fill(255, 255, 17)
  123. ellipse(x,y,25,25)
  124.  
  125. v2=v2+0.003
  126.  
  127. def moveCar():
  128. global carX
  129. global carXVelocity
  130. global carState
  131. global carParkingTimer
  132.  
  133. if carState == "FORWARD":
  134. carX=carX+carXVelocity
  135. setCarBattery()
  136. if carX > 400:
  137. carState = "BACKWARD"
  138. if carBattery <= 0:
  139. carState = "OUT_OF_FUEL"
  140.  
  141. elif carState == "BACKWARD":
  142. carX=carX-carXVelocity
  143. setCarBattery()
  144. if carX < 50:
  145. carState = "PARKING"
  146. carParkingTimer = 600
  147. if carBattery <= 0:
  148. carState = "OUT_OF_FUEL"
  149.  
  150. elif carState == "OUT_OF_FUEL":
  151. carXVelocity = 0
  152.  
  153. elif carState == "PARKING":
  154. carParkingTimer = carParkingTimer - 1
  155. if carParkingTimer <= 0:
  156. carParkingTimer = 0
  157. if carParkingTimer == 0:
  158. carState = "FORWARD"
  159.  
  160. def moveClouds():
  161. global cloud1X
  162. global cloud2X
  163.  
  164. cloud1X=cloud1X-0.5
  165. cloud2X=cloud2X-0.5
  166.  
  167. if cloud1X < -100:
  168. cloud1X = 430
  169.  
  170. if cloud2X < -70:
  171. cloud2X = 460
  172.  
  173. def moveWindmill():
  174. stroke(255,255,255)
  175. global windSpeed
  176. global v
  177.  
  178. #Vindemølle 1
  179. x= 350+cos(v)*radius
  180. y= 320-sin(v)*radius
  181.  
  182. line(x,y,350,320)
  183.  
  184. x2= 350+cos(v+2*PI/3)*radius
  185. y2= 320-sin(v+2*PI/3)*radius
  186.  
  187. line(x2,y2,350,320)
  188.  
  189. x3= 350+cos(v+4*PI/3)*radius
  190. y3= 320-sin(v+4*PI/3)*radius
  191.  
  192. line(x3,y3,350,320)
  193.  
  194. #Vindmølle 2
  195. x= 300+cos(v)*radius
  196. y= 340-sin(v)*radius
  197.  
  198. line(x,y,300,340)
  199.  
  200. x2= 300+cos(v+2*PI/3)*radius
  201. y2= 340-sin(v+2*PI/3)*radius
  202.  
  203. line(x2,y2,300,340)
  204.  
  205. x3= 300+cos(v+4*PI/3)*radius
  206. y3= 340-sin(v+4*PI/3)*radius
  207.  
  208. line(x3,y3,300,340)
  209.  
  210. v=v+windSpeed/500
  211.  
  212. #Skift af vindmølle hastighed
  213. if frameCount % 60 == 0:
  214. windSpeed = random(0,30)
  215.  
  216. ############ END CONTROL FUNCTIONS #############
  217.  
  218.  
  219. ########### STATUS AND INDICATORS ##############
  220.  
  221. def writeWindSpeed():
  222. fill(0,0,0)
  223. textSize(10)
  224. text("windspeed: " + str(windSpeed),300,390)
  225.  
  226. def writeFrameCount():
  227. fill(0,0,0)
  228. text(frameCount,350,20)
  229. if frameCount % 60 == 0:
  230. print(frameCount)
  231.  
  232. def writeCarBattery():
  233. fill(0,0,0)
  234. textSize(15)
  235. text("Battery: " + str(carBattery), 20, 40)
  236.  
  237. def writeCarParkingTimer():
  238. fill(0,0,0)
  239. textSize(15)
  240. text("Car Parking Timer: " + str(carParkingTimer),20,60)
  241.  
  242. def writeEverything():
  243. writeWindSpeed()
  244. writeFrameCount()
  245. writeCarBattery()
  246. writeCarParkingTimer()
  247.  
  248. ########### END STATUS AND INDICATORS ############
  249.  
  250.  
  251. ############ CAR BATTERY ###############
  252.  
  253. def setCarBattery():
  254. global carXVelocity
  255. global carBattery
  256. global carBatteryLoss
  257.  
  258. if carBattery <= 0:
  259. carXVelocity = 0
  260. carBatteryLoss = 0
  261. carBattery = 0
  262.  
  263. carBattery = carBattery - carBatteryLoss
  264.  
  265. def keyPressed():
  266. global carBattery
  267. if key == 'c':
  268. carBattery = carBattery + 0.3
  269. if carBattery > 100:
  270. carBattery = 100
  271.  
  272. ######### END CAR BATTERY ##############
  273.  
  274.  
  275. ########### MAIN PROGRAM ##############
  276. def setup():
  277. size(400,400)
  278.  
  279. def draw():
  280. drawEverything()
  281. moveSun()
  282. moveCar()
  283. moveClouds()
  284. moveWindmill()
  285. writeEverything()
  286.  
  287. ##########################################
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement