Logo Bolo: a re-envisioning of the classic tank game by Stuart Cheshire in NetLogo
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

447 rindas
6.4 KiB

  1. ;; lobo: Logo Bolo
  2. ;; (c) Ben Kurtovic, 2011
  3. ;;
  4. ;; Logo Bolo is a re-envisioning of the classic tank game by Stuart Cheshire in NetLogo.
  5. ;;
  6. __includes [
  7. "bullet.nls"
  8. "player.nls"
  9. "tank.nls"
  10. ]
  11. extensions [
  12. sound
  13. table
  14. ]
  15. globals [
  16. last-tick-time
  17. max-fps
  18. mouse-was-down?
  19. player
  20. player-deaths
  21. player-has-target?
  22. player-kills
  23. player-target-xcor
  24. player-target-ycor
  25. sounds
  26. ]
  27. ;; ===========================
  28. ;; Button-initiated procedures
  29. ;; ===========================
  30. to setup
  31. clear-all
  32. no-display
  33. setup-defaults
  34. ask patches [
  35. set pcolor (random 3) - 5 + green
  36. ]
  37. spawn-player
  38. spawn-tank 0 ask tank 1 [ setxy -6 0 ]
  39. spawn-tank 1 ask tank 2 [ setxy 6 0 ]
  40. render
  41. set last-tick-time timer
  42. end
  43. to go
  44. ask player [
  45. do-player-logic
  46. ]
  47. ask tanks [
  48. do-tank-logic
  49. ]
  50. ask bullets [
  51. do-bullet-logic
  52. ]
  53. show-crosshair
  54. render
  55. keep-time
  56. end
  57. to player-fire
  58. ask player [
  59. fire
  60. ]
  61. end
  62. to player-cancel-order
  63. ask player [
  64. cancel-order
  65. ]
  66. end
  67. ;; ================
  68. ;; Other procedures
  69. ;; ================
  70. to debug [action msg]
  71. ; Comment this and remove the output box
  72. ; to turn off debugging info:
  73. output-print (word (round timer) ": " action ": " msg)
  74. end
  75. to setup-defaults
  76. set-patch-size 30
  77. resize-world -8 8 -8 8
  78. set max-fps 30
  79. set mouse-was-down? false
  80. set player-deaths 0
  81. set player-has-target? false
  82. set player-kills 0
  83. set player-target-xcor 0
  84. set player-target-ycor 0
  85. make-sounds-table
  86. end
  87. to make-sounds-table
  88. set sounds table:make
  89. table:put sounds "fire" "Hand Clap"
  90. table:put sounds "shot player" "Acoustic Snare"
  91. table:put sounds "shot ally" "Acoustic Snare"
  92. table:put sounds "shot enemy" "Acoustic Snare"
  93. table:put sounds "kill player" "Electric Snare"
  94. table:put sounds "kill ally" "Electric Snare"
  95. table:put sounds "kill enemy" "Electric Snare"
  96. end
  97. to show-crosshair
  98. clear-drawing
  99. if mouse-inside? [
  100. ask patch mouse-xcor mouse-ycor [
  101. draw-border white 1
  102. ]
  103. ]
  104. if player-has-target? [
  105. ask patch player-target-xcor player-target-ycor [
  106. draw-border white 2
  107. ]
  108. ]
  109. end
  110. to draw-border [b-color b-thickness]
  111. sprout 1 [
  112. set color b-color
  113. set pen-size b-thickness
  114. set heading 0
  115. fd 0.5
  116. pd
  117. rt 90
  118. fd 0.5
  119. repeat 3 [
  120. rt 90
  121. fd 1
  122. ]
  123. rt 90
  124. fd 0.5
  125. die
  126. ]
  127. end
  128. to render
  129. display
  130. no-display
  131. end
  132. to keep-time
  133. let time-since-last-tick timer - last-tick-time
  134. let wait-time (1 / max-fps) - time-since-last-tick
  135. wait wait-time
  136. tick
  137. set last-tick-time timer
  138. end
  139. to play-sound [name]
  140. if enable-sound? [
  141. let dist distancexy ([xcor] of player) ([ycor] of player)
  142. let volume 127 - (dist * 4)
  143. if volume > 0 [
  144. sound:play-drum (table:get sounds name) volume
  145. ]
  146. ]
  147. end
  148. @#$#@#$#@
  149. GRAPHICS-WINDOW
  150. 452
  151. 10
  152. 972
  153. 551
  154. 8
  155. 8
  156. 30.0
  157. 1
  158. 10
  159. 1
  160. 1
  161. 1
  162. 0
  163. 1
  164. 1
  165. 1
  166. -8
  167. 8
  168. -8
  169. 8
  170. 0
  171. 0
  172. 1
  173. frames
  174. BUTTON
  175. 43
  176. 100
  177. 138
  178. 133
  179. New Game
  180. setup
  181. NIL
  182. 1
  183. T
  184. OBSERVER
  185. NIL
  186. R
  187. NIL
  188. NIL
  189. BUTTON
  190. 290
  191. 99
  192. 384
  193. 132
  194. Play Game
  195. go
  196. T
  197. 1
  198. T
  199. OBSERVER
  200. NIL
  201. G
  202. NIL
  203. NIL
  204. MONITOR
  205. 269
  206. 290
  207. 389
  208. 339
  209. Player Speed
  210. [speed] of player
  211. 8
  212. 1
  213. 12
  214. BUTTON
  215. 109
  216. 172
  217. 230
  218. 224
  219. FIRE!
  220. player-fire
  221. NIL
  222. 1
  223. T
  224. OBSERVER
  225. NIL
  226. F
  227. NIL
  228. NIL
  229. MONITOR
  230. 270
  231. 350
  232. 389
  233. 399
  234. Player Has Target?
  235. player-has-target?
  236. 5
  237. 1
  238. 12
  239. OUTPUT
  240. 998
  241. 30
  242. 1375
  243. 521
  244. 12
  245. MONITOR
  246. 55
  247. 290
  248. 149
  249. 339
  250. Player Deaths
  251. player-deaths
  252. 17
  253. 1
  254. 12
  255. MONITOR
  256. 55
  257. 350
  258. 148
  259. 399
  260. Player Kills
  261. player-kills
  262. 17
  263. 1
  264. 12
  265. MONITOR
  266. 160
  267. 290
  268. 261
  269. 339
  270. Player Ammo
  271. [ammunition] of player
  272. 17
  273. 1
  274. 12
  275. MONITOR
  276. 160
  277. 350
  278. 260
  279. 399
  280. Player Armor
  281. [armor] of player
  282. 17
  283. 1
  284. 12
  285. SWITCH
  286. 264
  287. 179
  288. 394
  289. 212
  290. enable-sound?
  291. enable-sound?
  292. 0
  293. 1
  294. -1000
  295. MONITOR
  296. 272
  297. 411
  298. 390
  299. 460
  300. Player Target
  301. word \"(\" player-target-xcor \", \" player-target-ycor \")\"
  302. 10
  303. 1
  304. 12
  305. BUTTON
  306. 109
  307. 235
  308. 230
  309. 268
  310. Cancel Order
  311. player-cancel-order
  312. NIL
  313. 1
  314. T
  315. OBSERVER
  316. NIL
  317. C
  318. NIL
  319. NIL
  320. @#$#@#$#@
  321. WHAT IS IT?
  322. -----------
  323. This section could give a general understanding of what the model is trying to show or explain.
  324. HOW IT WORKS
  325. ------------
  326. This section could explain what rules the agents use to create the overall behavior of the model.
  327. HOW TO USE IT
  328. -------------
  329. This section could explain how to use the model, including a description of each of the items in the interface tab.
  330. THINGS TO NOTICE
  331. ----------------
  332. This section could give some ideas of things for the user to notice while running the model.
  333. THINGS TO TRY
  334. -------------
  335. This section could give some ideas of things for the user to try to do (move sliders, switches, etc.) with the model.
  336. EXTENDING THE MODEL
  337. -------------------
  338. This section could give some ideas of things to add or change in the procedures tab to make the model more complicated, detailed, accurate, etc.
  339. NETLOGO FEATURES
  340. ----------------
  341. This section could point out any especially interesting or unusual features of NetLogo that the model makes use of, particularly in the Procedures tab. It might also point out places where workarounds were needed because of missing features.
  342. RELATED MODELS
  343. --------------
  344. This section could give the names of models in the NetLogo Models Library or elsewhere which are of related interest.
  345. CREDITS AND REFERENCES
  346. ----------------------
  347. This section could contain a reference to the model's URL on the web if it has one, as well as any other necessary credits or references.
  348. @#$#@#$#@
  349. default
  350. true
  351. 0
  352. Polygon -7500403 true true 150 5 40 250 150 205 260 250
  353. bullet
  354. true
  355. 5
  356. Rectangle -16777216 true false 135 30 165 90
  357. Rectangle -1 true false 135 90 165 150
  358. Rectangle -1 true false 135 150 165 210
  359. Polygon -16777216 true false 135 30 150 0 165 30 135 30
  360. Rectangle -2674135 true false 135 210 165 270
  361. Rectangle -16777216 true false 120 270 180 300
  362. Polygon -7500403 true false 195 210 165 150 165 210 195 210
  363. Rectangle -7500403 true false 165 210 195 268
  364. Rectangle -7500403 true false 105 210 135 268
  365. Polygon -7500403 true false 105 210 135 150 135 210 105 210
  366. tank
  367. true
  368. 1
  369. Rectangle -7500403 true false 78 85 116 103
  370. Polygon -7500403 true false 105 270 210 271 210 105 180 105 180 135 120 135 120 105 90 105 89 270
  371. Polygon -2674135 true true 120 105 90 105 90 180 120 180 120 195 180 195 180 180 210 180 210 105 180 105 165 105 165 135 135 135 135 105 120 105
  372. Polygon -1 true false 135 15 135 150 165 150 165 15
  373. Polygon -1 true false 67 105 67 255 97 255 97 105
  374. Polygon -1 true false 202 105 202 255 232 255 232 105
  375. Rectangle -7500403 true false 184 85 222 103
  376. @#$#@#$#@
  377. NetLogo 4.1.3
  378. @#$#@#$#@
  379. @#$#@#$#@
  380. @#$#@#$#@
  381. @#$#@#$#@
  382. @#$#@#$#@
  383. default
  384. 0.0
  385. -0.2 0 1.0 0.0
  386. 0.0 1 1.0 0.0
  387. 0.2 0 1.0 0.0
  388. link direction
  389. true
  390. 0
  391. Line -7500403 true 150 150 90 180
  392. Line -7500403 true 150 150 210 180
  393. @#$#@#$#@
  394. 0
  395. @#$#@#$#@