| @@ -21,7 +21,8 @@ to fire-bullet | |||||
| set shape "bullet" | set shape "bullet" | ||||
| set size 0.5 | set size 0.5 | ||||
| lt random 10 ; Bullets shouldn't travel perfectly straight | |||||
| ; Bullets shouldn't travel perfectly straight: | |||||
| lt random 10 | |||||
| rt random 10 | rt random 10 | ||||
| ] | ] | ||||
| end | end | ||||
| @@ -20,9 +20,11 @@ globals [ | |||||
| max-fps | max-fps | ||||
| mouse-was-down? | mouse-was-down? | ||||
| player | player | ||||
| player-accelerate-for | |||||
| player-deaths | player-deaths | ||||
| player-has-target? | |||||
| player-kills | player-kills | ||||
| player-target-xcor | |||||
| player-target-ycor | |||||
| sounds | sounds | ||||
| ] | ] | ||||
| @@ -38,8 +40,8 @@ to setup | |||||
| set pcolor (random 3) - 5 + green | set pcolor (random 3) - 5 + green | ||||
| ] | ] | ||||
| spawn-player | spawn-player | ||||
| spawn-tank 0 ask tank 1 [ setxy -10 0 ] | |||||
| spawn-tank 1 ask tank 2 [ setxy 10 0 ] | |||||
| spawn-tank 0 ask tank 1 [ setxy -6 0 ] | |||||
| spawn-tank 1 ask tank 2 [ setxy 6 0 ] | |||||
| render | render | ||||
| set last-tick-time timer | set last-tick-time timer | ||||
| end | end | ||||
| @@ -74,9 +76,11 @@ to setup-defaults | |||||
| resize-world -8 8 -8 8 | resize-world -8 8 -8 8 | ||||
| set max-fps 30 | set max-fps 30 | ||||
| set mouse-was-down? false | set mouse-was-down? false | ||||
| set player-accelerate-for 0 | |||||
| set player-deaths 0 | set player-deaths 0 | ||||
| set player-has-target? false | |||||
| set player-kills 0 | set player-kills 0 | ||||
| set player-target-xcor 0 | |||||
| set player-target-ycor 0 | |||||
| make-sounds-table | make-sounds-table | ||||
| end | end | ||||
| @@ -95,27 +99,33 @@ to show-crosshair | |||||
| clear-drawing | clear-drawing | ||||
| if mouse-inside? [ | if mouse-inside? [ | ||||
| ask patch mouse-xcor mouse-ycor [ | ask patch mouse-xcor mouse-ycor [ | ||||
| sprout 1 [ | |||||
| set color white | |||||
| set heading 0 | |||||
| make-square | |||||
| die | |||||
| ] | |||||
| draw-border white 1 | |||||
| ] | |||||
| ] | |||||
| if player-has-target? [ | |||||
| ask patch player-target-xcor player-target-ycor [ | |||||
| draw-border white 2 | |||||
| ] | ] | ||||
| ] | ] | ||||
| end | end | ||||
| to make-square | |||||
| fd 0.5 | |||||
| pd | |||||
| rt 90 | |||||
| fd 0.5 | |||||
| repeat 3 [ | |||||
| to draw-border [b-color b-thickness] | |||||
| sprout 1 [ | |||||
| set color b-color | |||||
| set pen-size b-thickness | |||||
| set heading 0 | |||||
| fd 0.5 | |||||
| pd | |||||
| rt 90 | rt 90 | ||||
| fd 1 | |||||
| fd 0.5 | |||||
| repeat 3 [ | |||||
| rt 90 | |||||
| fd 1 | |||||
| ] | |||||
| rt 90 | |||||
| fd 0.5 | |||||
| die | |||||
| ] | ] | ||||
| rt 90 | |||||
| fd 0.5 | |||||
| end | end | ||||
| to render | to render | ||||
| @@ -165,7 +175,7 @@ GRAPHICS-WINDOW | |||||
| 0 | 0 | ||||
| 0 | 0 | ||||
| 1 | 1 | ||||
| ticks | |||||
| frames | |||||
| BUTTON | BUTTON | ||||
| 43 | 43 | ||||
| @@ -231,8 +241,8 @@ MONITOR | |||||
| 350 | 350 | ||||
| 389 | 389 | ||||
| 399 | 399 | ||||
| Player Accel Time | |||||
| player-accelerate-for | |||||
| Player Has Target? | |||||
| player-has-target? | |||||
| 5 | 5 | ||||
| 1 | 1 | ||||
| 12 | 12 | ||||
| @@ -299,6 +309,17 @@ enable-sound? | |||||
| 1 | 1 | ||||
| -1000 | -1000 | ||||
| MONITOR | |||||
| 272 | |||||
| 411 | |||||
| 390 | |||||
| 460 | |||||
| Player Target | |||||
| word \"(\" player-target-xcor \", \" player-target-ycor \")\" | |||||
| 10 | |||||
| 1 | |||||
| 12 | |||||
| @#$#@#$#@ | @#$#@#$#@ | ||||
| WHAT IS IT? | WHAT IS IT? | ||||
| ----------- | ----------- | ||||
| @@ -17,41 +17,25 @@ end | |||||
| to do-player-logic | to do-player-logic | ||||
| if mouse-inside? [ | if mouse-inside? [ | ||||
| if mouse-down? and not mouse-was-down? [ | if mouse-down? and not mouse-was-down? [ | ||||
| set player-accelerate-for player-accelerate-for + 10 | |||||
| if player-accelerate-for > 60 [ | |||||
| set player-accelerate-for 60 | |||||
| ] | |||||
| set is-accelerating? true | |||||
| set player-has-target? true | |||||
| set player-target-xcor (round mouse-xcor) | |||||
| set player-target-ycor (round mouse-ycor) | |||||
| ] | ] | ||||
| set mouse-was-down? mouse-down? | set mouse-was-down? mouse-down? | ||||
| let old-heading heading | |||||
| ; Slow down the tank a bit more than usual if we're | |||||
| ; very close to the mouse: | |||||
| let mouse-dist distancexy mouse-xcor mouse-ycor | |||||
| if mouse-dist < 3 [ | |||||
| decelerate friction | |||||
| ] | |||||
| if mouse-dist < 1.5 [ | |||||
| decelerate friction * 6.5 | |||||
| ] | |||||
| if mouse-dist < 0.35 [ | |||||
| set speed 0 | |||||
| set player-accelerate-for 0 | |||||
| ] | |||||
| facexy mouse-xcor mouse-ycor | |||||
| if subtract-headings old-heading heading > max-turn [ | |||||
| set heading old-heading - max-turn | |||||
| ] | |||||
| ifelse player-has-target? [ | |||||
| tank-facexy player-target-xcor player-target-ycor | |||||
| let dist distancexy player-target-xcor player-target-ycor | |||||
| if dist < 2 and speed > 0.075 [ | |||||
| decelerate friction * 5 | |||||
| ] | ] | ||||
| if subtract-headings old-heading heading < 0 - max-turn [ | |||||
| set heading old-heading + max-turn | |||||
| if dist < 0.1 [ | |||||
| set is-accelerating? false | |||||
| set player-has-target? false | |||||
| ] | ] | ||||
| ] | |||||
| ifelse player-accelerate-for > 0 [ | |||||
| set player-accelerate-for player-accelerate-for - 1 | |||||
| set is-accelerating? true | |||||
| ] [ | ] [ | ||||
| set is-accelerating? false | |||||
| tank-facexy mouse-xcor mouse-ycor | |||||
| ] | ] | ||||
| end | end | ||||
| @@ -69,6 +69,19 @@ to decelerate [amount] | |||||
| ] | ] | ||||
| end | end | ||||
| to tank-facexy [txcor tycor] | |||||
| ;; Face a target at (txcor, tycor) like facexy, but don't | |||||
| ;; turn more than our max turn rate (max-turn¡): | |||||
| let old-heading heading | |||||
| facexy txcor tycor | |||||
| if subtract-headings old-heading heading > max-turn [ | |||||
| set heading old-heading - max-turn | |||||
| ] | |||||
| if subtract-headings old-heading heading < 0 - max-turn [ | |||||
| set heading old-heading + max-turn | |||||
| ] | |||||
| end | |||||
| to fire | to fire | ||||
| if ammunition > 0 and fire-cool-down = 0 [ | if ammunition > 0 and fire-cool-down = 0 [ | ||||
| debug "FIRE" (word who " (" ammunition " left)") | debug "FIRE" (word who " (" ammunition " left)") | ||||