Logo Bolo: a re-envisioning of the classic tank game by Stuart Cheshire in NetLogo
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

600 rindas
10 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. output-print (word (round timer) ": " agent ": " action " (" msg ")")
  83. end
  84. to setup-defaults
  85. set-patch-size 30
  86. resize-world -8 8 -8 8
  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. set tank-max-ammo 24
  95. set tank-max-armor 8
  96. set base-max-ammo 50
  97. set base-max-armor 20
  98. set pill-anger-range [1.2 0.2]
  99. set pill-max-armor 8
  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. end
  109. to load-map
  110. ask patches [
  111. set pcolor (random 3) - 5 + green
  112. ]
  113. end
  114. to show-crosshairs
  115. clear-drawing
  116. if mouse-inside? [
  117. ask patch mouse-xcor mouse-ycor [
  118. draw-border white 1
  119. ]
  120. ]
  121. if player-has-target? [
  122. ask patch player-target-xcor player-target-ycor [
  123. draw-border white 2
  124. ]
  125. ]
  126. end
  127. to draw-border [b-color b-thickness]
  128. sprout 1 [
  129. set color b-color
  130. set pen-size b-thickness
  131. set heading 0
  132. fd 0.5
  133. pd
  134. rt 90
  135. fd 0.5
  136. repeat 3 [
  137. rt 90
  138. fd 1
  139. ]
  140. rt 90
  141. fd 0.5
  142. die
  143. ]
  144. end
  145. to show-hud
  146. end
  147. to render
  148. display
  149. no-display
  150. end
  151. to keep-time
  152. let time-since-last-tick timer - last-tick-time
  153. let wait-time (1 / max-fps) - time-since-last-tick
  154. wait wait-time
  155. tick
  156. set last-tick-time timer
  157. end
  158. to play-sound [name]
  159. if enable-sound? [
  160. let dist distancexy ([xcor] of player) ([ycor] of player)
  161. let volume 127 - (dist * 4)
  162. if volume > 0 [
  163. sound:play-drum (table:get sounds name) volume
  164. ]
  165. ]
  166. end
  167. @#$#@#$#@
  168. GRAPHICS-WINDOW
  169. 452
  170. 10
  171. 972
  172. 551
  173. 8
  174. 8
  175. 30.0
  176. 1
  177. 10
  178. 1
  179. 1
  180. 1
  181. 0
  182. 1
  183. 1
  184. 1
  185. -8
  186. 8
  187. -8
  188. 8
  189. 0
  190. 0
  191. 1
  192. frames
  193. BUTTON
  194. 43
  195. 100
  196. 138
  197. 133
  198. New Game
  199. setup
  200. NIL
  201. 1
  202. T
  203. OBSERVER
  204. NIL
  205. R
  206. NIL
  207. NIL
  208. BUTTON
  209. 290
  210. 99
  211. 384
  212. 132
  213. Play Game
  214. go
  215. T
  216. 1
  217. T
  218. OBSERVER
  219. NIL
  220. G
  221. NIL
  222. NIL
  223. MONITOR
  224. 269
  225. 290
  226. 389
  227. 339
  228. Player Speed
  229. [speed] of player
  230. 8
  231. 1
  232. 12
  233. BUTTON
  234. 109
  235. 172
  236. 230
  237. 224
  238. FIRE!
  239. player-fire
  240. NIL
  241. 1
  242. T
  243. OBSERVER
  244. NIL
  245. F
  246. NIL
  247. NIL
  248. MONITOR
  249. 270
  250. 350
  251. 389
  252. 399
  253. Player Has Target?
  254. player-has-target?
  255. 5
  256. 1
  257. 12
  258. OUTPUT
  259. 1012
  260. 10
  261. 1500
  262. 557
  263. 12
  264. MONITOR
  265. 55
  266. 290
  267. 149
  268. 339
  269. Player Deaths
  270. player-deaths
  271. 17
  272. 1
  273. 12
  274. MONITOR
  275. 55
  276. 350
  277. 148
  278. 399
  279. Player Kills
  280. player-kills
  281. 17
  282. 1
  283. 12
  284. MONITOR
  285. 160
  286. 290
  287. 261
  288. 339
  289. Player Ammo
  290. [ammunition] of player
  291. 17
  292. 1
  293. 12
  294. MONITOR
  295. 160
  296. 350
  297. 260
  298. 399
  299. Player Armor
  300. [armor] of player
  301. 17
  302. 1
  303. 12
  304. SWITCH
  305. 264
  306. 179
  307. 394
  308. 212
  309. enable-sound?
  310. enable-sound?
  311. 0
  312. 1
  313. -1000
  314. MONITOR
  315. 272
  316. 411
  317. 390
  318. 460
  319. Player Target
  320. word \"(\" player-target-xcor \", \" player-target-ycor \")\"
  321. 10
  322. 1
  323. 12
  324. BUTTON
  325. 109
  326. 235
  327. 230
  328. 268
  329. Cancel Order
  330. player-cancel-order
  331. NIL
  332. 1
  333. T
  334. OBSERVER
  335. NIL
  336. C
  337. NIL
  338. NIL
  339. BUTTON
  340. 109
  341. 536
  342. 368
  343. 569
  344. NIL
  345. ask one-of bases [claim-base tank 2]
  346. NIL
  347. 1
  348. T
  349. OBSERVER
  350. NIL
  351. NIL
  352. NIL
  353. NIL
  354. MONITOR
  355. 160
  356. 412
  357. 259
  358. 461
  359. Player's Pills
  360. [number-of-pills] of player
  361. 17
  362. 1
  363. 12
  364. MONITOR
  365. 261
  366. 584
  367. 357
  368. 629
  369. Pillbox Anger
  370. [anger] of pillbox 4
  371. 6
  372. 1
  373. 11
  374. MONITOR
  375. 148
  376. 584
  377. 246
  378. 629
  379. Pillbox Armor
  380. [armor] of pillbox 4
  381. 17
  382. 1
  383. 11
  384. @#$#@#$#@
  385. WHAT IS IT?
  386. -----------
  387. This section could give a general understanding of what the model is trying to show or explain.
  388. HOW IT WORKS
  389. ------------
  390. This section could explain what rules the agents use to create the overall behavior of the model.
  391. HOW TO USE IT
  392. -------------
  393. This section could explain how to use the model, including a description of each of the items in the interface tab.
  394. THINGS TO NOTICE
  395. ----------------
  396. This section could give some ideas of things for the user to notice while running the model.
  397. THINGS TO TRY
  398. -------------
  399. This section could give some ideas of things for the user to try to do (move sliders, switches, etc.) with the model.
  400. EXTENDING THE MODEL
  401. -------------------
  402. 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.
  403. NETLOGO FEATURES
  404. ----------------
  405. 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.
  406. RELATED MODELS
  407. --------------
  408. This section could give the names of models in the NetLogo Models Library or elsewhere which are of related interest.
  409. CREDITS AND REFERENCES
  410. ----------------------
  411. 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.
  412. @#$#@#$#@
  413. default
  414. true
  415. 0
  416. Polygon -7500403 true true 150 5 40 250 150 205 260 250
  417. base
  418. false
  419. 0
  420. Rectangle -1184463 true false 60 240 120 255
  421. Rectangle -1184463 true false 120 225 180 240
  422. Rectangle -1184463 true false 180 240 240 255
  423. Polygon -1184463 true false 45 240 30 240 30 270 60 270 60 255 45 255
  424. Polygon -7500403 true true 195 210 195 225 225 225 225 195 210 195 210 210
  425. Polygon -1184463 true false 60 45 60 30 30 30 30 60 45 60 45 45
  426. Polygon -1184463 true false 240 255 240 270 270 270 270 240 255 240 255 255
  427. Rectangle -1184463 true false 45 60 60 120
  428. Rectangle -1184463 true false 180 45 240 60
  429. Rectangle -1184463 true false 240 180 255 240
  430. Rectangle -1184463 true false 60 120 75 180
  431. Rectangle -1184463 true false 120 60 180 75
  432. Rectangle -1184463 true false 225 120 240 180
  433. Rectangle -1184463 true false 45 180 60 240
  434. Rectangle -1184463 true false 60 45 120 60
  435. Rectangle -1184463 true false 240 60 255 120
  436. Rectangle -1184463 true false 135 135 165 165
  437. Rectangle -1184463 true false 165 120 180 135
  438. Rectangle -1184463 true false 120 120 135 135
  439. Rectangle -1184463 true false 120 165 135 180
  440. Rectangle -1184463 true false 165 165 180 180
  441. Rectangle -7500403 true true 195 105 210 195
  442. Polygon -1184463 true false 255 60 270 60 270 30 240 30 240 45 255 45
  443. Rectangle -7500403 true true 105 90 195 105
  444. Rectangle -7500403 true true 90 105 105 195
  445. Rectangle -7500403 true true 105 195 195 210
  446. Polygon -7500403 true true 210 105 225 105 225 75 195 75 195 90 210 90
  447. Polygon -7500403 true true 105 90 105 75 75 75 75 105 90 105 90 90
  448. Polygon -7500403 true true 90 195 75 195 75 225 105 225 105 210 90 210
  449. bullet
  450. true
  451. 5
  452. Rectangle -16777216 true false 135 30 165 90
  453. Rectangle -1 true false 135 90 165 150
  454. Rectangle -1 true false 135 150 165 210
  455. Polygon -16777216 true false 135 30 150 0 165 30 135 30
  456. Rectangle -2674135 true false 135 210 165 270
  457. Rectangle -16777216 true false 120 270 180 300
  458. Polygon -7500403 true false 195 210 165 150 165 210 195 210
  459. Rectangle -7500403 true false 165 210 195 268
  460. Rectangle -7500403 true false 105 210 135 268
  461. Polygon -7500403 true false 105 210 135 150 135 210 105 210
  462. explosion-large
  463. false
  464. 0
  465. Circle -6459832 true false 2 2 297
  466. Circle -2674135 true false 30 30 240
  467. Circle -955883 true false 60 60 180
  468. Circle -1184463 true false 90 90 120
  469. explosion-med
  470. false
  471. 0
  472. Circle -2674135 true false 0 0 300
  473. Circle -955883 true false 45 45 210
  474. Circle -1184463 true false 90 90 120
  475. explosion-small
  476. false
  477. 0
  478. Circle -2674135 true false 2 2 295
  479. Circle -955883 true false 75 75 148
  480. pillbox-alive
  481. false
  482. 1
  483. Polygon -2674135 true true 270 240 270 270 240 270 180 210 210 180 270 240
  484. Rectangle -2674135 true true 225 135 300 165
  485. Rectangle -2674135 true true 135 0 165 75
  486. Rectangle -2674135 true true 0 135 75 165
  487. Rectangle -2674135 true true 135 225 165 300
  488. Polygon -2674135 true true 240 30 270 30 270 60 210 120 180 90 240 30
  489. Polygon -2674135 true true 30 60 30 30 60 30 120 90 90 120 30 60
  490. Polygon -2674135 true true 60 270 30 270 30 240 90 180 120 210 60 270
  491. Circle -7500403 true false 45 45 210
  492. pillbox-dead
  493. false
  494. 1
  495. Polygon -7500403 true false 240 30 270 30 270 60 240 90 210 60 240 30
  496. Rectangle -7500403 true false 135 0 165 45
  497. Rectangle -7500403 true false 0 135 45 165
  498. Rectangle -7500403 true false 135 255 165 300
  499. Rectangle -7500403 true false 255 135 300 165
  500. Polygon -7500403 true false 30 60 30 30 60 30 90 60 60 90 30 60
  501. Polygon -7500403 true false 60 270 30 270 30 240 60 210 90 240 60 270
  502. Polygon -7500403 true false 270 240 270 270 240 270 210 240 240 210 270 240
  503. Polygon -2674135 true true 195 165 210 180 210 180 210 210 180 210 165 195
  504. Polygon -2674135 true true 165 105 180 90 180 90 210 90 210 120 195 135
  505. Polygon -2674135 true true 105 135 90 120 90 120 90 90 120 90 135 105
  506. Polygon -2674135 true true 135 195 120 210 120 210 90 210 90 180 105 165
  507. tank
  508. true
  509. 1
  510. Rectangle -7500403 true false 78 85 116 103
  511. Polygon -7500403 true false 105 270 210 271 210 105 180 105 180 135 120 135 120 105 90 105 89 270
  512. 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
  513. Polygon -1 true false 135 15 135 150 165 150 165 15
  514. Polygon -1 true false 67 105 67 255 97 255 97 105
  515. Polygon -1 true false 202 105 202 255 232 255 232 105
  516. Rectangle -7500403 true false 184 85 222 103
  517. @#$#@#$#@
  518. NetLogo 4.1.3
  519. @#$#@#$#@
  520. @#$#@#$#@
  521. @#$#@#$#@
  522. @#$#@#$#@
  523. @#$#@#$#@
  524. default
  525. 0.0
  526. -0.2 0 1.0 0.0
  527. 0.0 1 1.0 0.0
  528. 0.2 0 1.0 0.0
  529. link direction
  530. true
  531. 0
  532. Line -7500403 true 150 150 90 180
  533. Line -7500403 true 150 150 210 180
  534. @#$#@#$#@
  535. 0
  536. @#$#@#$#@