From 7205c7b7aa610c407f2f05a41a38bc9a52c58abd Mon Sep 17 00:00:00 2001 From: Ben Kurtovic Date: Sun, 25 Dec 2011 00:35:55 -0500 Subject: [PATCH] Sounds and tank fire rate --- lobo.nlogo | 55 ++++++++++++++++++++++++++++++++++++++++++++++++++----- tank.nls | 37 +++++++++++++++++++++++++++++++------ 2 files changed, 81 insertions(+), 11 deletions(-) diff --git a/lobo.nlogo b/lobo.nlogo index 6746fb5..75b46ca 100644 --- a/lobo.nlogo +++ b/lobo.nlogo @@ -14,6 +14,11 @@ __includes [ "tank.nls" ] +extensions [ + sound + table +] + globals [ last-tick-time max-fps @@ -22,6 +27,7 @@ globals [ player-accelerate-for player-deaths player-kills + sounds ] ;; =========================== @@ -36,7 +42,8 @@ to setup set pcolor (random 3) - 5 + green ] spawn-player - spawn-tank 1 + spawn-tank 0 ask tank 1 [ setxy -10 0 ] + spawn-tank 1 ask tank 2 [ setxy 10 0 ] render set last-tick-time timer end @@ -61,6 +68,8 @@ end ;; ================ to debug [action msg] + ; Comment this and remove the output box + ; to turn off debugging info: output-print (word (round timer) ": " action ": " msg) end @@ -72,6 +81,20 @@ to setup-defaults set player-accelerate-for 0 set player-deaths 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 to show-crosshair @@ -113,6 +136,17 @@ to keep-time tick set last-tick-time timer 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 452 @@ -184,10 +218,10 @@ Player Speed 12 BUTTON -148 -181 -269 -233 +109 +172 +230 +224 FIRE! player-fire NIL @@ -261,6 +295,17 @@ Player Armor 1 12 +SWITCH +264 +179 +394 +212 +enable-sound? +enable-sound? +0 +1 +-1000 + @#$#@#$#@ WHAT IS IT? ----------- diff --git a/tank.nls b/tank.nls index ecd8792..5968ff0 100644 --- a/tank.nls +++ b/tank.nls @@ -7,9 +7,11 @@ tanks-own [ acceleration ammunition armor + fire-cool-down friction is-accelerating? is-player? + max-fire-rate max-speed max-turn speed @@ -26,9 +28,11 @@ to set-tank-vars [tank-team player-tank?] set acceleration 0.03 set ammunition 20 set armor 8 + set fire-cool-down 0 set friction 0.0075 set is-accelerating? false set is-player? player-tank? + set max-fire-rate 7 set max-speed 0.25 set max-turn 24 set speed 0 @@ -46,6 +50,9 @@ to do-tank-logic ] fd speed decelerate friction + if fire-cool-down > 0 [ + set fire-cool-down fire-cool-down - 1 + ] end to accelerate [amount] @@ -63,8 +70,11 @@ to decelerate [amount] end to fire - if ammunition > 0 [ + if ammunition > 0 and fire-cool-down = 0 [ + debug "FIRE" (word who " (" ammunition " left)") set ammunition ammunition - 1 + set fire-cool-down max-fire-rate + hatch-bullets 1 [ set max-travel-distance 8 set shooter [who] of myself @@ -74,20 +84,35 @@ to fire set color white set shape "bullet" set size 0.5 + + lt random 10 ; Bullets shouldn't travel perfectly straight + rt random 10 ] + play-sound "fire" ] end to shot-at [bullet] - debug "SHOT" (word ([shooter] of myself) " -> " who) + debug "SHOT" (word who " by " ([shooter] of myself)) set armor armor - 1 - if armor = 0 [ + ifelse armor = 0 [ + debug "KILL" (word who " by " ([shooter] of myself)) + play-sound "kill" die + ] [ + play-sound "shot" ] end +to-report get-tank-affiliation + if is-player? [ report "player" ] + if team = 0 [ report "ally" ] + report "enemy" +end + 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