@@ -14,6 +14,11 @@ __includes [ | |||||
"tank.nls" | "tank.nls" | ||||
] | ] | ||||
extensions [ | |||||
sound | |||||
table | |||||
] | |||||
globals [ | globals [ | ||||
last-tick-time | last-tick-time | ||||
max-fps | max-fps | ||||
@@ -22,6 +27,7 @@ globals [ | |||||
player-accelerate-for | player-accelerate-for | ||||
player-deaths | player-deaths | ||||
player-kills | player-kills | ||||
sounds | |||||
] | ] | ||||
;; =========================== | ;; =========================== | ||||
@@ -36,7 +42,8 @@ to setup | |||||
set pcolor (random 3) - 5 + green | set pcolor (random 3) - 5 + green | ||||
] | ] | ||||
spawn-player | spawn-player | ||||
spawn-tank 1 | |||||
spawn-tank 0 ask tank 1 [ setxy -10 0 ] | |||||
spawn-tank 1 ask tank 2 [ setxy 10 0 ] | |||||
render | render | ||||
set last-tick-time timer | set last-tick-time timer | ||||
end | end | ||||
@@ -61,6 +68,8 @@ end | |||||
;; ================ | ;; ================ | ||||
to debug [action msg] | to debug [action msg] | ||||
; Comment this and remove the output box | |||||
; to turn off debugging info: | |||||
output-print (word (round timer) ": " action ": " msg) | output-print (word (round timer) ": " action ": " msg) | ||||
end | end | ||||
@@ -72,6 +81,20 @@ to setup-defaults | |||||
set player-accelerate-for 0 | set player-accelerate-for 0 | ||||
set player-deaths 0 | set player-deaths 0 | ||||
set player-kills 0 | set player-kills 0 | ||||
make-sounds-table | |||||
end | |||||
to make-sounds-table | |||||
set sounds table:make | |||||
table:put sounds "fire player" "Hand Clap" | |||||
table:put sounds "fire ally" "Hand Clap" | |||||
table:put sounds "fire enemy" "Hand Clap" | |||||
table:put sounds "shot player" "Acoustic Snare" | |||||
table:put sounds "shot ally" "Acoustic Snare" | |||||
table:put sounds "shot enemy" "Acoustic Snare" | |||||
table:put sounds "kill player" "Electric Snare" | |||||
table:put sounds "kill ally" "Electric Snare" | |||||
table:put sounds "kill enemy" "Electric Snare" | |||||
end | end | ||||
to show-crosshair | to show-crosshair | ||||
@@ -113,6 +136,17 @@ to keep-time | |||||
tick | tick | ||||
set last-tick-time timer | set last-tick-time timer | ||||
end | end | ||||
to play-sound [name] | |||||
if enable-sound? [ | |||||
let sname (word name " " get-tank-affiliation) | |||||
let dist distancexy ([xcor] of player) ([ycor] of player) | |||||
let volume 127 - (dist * 4) | |||||
if volume > 0 [ | |||||
sound:play-drum (table:get sounds sname) volume | |||||
] | |||||
] | |||||
end | |||||
@#$#@#$#@ | @#$#@#$#@ | ||||
GRAPHICS-WINDOW | GRAPHICS-WINDOW | ||||
452 | 452 | ||||
@@ -184,10 +218,10 @@ Player Speed | |||||
12 | 12 | ||||
BUTTON | BUTTON | ||||
148 | |||||
181 | |||||
269 | |||||
233 | |||||
109 | |||||
172 | |||||
230 | |||||
224 | |||||
FIRE! | FIRE! | ||||
player-fire | player-fire | ||||
NIL | NIL | ||||
@@ -261,6 +295,17 @@ Player Armor | |||||
1 | 1 | ||||
12 | 12 | ||||
SWITCH | |||||
264 | |||||
179 | |||||
394 | |||||
212 | |||||
enable-sound? | |||||
enable-sound? | |||||
0 | |||||
1 | |||||
-1000 | |||||
@#$#@#$#@ | @#$#@#$#@ | ||||
WHAT IS IT? | WHAT IS IT? | ||||
----------- | ----------- | ||||
@@ -7,9 +7,11 @@ tanks-own [ | |||||
acceleration | acceleration | ||||
ammunition | ammunition | ||||
armor | armor | ||||
fire-cool-down | |||||
friction | friction | ||||
is-accelerating? | is-accelerating? | ||||
is-player? | is-player? | ||||
max-fire-rate | |||||
max-speed | max-speed | ||||
max-turn | max-turn | ||||
speed | speed | ||||
@@ -26,9 +28,11 @@ to set-tank-vars [tank-team player-tank?] | |||||
set acceleration 0.03 | set acceleration 0.03 | ||||
set ammunition 20 | set ammunition 20 | ||||
set armor 8 | set armor 8 | ||||
set fire-cool-down 0 | |||||
set friction 0.0075 | set friction 0.0075 | ||||
set is-accelerating? false | set is-accelerating? false | ||||
set is-player? player-tank? | set is-player? player-tank? | ||||
set max-fire-rate 7 | |||||
set max-speed 0.25 | set max-speed 0.25 | ||||
set max-turn 24 | set max-turn 24 | ||||
set speed 0 | set speed 0 | ||||
@@ -46,6 +50,9 @@ to do-tank-logic | |||||
] | ] | ||||
fd speed | fd speed | ||||
decelerate friction | decelerate friction | ||||
if fire-cool-down > 0 [ | |||||
set fire-cool-down fire-cool-down - 1 | |||||
] | |||||
end | end | ||||
to accelerate [amount] | to accelerate [amount] | ||||
@@ -63,8 +70,11 @@ to decelerate [amount] | |||||
end | end | ||||
to fire | to fire | ||||
if ammunition > 0 [ | |||||
if ammunition > 0 and fire-cool-down = 0 [ | |||||
debug "FIRE" (word who " (" ammunition " left)") | |||||
set ammunition ammunition - 1 | set ammunition ammunition - 1 | ||||
set fire-cool-down max-fire-rate | |||||
hatch-bullets 1 [ | hatch-bullets 1 [ | ||||
set max-travel-distance 8 | set max-travel-distance 8 | ||||
set shooter [who] of myself | set shooter [who] of myself | ||||
@@ -74,20 +84,35 @@ to fire | |||||
set color white | set color white | ||||
set shape "bullet" | set shape "bullet" | ||||
set size 0.5 | set size 0.5 | ||||
lt random 10 ; Bullets shouldn't travel perfectly straight | |||||
rt random 10 | |||||
] | ] | ||||
play-sound "fire" | |||||
] | ] | ||||
end | end | ||||
to shot-at [bullet] | to shot-at [bullet] | ||||
debug "SHOT" (word ([shooter] of myself) " -> " who) | |||||
debug "SHOT" (word who " by " ([shooter] of myself)) | |||||
set armor armor - 1 | set armor armor - 1 | ||||
if armor = 0 [ | |||||
ifelse armor = 0 [ | |||||
debug "KILL" (word who " by " ([shooter] of myself)) | |||||
play-sound "kill" | |||||
die | die | ||||
] [ | |||||
play-sound "shot" | |||||
] | ] | ||||
end | end | ||||
to-report get-tank-affiliation | |||||
if is-player? [ report "player" ] | |||||
if team = 0 [ report "ally" ] | |||||
report "enemy" | |||||
end | |||||
to-report get-tank-color | to-report get-tank-color | ||||
if is-player? [ report black ] | |||||
if team = 0 [ report green ] | |||||
report red | |||||
let affiliation get-tank-affiliation | |||||
if affiliation = "player" [ report black ] | |||||
if affiliation = "ally" [ report green ] | |||||
if affiliation = "enemy" [ report red ] | |||||
end | end |