From c89172ba94f3798ff51b43afee3ca9fa824002dc Mon Sep 17 00:00:00 2001 From: Oreolek Date: Fri, 11 Dec 2015 15:37:58 +0700 Subject: [PATCH] WIP: volume slider --- game/begin.coffee | 8 +++++- game/end.coffee | 21 +++++++++++++-- game/gameplay.coffee | 8 +++--- html/index.html | 15 ++++++++--- img/background.jpg | Bin 0 -> 1016112 bytes img/bg-track.png | Bin 0 -> 1127 bytes img/clip0.png | Bin 7842 -> 3665 bytes img/clip1.png | Bin 8563 -> 4564 bytes img/clip2.png | Bin 9015 -> 4904 bytes img/clip3.png | Bin 9384 -> 5214 bytes img/clip4.png | Bin 9663 -> 5351 bytes img/clip5.png | Bin 9938 -> 5571 bytes img/clip6.png | Bin 10290 -> 5804 bytes img/handle.png | Bin 0 -> 1167 bytes img/volume.png | Bin 0 -> 603 bytes less/layout.less | 44 +++++++++++++++++++------------- less/main.less | 3 ++- less/slider.less | 59 +++++++++++++++++++++++++++++++++++++++++++ package.json | 1 + 19 files changed, 130 insertions(+), 29 deletions(-) create mode 100644 img/background.jpg create mode 100644 img/bg-track.png create mode 100644 img/handle.png create mode 100644 img/volume.png create mode 100644 less/slider.less diff --git a/game/begin.coffee b/game/begin.coffee index d08c1b0..28f8833 100644 --- a/game/begin.coffee +++ b/game/begin.coffee @@ -12,6 +12,8 @@ undum.language["ru"] = undumloc undumloc = require("./translations/en.coffee").language undum.language["en"] = undumloc $ = require("jquery") +require('jquery-ui/slider'); + Array.prototype.oneOf = () -> oneOf.apply(null, this) md = require('markdown-it') @@ -21,7 +23,7 @@ markdown = new md({ }) undum.game.id = "7a1aba32-f0fd-4e3b-ba5a-59e3fa9e6012" -undum.game.version = "3.2" +undum.game.version = "3.3" a = require('raconteur/lib/elements.js').a way_to = (content, ref) -> a(content).class('way').ref(ref) @@ -46,3 +48,7 @@ is_visited = (situation) -> if situations return Boolean situations.visited return 0 + +# Volume from 0 to 1 +get_volume = () -> + return $('#slider').slider('value') / 100 diff --git a/game/end.coffee b/game/end.coffee index 288baec..a3dae88 100644 --- a/game/end.coffee +++ b/game/end.coffee @@ -11,8 +11,6 @@ undum.game.init = (character, system) -> system.setQuality("enemies", 25) system.setQuality("clips", Math.floor(character.qualities.enemies / 6)) character.sandbox.search_clip_threshold = character.qualities.clips - 2 - # Sound volume multiplicator. 0 means the game is muted. - character.sandbox.volume = 1 character.sandbox.clips = [] for i in [1 .. character.qualities.clips] character.sandbox.clips.push(6) @@ -30,6 +28,25 @@ undum.game.init = (character, system) -> character.sandbox.steps_volume = 0 $("#title").click(() -> $("#clip").fadeIn() + $(".volume").fadeIn() + slider = $('#slider') + + slider.slider({ + range: "min", + min: 1, + value: 100, + slide: (event, ui) -> + value = slider.slider('value') + volume = $('.voldisplay') + if value <= 5 + volume.css('background-position', '0 0') + else if value <= 25 + volume.css('background-position', '0 -25px') + else if value <= 75 + volume.css('background-position', '0 -50px') + else + volume.css('background-position', '0 -75px') + }) ) setInterval( () -> play_steps(character) diff --git a/game/gameplay.coffee b/game/gameplay.coffee index 4fd0831..e47a3e8 100644 --- a/game/gameplay.coffee +++ b/game/gameplay.coffee @@ -20,7 +20,7 @@ scripted_events = (character, system) -> if character.qualities.enemies == 1 audio = document.getElementById("roar") audio.currentTime=0 - audio.volume = 1 * character.sandbox.volume + audio.volume = 1 * get_volume() audio.play() writemd(system, "boss".l()) if character.qualities.enemies == 0 @@ -37,7 +37,7 @@ play_steps = (character) -> audio = 'step2' audio = document.getElementById(audio) audio.currentTime=0 - audio.volume = character.sandbox.steps_volume * character.sandbox.volume + audio.volume = character.sandbox.steps_volume * get_volume() audio.play() kill_enemy = (character, system) -> @@ -58,7 +58,7 @@ spend_bullet = (character, system) -> audio = 'shot2' audio = document.getElementById(audio) audio.currentTime=0 - audio.volume = 1 * character.sandbox.volume + audio.volume = 1 * get_volume() audio.play() character.sandbox.clips[character.sandbox.current_clip]-- bullets-- @@ -73,7 +73,7 @@ spend_clip = (character, system) -> return audio = document.getElementById("reload") audio.currentTime=0 - audio.volume = 1 * character.sandbox.volume + audio.volume = 1 * get_volume() audio.play() if bullets == 0 character.sandbox.clips.splice(character.sandbox.current_clip, 1) diff --git a/html/index.html b/html/index.html index 3c594eb..7e13d8a 100644 --- a/html/index.html +++ b/html/index.html @@ -5,6 +5,7 @@ Пули говорят быстрее +
@@ -20,8 +21,15 @@

нажмите, чтобы начать

-
-

+
+
+

+
+ +
+
+ +
@@ -77,9 +85,10 @@