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.

492 lines
8.5 KiB

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