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.

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