Logo Bolo: a re-envisioning of the classic tank game by Stuart Cheshire in NetLogo
Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

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