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.

709 lines
14 KiB

  1. ;; lobo: Logo Bolo
  2. ;; (c) Ben Kurtovic, 2011
  3. ;;
  4. ;; Logo Bolo is a rewrite of the classic tank game by Stuart Cheshire in NetLogo.
  5. ;;
  6. ;; ============
  7. ;; Declarations
  8. ;; ============
  9. globals [
  10. bullet-speed
  11. bullet-travel-distance
  12. friction
  13. last-tick-time
  14. max-acceleration
  15. max-fps
  16. max-tank-speed
  17. min-acceleration
  18. player
  19. speed-up
  20. turn-speed
  21. ]
  22. breed [bullets bullet]
  23. breed [crosshairs crosshair]
  24. breed [tanks tank]
  25. bullets-own [
  26. travel-distance
  27. ]
  28. tanks-own [
  29. acceleration
  30. speed
  31. team
  32. ]
  33. ;; ===========================
  34. ;; Button-initiated procedures
  35. ;; ===========================
  36. to setup
  37. clear-all
  38. no-display
  39. setup-defaults
  40. ask patches [
  41. set pcolor random 3
  42. ]
  43. spawn-player
  44. display
  45. no-display
  46. set last-tick-time timer
  47. end
  48. to go
  49. do-tank-physics
  50. do-bullet-physics
  51. render
  52. keep-time
  53. end
  54. to player-accelerate
  55. ask player [
  56. if acceleration < 0 [
  57. set acceleration 0
  58. ]
  59. set acceleration acceleration + speed-up
  60. if acceleration > max-acceleration [
  61. set acceleration max-acceleration
  62. ]
  63. ]
  64. end
  65. to player-decelerate
  66. ask player [
  67. set acceleration min-acceleration
  68. ]
  69. end
  70. to player-turn-left
  71. ask player [
  72. lt turn-speed
  73. ]
  74. end
  75. to player-turn-right
  76. ask player [
  77. rt turn-speed
  78. ]
  79. end
  80. to player-fire
  81. ask player [
  82. fire
  83. ]
  84. end
  85. ;; ================
  86. ;; Other procedures
  87. ;; ================
  88. to setup-defaults
  89. set bullet-speed 2
  90. set bullet-travel-distance 16
  91. set friction 0.01
  92. set max-acceleration 0.5
  93. set max-fps 30
  94. set max-tank-speed 0.3
  95. set min-acceleration -0.025
  96. set speed-up 0.1
  97. set turn-speed 24
  98. end
  99. to spawn-player
  100. create-ordered-tanks 1 [
  101. set player (tank who)
  102. set color (get-tank-color "player")
  103. set size 2
  104. set speed 0
  105. set team 0
  106. ]
  107. end
  108. to fire
  109. hatch-bullets 1 [
  110. set color white
  111. set size 1
  112. set travel-distance 0
  113. ]
  114. end
  115. to do-tank-physics
  116. ask tanks [
  117. set speed speed + acceleration
  118. if speed > max-tank-speed [
  119. set speed max-tank-speed
  120. ]
  121. if speed < 0 [
  122. set speed 0
  123. ]
  124. set acceleration acceleration - friction
  125. if acceleration < min-acceleration [
  126. set acceleration min-acceleration
  127. ]
  128. fd speed
  129. ]
  130. end
  131. to do-bullet-physics
  132. ask bullets [
  133. fd bullet-speed
  134. set travel-distance travel-distance + bullet-speed
  135. if travel-distance >= bullet-travel-distance [
  136. die
  137. ]
  138. ]
  139. end
  140. to render
  141. display
  142. no-display
  143. end
  144. to keep-time
  145. let time-since-last-tick timer - last-tick-time
  146. let wait-time (1 / max-fps) - time-since-last-tick
  147. wait wait-time
  148. tick
  149. set last-tick-time timer
  150. end
  151. ;; =================
  152. ;; Monitor reporters
  153. ;; =================
  154. to-report player-speed
  155. report [speed] of player
  156. end
  157. ;; ===============
  158. ;; Other reporters
  159. ;; ===============
  160. to-report get-tank-color [affiliation]
  161. if affiliation = "player" [ report gray ]
  162. if affiliation = "enemy" [ report red ]
  163. if affiliation = "ally" [ report green ]
  164. report black
  165. end
  166. @#$#@#$#@
  167. GRAPHICS-WINDOW
  168. 475
  169. 10
  170. 980
  171. 536
  172. 16
  173. 16
  174. 15.0
  175. 1
  176. 10
  177. 1
  178. 1
  179. 1
  180. 0
  181. 1
  182. 1
  183. 1
  184. -16
  185. 16
  186. -16
  187. 16
  188. 0
  189. 0
  190. 1
  191. ticks
  192. BUTTON
  193. 66
  194. 100
  195. 161
  196. 133
  197. New Game
  198. setup
  199. NIL
  200. 1
  201. T
  202. OBSERVER
  203. NIL
  204. R
  205. NIL
  206. NIL
  207. BUTTON
  208. 313
  209. 99
  210. 407
  211. 132
  212. Play Game
  213. go
  214. T
  215. 1
  216. T
  217. OBSERVER
  218. NIL
  219. G
  220. NIL
  221. NIL
  222. BUTTON
  223. 193
  224. 174
  225. 289
  226. 207
  227. Accelerate
  228. player-accelerate
  229. NIL
  230. 1
  231. T
  232. OBSERVER
  233. NIL
  234. W
  235. NIL
  236. NIL
  237. BUTTON
  238. 143
  239. 236
  240. 206
  241. 269
  242. Left
  243. player-turn-left
  244. NIL
  245. 1
  246. T
  247. OBSERVER
  248. NIL
  249. A
  250. NIL
  251. NIL
  252. BUTTON
  253. 250
  254. 235
  255. 319
  256. 268
  257. Right
  258. player-turn-right
  259. NIL
  260. 1
  261. T
  262. OBSERVER
  263. NIL
  264. D
  265. NIL
  266. NIL
  267. MONITOR
  268. 310
  269. 381
  270. 410
  271. 426
  272. Player Speed
  273. player-speed
  274. 5
  275. 1
  276. 11
  277. BUTTON
  278. 81
  279. 401
  280. 144
  281. 434
  282. FIRE!
  283. player-fire
  284. NIL
  285. 1
  286. T
  287. OBSERVER
  288. NIL
  289. NIL
  290. NIL
  291. NIL
  292. MONITOR
  293. 281
  294. 443
  295. 412
  296. 488
  297. Player Acceleration
  298. [acceleration] of player
  299. 5
  300. 1
  301. 11
  302. BUTTON
  303. 185
  304. 294
  305. 295
  306. 327
  307. Decelerate
  308. player-decelerate
  309. NIL
  310. 1
  311. T
  312. OBSERVER
  313. NIL
  314. S
  315. NIL
  316. NIL
  317. @#$#@#$#@
  318. WHAT IS IT?
  319. -----------
  320. This section could give a general understanding of what the model is trying to show or explain.
  321. HOW IT WORKS
  322. ------------
  323. This section could explain what rules the agents use to create the overall behavior of the model.
  324. HOW TO USE IT
  325. -------------
  326. This section could explain how to use the model, including a description of each of the items in the interface tab.
  327. THINGS TO NOTICE
  328. ----------------
  329. This section could give some ideas of things for the user to notice while running the model.
  330. THINGS TO TRY
  331. -------------
  332. This section could give some ideas of things for the user to try to do (move sliders, switches, etc.) with the model.
  333. EXTENDING THE MODEL
  334. -------------------
  335. 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.
  336. NETLOGO FEATURES
  337. ----------------
  338. 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.
  339. RELATED MODELS
  340. --------------
  341. This section could give the names of models in the NetLogo Models Library or elsewhere which are of related interest.
  342. CREDITS AND REFERENCES
  343. ----------------------
  344. 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.
  345. @#$#@#$#@
  346. default
  347. true
  348. 0
  349. Polygon -7500403 true true 150 5 40 250 150 205 260 250
  350. airplane
  351. true
  352. 0
  353. Polygon -7500403 true true 150 0 135 15 120 60 120 105 15 165 15 195 120 180 135 240 105 270 120 285 150 270 180 285 210 270 165 240 180 180 285 195 285 165 180 105 180 60 165 15
  354. arrow
  355. true
  356. 0
  357. Polygon -7500403 true true 150 0 0 150 105 150 105 293 195 293 195 150 300 150
  358. box
  359. false
  360. 0
  361. Polygon -7500403 true true 150 285 285 225 285 75 150 135
  362. Polygon -7500403 true true 150 135 15 75 150 15 285 75
  363. Polygon -7500403 true true 15 75 15 225 150 285 150 135
  364. Line -16777216 false 150 285 150 135
  365. Line -16777216 false 150 135 15 75
  366. Line -16777216 false 150 135 285 75
  367. bug
  368. true
  369. 0
  370. Circle -7500403 true true 96 182 108
  371. Circle -7500403 true true 110 127 80
  372. Circle -7500403 true true 110 75 80
  373. Line -7500403 true 150 100 80 30
  374. Line -7500403 true 150 100 220 30
  375. butterfly
  376. true
  377. 0
  378. Polygon -7500403 true true 150 165 209 199 225 225 225 255 195 270 165 255 150 240
  379. Polygon -7500403 true true 150 165 89 198 75 225 75 255 105 270 135 255 150 240
  380. Polygon -7500403 true true 139 148 100 105 55 90 25 90 10 105 10 135 25 180 40 195 85 194 139 163
  381. Polygon -7500403 true true 162 150 200 105 245 90 275 90 290 105 290 135 275 180 260 195 215 195 162 165
  382. Polygon -16777216 true false 150 255 135 225 120 150 135 120 150 105 165 120 180 150 165 225
  383. Circle -16777216 true false 135 90 30
  384. Line -16777216 false 150 105 195 60
  385. Line -16777216 false 150 105 105 60
  386. car
  387. false
  388. 0
  389. Polygon -7500403 true true 300 180 279 164 261 144 240 135 226 132 213 106 203 84 185 63 159 50 135 50 75 60 0 150 0 165 0 225 300 225 300 180
  390. Circle -16777216 true false 180 180 90
  391. Circle -16777216 true false 30 180 90
  392. Polygon -16777216 true false 162 80 132 78 134 135 209 135 194 105 189 96 180 89
  393. Circle -7500403 true true 47 195 58
  394. Circle -7500403 true true 195 195 58
  395. circle
  396. false
  397. 0
  398. Circle -7500403 true true 0 0 300
  399. circle 2
  400. false
  401. 0
  402. Circle -7500403 true true 0 0 300
  403. Circle -16777216 true false 30 30 240
  404. cow
  405. false
  406. 0
  407. Polygon -7500403 true true 200 193 197 249 179 249 177 196 166 187 140 189 93 191 78 179 72 211 49 209 48 181 37 149 25 120 25 89 45 72 103 84 179 75 198 76 252 64 272 81 293 103 285 121 255 121 242 118 224 167
  408. Polygon -7500403 true true 73 210 86 251 62 249 48 208
  409. Polygon -7500403 true true 25 114 16 195 9 204 23 213 25 200 39 123
  410. cylinder
  411. false
  412. 0
  413. Circle -7500403 true true 0 0 300
  414. dot
  415. false
  416. 0
  417. Circle -7500403 true true 90 90 120
  418. face happy
  419. false
  420. 0
  421. Circle -7500403 true true 8 8 285
  422. Circle -16777216 true false 60 75 60
  423. Circle -16777216 true false 180 75 60
  424. Polygon -16777216 true false 150 255 90 239 62 213 47 191 67 179 90 203 109 218 150 225 192 218 210 203 227 181 251 194 236 217 212 240
  425. face neutral
  426. false
  427. 0
  428. Circle -7500403 true true 8 7 285
  429. Circle -16777216 true false 60 75 60
  430. Circle -16777216 true false 180 75 60
  431. Rectangle -16777216 true false 60 195 240 225
  432. face sad
  433. false
  434. 0
  435. Circle -7500403 true true 8 8 285
  436. Circle -16777216 true false 60 75 60
  437. Circle -16777216 true false 180 75 60
  438. Polygon -16777216 true false 150 168 90 184 62 210 47 232 67 244 90 220 109 205 150 198 192 205 210 220 227 242 251 229 236 206 212 183
  439. fish
  440. false
  441. 0
  442. Polygon -1 true false 44 131 21 87 15 86 0 120 15 150 0 180 13 214 20 212 45 166
  443. Polygon -1 true false 135 195 119 235 95 218 76 210 46 204 60 165
  444. Polygon -1 true false 75 45 83 77 71 103 86 114 166 78 135 60
  445. Polygon -7500403 true true 30 136 151 77 226 81 280 119 292 146 292 160 287 170 270 195 195 210 151 212 30 166
  446. Circle -16777216 true false 215 106 30
  447. flag
  448. false
  449. 0
  450. Rectangle -7500403 true true 60 15 75 300
  451. Polygon -7500403 true true 90 150 270 90 90 30
  452. Line -7500403 true 75 135 90 135
  453. Line -7500403 true 75 45 90 45
  454. flower
  455. false
  456. 0
  457. Polygon -10899396 true false 135 120 165 165 180 210 180 240 150 300 165 300 195 240 195 195 165 135
  458. Circle -7500403 true true 85 132 38
  459. Circle -7500403 true true 130 147 38
  460. Circle -7500403 true true 192 85 38
  461. Circle -7500403 true true 85 40 38
  462. Circle -7500403 true true 177 40 38
  463. Circle -7500403 true true 177 132 38
  464. Circle -7500403 true true 70 85 38
  465. Circle -7500403 true true 130 25 38
  466. Circle -7500403 true true 96 51 108
  467. Circle -16777216 true false 113 68 74
  468. Polygon -10899396 true false 189 233 219 188 249 173 279 188 234 218
  469. Polygon -10899396 true false 180 255 150 210 105 210 75 240 135 240
  470. house
  471. false
  472. 0
  473. Rectangle -7500403 true true 45 120 255 285
  474. Rectangle -16777216 true false 120 210 180 285
  475. Polygon -7500403 true true 15 120 150 15 285 120
  476. Line -16777216 false 30 120 270 120
  477. leaf
  478. false
  479. 0
  480. Polygon -7500403 true true 150 210 135 195 120 210 60 210 30 195 60 180 60 165 15 135 30 120 15 105 40 104 45 90 60 90 90 105 105 120 120 120 105 60 120 60 135 30 150 15 165 30 180 60 195 60 180 120 195 120 210 105 240 90 255 90 263 104 285 105 270 120 285 135 240 165 240 180 270 195 240 210 180 210 165 195
  481. Polygon -7500403 true true 135 195 135 240 120 255 105 255 105 285 135 285 165 240 165 195
  482. line
  483. true
  484. 0
  485. Line -7500403 true 150 0 150 300
  486. line half
  487. true
  488. 0
  489. Line -7500403 true 150 0 150 150
  490. pentagon
  491. false
  492. 0
  493. Polygon -7500403 true true 150 15 15 120 60 285 240 285 285 120
  494. person
  495. false
  496. 0
  497. Circle -7500403 true true 110 5 80
  498. Polygon -7500403 true true 105 90 120 195 90 285 105 300 135 300 150 225 165 300 195 300 210 285 180 195 195 90
  499. Rectangle -7500403 true true 127 79 172 94
  500. Polygon -7500403 true true 195 90 240 150 225 180 165 105
  501. Polygon -7500403 true true 105 90 60 150 75 180 135 105
  502. plant
  503. false
  504. 0
  505. Rectangle -7500403 true true 135 90 165 300
  506. Polygon -7500403 true true 135 255 90 210 45 195 75 255 135 285
  507. Polygon -7500403 true true 165 255 210 210 255 195 225 255 165 285
  508. Polygon -7500403 true true 135 180 90 135 45 120 75 180 135 210
  509. Polygon -7500403 true true 165 180 165 210 225 180 255 120 210 135
  510. Polygon -7500403 true true 135 105 90 60 45 45 75 105 135 135
  511. Polygon -7500403 true true 165 105 165 135 225 105 255 45 210 60
  512. Polygon -7500403 true true 135 90 120 45 150 15 180 45 165 90
  513. sheep
  514. false
  515. 0
  516. Rectangle -7500403 true true 151 225 180 285
  517. Rectangle -7500403 true true 47 225 75 285
  518. Rectangle -7500403 true true 15 75 210 225
  519. Circle -7500403 true true 135 75 150
  520. Circle -16777216 true false 165 76 116
  521. square
  522. false
  523. 0
  524. Rectangle -7500403 true true 30 30 270 270
  525. square 2
  526. false
  527. 0
  528. Rectangle -7500403 true true 30 30 270 270
  529. Rectangle -16777216 true false 60 60 240 240
  530. star
  531. false
  532. 0
  533. Polygon -7500403 true true 151 1 185 108 298 108 207 175 242 282 151 216 59 282 94 175 3 108 116 108
  534. target
  535. false
  536. 0
  537. Circle -7500403 true true 0 0 300
  538. Circle -16777216 true false 30 30 240
  539. Circle -7500403 true true 60 60 180
  540. Circle -16777216 true false 90 90 120
  541. Circle -7500403 true true 120 120 60
  542. tree
  543. false
  544. 0
  545. Circle -7500403 true true 118 3 94
  546. Rectangle -6459832 true false 120 195 180 300
  547. Circle -7500403 true true 65 21 108
  548. Circle -7500403 true true 116 41 127
  549. Circle -7500403 true true 45 90 120
  550. Circle -7500403 true true 104 74 152
  551. triangle
  552. false
  553. 0
  554. Polygon -7500403 true true 150 30 15 255 285 255
  555. triangle 2
  556. false
  557. 0
  558. Polygon -7500403 true true 150 30 15 255 285 255
  559. Polygon -16777216 true false 151 99 225 223 75 224
  560. truck
  561. false
  562. 0
  563. Rectangle -7500403 true true 4 45 195 187
  564. Polygon -7500403 true true 296 193 296 150 259 134 244 104 208 104 207 194
  565. Rectangle -1 true false 195 60 195 105
  566. Polygon -16777216 true false 238 112 252 141 219 141 218 112
  567. Circle -16777216 true false 234 174 42
  568. Rectangle -7500403 true true 181 185 214 194
  569. Circle -16777216 true false 144 174 42
  570. Circle -16777216 true false 24 174 42
  571. Circle -7500403 false true 24 174 42
  572. Circle -7500403 false true 144 174 42
  573. Circle -7500403 false true 234 174 42
  574. turtle
  575. true
  576. 0
  577. Polygon -10899396 true false 215 204 240 233 246 254 228 266 215 252 193 210
  578. Polygon -10899396 true false 195 90 225 75 245 75 260 89 269 108 261 124 240 105 225 105 210 105
  579. Polygon -10899396 true false 105 90 75 75 55 75 40 89 31 108 39 124 60 105 75 105 90 105
  580. Polygon -10899396 true false 132 85 134 64 107 51 108 17 150 2 192 18 192 52 169 65 172 87
  581. Polygon -10899396 true false 85 204 60 233 54 254 72 266 85 252 107 210
  582. Polygon -7500403 true true 119 75 179 75 209 101 224 135 220 225 175 261 128 261 81 224 74 135 88 99
  583. wheel
  584. false
  585. 0
  586. Circle -7500403 true true 3 3 294
  587. Circle -16777216 true false 30 30 240
  588. Line -7500403 true 150 285 150 15
  589. Line -7500403 true 15 150 285 150
  590. Circle -7500403 true true 120 120 60
  591. Line -7500403 true 216 40 79 269
  592. Line -7500403 true 40 84 269 221
  593. Line -7500403 true 40 216 269 79
  594. Line -7500403 true 84 40 221 269
  595. x
  596. false
  597. 0
  598. Polygon -7500403 true true 270 75 225 30 30 225 75 270
  599. Polygon -7500403 true true 30 75 75 30 270 225 225 270
  600. @#$#@#$#@
  601. NetLogo 4.1.3
  602. @#$#@#$#@
  603. @#$#@#$#@
  604. @#$#@#$#@
  605. @#$#@#$#@
  606. @#$#@#$#@
  607. default
  608. 0.0
  609. -0.2 0 1.0 0.0
  610. 0.0 1 1.0 0.0
  611. 0.2 0 1.0 0.0
  612. link direction
  613. true
  614. 0
  615. Line -7500403 true 150 150 90 180
  616. Line -7500403 true 150 150 210 180
  617. @#$#@#$#@
  618. 0
  619. @#$#@#$#@