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.

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