Logo Bolo: a re-envisioning of the classic tank game by Stuart Cheshire in NetLogo
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

lobo.nlogo 8.3 KiB

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