Logo Bolo: a re-envisioning of the classic tank game by Stuart Cheshire in NetLogo
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

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