|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148 |
- ;; lobo: Logo Bolo
- ;; (c) Ben Kurtovic, 2011
-
- globals [
- tank-max-ammo
- tank-max-armor
- ]
-
- breed [tanks tank]
-
- tanks-own [
- acceleration
- ammunition
- armor
- fire-cool-down
- friction
- is-accelerating?
- is-player?
- max-fire-rate
- max-speed
- max-turn
- speed
- team
- ]
-
- ;; ==========
- ;; Procedures
- ;; ==========
-
- to spawn-tank [tank-team tank-xcor tank-ycor tank-heading]
- create-tanks 1 [
- set-tank-vars false tank-team tank-xcor tank-ycor tank-heading
- ]
- end
-
- to set-tank-vars [player? tteam txcor tycor theading]
- set acceleration 0.03
- set ammunition tank-max-ammo
- set armor tank-max-armor
- set fire-cool-down 0
- set friction 0.0075
- set is-accelerating? false
- set is-player? player?
- set max-fire-rate 7
- set max-speed 0.25
- set max-turn 24
- set speed 0
- set team tteam
-
- set color get-tank-color
- set heading theading
- set shape "tank"
- set size 1.5
- setxy txcor tycor
- end
-
- to do-tank-logic
- if is-accelerating? [
- accelerate acceleration
- ]
- fd speed
- decelerate friction
- if fire-cool-down > 0 [
- set fire-cool-down fire-cool-down - 1
- ]
- end
-
- to accelerate [amount]
- set speed speed + amount
- if speed > max-speed [
- set speed max-speed
- ]
- end
-
- to decelerate [amount]
- set speed speed - amount
- if speed < 0 [
- set speed 0
- ]
- 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
- if fire-cool-down = 0 [
- ifelse ammunition > 0 [
- debug "FIRE" (word who " (" ammunition " left)")
- set ammunition ammunition - 1
- fire-bullet
- play-sound "fire"
- ] [
- play-sound "noammo"
- ]
- set fire-cool-down max-fire-rate
- ]
- end
-
- to tank-shot-at
- debug "SHOT" (word who " by " ([shooter] of myself))
- set armor armor - 1
- ifelse armor = 0 [
- explode "kill"
- play-sound "kill"
- kill-tank
- ] [
- explode "shot"
- play-sound "shot"
- ]
- end
-
- to kill-tank
- debug "KILL" (word who " by " ([shooter] of myself))
- if is-player? [
- set player-deaths player-deaths + 1
- ]
- if [is-player?] of (turtle [shooter] of myself) [
- set player-kills player-kills + 1
- ]
- die
- end
-
- ;; =========
- ;; Reporters
- ;; =========
-
- to-report get-tank-affiliation
- if is-player? [ report "player" ]
- if team = 0 [ report "ally" ]
- report "enemy"
- end
-
- to-report get-tank-color
- let affiliation get-tank-affiliation
- if affiliation = "player" [ report black ]
- if affiliation = "ally" [ report green ]
- if affiliation = "enemy" [ report red ]
- end
|