From bdf1e844e3098ccf7e1abc2471e4e182120de6e0 Mon Sep 17 00:00:00 2001 From: "Valeriano A.R" Date: Tue, 8 Dec 2015 21:07:50 +0100 Subject: [PATCH] Limit sound repetition per process frame. --- code/CandyFucker.js | 4 +++- code/GameLib.js | 23 +++++++++++++++++++++-- 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/code/CandyFucker.js b/code/CandyFucker.js index 0da9648..52f17c4 100644 --- a/code/CandyFucker.js +++ b/code/CandyFucker.js @@ -453,7 +453,8 @@ CandyFucker.prototype = { [ { Name: "Explosion", - Url: "sfx/explosion1.wav" + Url: "sfx/explosion1.wav", + Limit: 1 }, { Name: "PickCandy", @@ -475,6 +476,7 @@ CandyFucker.prototype = { this.UpdateInfoDisplay(); }, Proc: function () { + window.Sounds.ResetCounters(); if (this.Locked) { if (this.Falling) { if (!this.Board.CandyFall()) { diff --git a/code/GameLib.js b/code/GameLib.js index e1e2181..34eb05e 100644 --- a/code/GameLib.js +++ b/code/GameLib.js @@ -442,6 +442,7 @@ ImageLoader.prototype = { // var SoundLoader = function () { this.Sounds = {}; + this.Limits = {}; }; SoundLoader.prototype = { LoadSounds: function (soundsList, funcOnLoad) { @@ -450,11 +451,16 @@ SoundLoader.prototype = { var soundName; - var i, - n; + var i, n; for (i = 0, n = soundsList.length; i < n; i++) { soundName = soundsList[i].Name; this.Sounds[soundName] = new Audio(); + if (soundsList[i].Limit) { + this.Limits[soundName] = { + Max: soundsList[i].Limit, + Count: 0 + }; + } } var self = this; @@ -488,10 +494,23 @@ SoundLoader.prototype = { privateOnLoad(); }, PlaySound: function (name) { + if (this.Limits[name]) { + if (this.Limits[name].Max <= this.Limits[name].Count){ + return; + } + this.Limits[name].Count++; + } var sndOrig = this.Sounds[name]; var sndCopy = sndOrig.cloneNode(); sndCopy.play(); }, + ResetCounters: function () { + for (var name in this.Limits) { + if (this.Limits.hasOwnProperty(name)) { + this.Limits[name].Count = 0; + } + } + }, Debug: false };