1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 | <!DOCTYPE html> <html> <head> <title>Snail Bait</title> <link rel='stylesheet' href='game.css'/> </head> <body> <audioid='soundtrack'> <source src='sounds/soundtrack.mp3' type='audio/mp3'> <source src='sounds/soundtrack.ogg' type='audio/ogg'> </audio> <audioid='plop-sound' > <source src='sounds/plop.mp3' type='audio/mp3'> <source src='sounds/plop.ogg' type='audio/ogg'> </audio> <audioid='chimes-sound' > <source src='sounds/chimes.mp3' type='audio/mp3'> <source src='sounds/chimes.ogg' type='audio/ogg'> </audio> <audioid='whistle-down-sound' > <source src='sounds/whistledown.mp3' type='audio/mp3'> <source src='sounds/whistledown.ogg' type='audio/ogg'> </audio> <audioid='thud-sound' > <source src='sounds/thud.mp3' type='audio/mp3'> <source src='sounds/thud.ogg' type='audio/ogg'> </audio> <audioid='jump-sound' > <source src='sounds/jump.mp3' type='audio/mp3'> <source src='sounds/jump.ogg' type='audio/ogg'> </audio> <audioid='coin-sound' > <source src='sounds/coin.mp3' type='audio/mp3'> <source src='sounds/coin.ogg' type='audio/ogg'> </audio> <audioid='explosion-sound' > <source src='sounds/explosion.mp3' type='audio/mp3'> <source src='sounds/explosion.ogg' type='audio/ogg'> </audio> ... </body> </html> |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | SnailBait = function () { ... this.coinSound = document.getElementById('coin-sound'), this.chimesSound = document.getElementById('chimes-sound'), this.explosionSound = document.getElementById('explosion-sound'), this.fallingWhistleSound = document.getElementById('whistle-down-sound'), this.plopSound = document.getElementById('plop-sound'), this.jumpWhistleSound = document.getElementById('jump-sound'), this.soundtrack = document.getElementById('soundtrack'), this.thudSound = document.getElementById('thud-sound'), ... }; |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | SnailBait = function () { // Sound-related constants this.COIN_VOLUME = 1.0, this.CHIMES_VOLUME = 1.0, this.EXPLOSION_VOLUME = 0.25, this.FALLING_WHISTLE_VOLUME = 0.10, this.JUMP_WHISTLE_VOLUME = 0.05, this.PLOP_VOLUME = 0.20, this.SOUNDTRACK_VOLUME = 0.12, this.THUD_VOLUME = 0.20, ... }; |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | SnailBait.prototype = { ... initializeSounds: function () { this.coinSound.volume = this.COIN_VOLUME; this.chimesSound.volume = this.CHIMES_VOLUME; this.explosionSound.volume = this.EXPLOSION_VOLUME; this.fallingWhistleSound.volume= this.FALLING_WHISTLE_VOLUME; this.plopSound.volume = this.PLOP_VOLUME; this.jumpWhistleSound.volume = this.JUMP_WHISTLE_VOLUME; this.soundtrack.volume = this.SOUNDTRACK_VOLUME; this.thudSound.volume = this.LANDING_VOLUME; }, start: function () { this.createSprites(); this.initializeImages(); this.initializeSounds(); this.equipRunner(); this.splashToast('Good Luck!'); ... }, ... }; |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 | SnailBait = function () { ... this.soundOn= true, this.audioTracks= [ // 8 tracks is more than enough new Audio(), new Audio(), new Audio(), new Audio(), new Audio(), new Audio(), new Audio(), new Audio() ], ... // Playing sounds....................................................... soundIsPlaying: function (sound) { return !sound.ended && sound.currentTime > 0; }, playSound: function (sound) { var track, index; if (this.soundOn) { if (!this.soundIsPlaying(sound)) { sound.play(); } else { for (i=0; index < this.audioTracks.length; ++index) { track = this.audioTracks[index]; if (!this.soundIsPlaying(track)) { track.src = sound.currentSrc; track.load(); track.volume = sound.volume; track.play(); break; } } } } }, ... }; |
欢迎光临 电子技术论坛_中国专业的电子工程师学习交流社区-中电网技术论坛 (http://bbs.eccn.com/) | Powered by Discuz! 7.0.0 |