Logo Bolo: a re-envisioning of the classic tank game by Stuart Cheshire in NetLogo
25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

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