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.

player.nls 1.7 KiB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. ;; lobo: Logo Bolo
  2. ;; (c) Ben Kurtovic, 2011-2012
  3. globals [
  4. player
  5. player-deaths
  6. player-has-target?
  7. player-kills
  8. player-target-xcor
  9. player-target-ycor
  10. ]
  11. ;; ==========
  12. ;; Procedures
  13. ;; ==========
  14. to spawn-player [tank-heading]
  15. sprout-tanks 1 [
  16. set player tank who
  17. set-tank-vars true 0 tank-heading
  18. ]
  19. end
  20. to do-player-logic
  21. if player != nobody [
  22. ask player [
  23. do-player-movement
  24. ]
  25. ]
  26. end
  27. to do-player-movement
  28. if mouse-inside? [
  29. if mouse-down? and not mouse-was-down? [
  30. let txcor round mouse-xcor
  31. let tycor round mouse-ycor
  32. ifelse player-has-target? and player-target-xcor = txcor and player-target-ycor = tycor [
  33. cancel-target
  34. ] [
  35. set is-accelerating? true
  36. set player-has-target? true
  37. set player-target-xcor txcor
  38. set player-target-ycor tycor
  39. ]
  40. ]
  41. set mouse-was-down? mouse-down?
  42. ]
  43. ifelse player-has-target? [
  44. tank-facexy player-target-xcor player-target-ycor
  45. let dist distancexy player-target-xcor player-target-ycor
  46. if dist < 2 and speed > 0.075 [
  47. ; Turn on "brakes" if we're getting
  48. ; close and we're moving fast:
  49. decelerate friction * 5
  50. ]
  51. if dist < 0.1 [
  52. cancel-target
  53. ]
  54. ] [
  55. tank-facexy mouse-xcor mouse-ycor
  56. ]
  57. end
  58. to player-fire
  59. if player != nobody [
  60. ask player [
  61. fire
  62. ]
  63. ]
  64. end
  65. to player-place-pill
  66. if player != nobody [
  67. ask player [
  68. place-pill
  69. ]
  70. ]
  71. end
  72. to player-cancel-order
  73. if player != nobody [
  74. ask player [
  75. if player-has-target? [
  76. cancel-target
  77. ]
  78. ]
  79. ]
  80. end
  81. to cancel-target
  82. set is-accelerating? false
  83. set player-has-target? false
  84. set speed speed / 2
  85. end