Logo Bolo: a re-envisioning of the classic tank game by Stuart Cheshire in NetLogo
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

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