Permalink
Browse files

added .mp3 gameover sound and loadbar skip possibility

  • Loading branch information...
1 parent 710909a commit 905d32212b006b3c6484949dd84d4e96ddfd382c @BlackScorp committed Mar 21, 2012
Showing with 49 additions and 27 deletions.
  1. +6 −1 assets/css/style.css
  2. +24 −15 assets/js/levels.js
  3. +10 −9 assets/js/loader.js
  4. +8 −2 assets/js/sounds.js
  5. +1 −0 index.html
  6. 0 media/music/ambient.mp3
@@ -13,8 +13,13 @@
.clear{
clear:both;
}
+.skip{
+ color:#990000;
+ text-decoration: underline;
+ cursor:pointer;
+}
#interface,#loading{
- display:none;
+
position: absolute;
width: 100%;
height: 100%;
View
@@ -12,31 +12,38 @@ Crafty.scene("Loading",function(){
Crafty.background("url("+game_path+"assets/img/loading.jpg) black");
//Select DOM elements
- var loading = $('#loading');
var bar = $('#load');
var button = $('.button');
var text = bar.find('.text');
- //Display loading interface
- loading.show();
+ $('#interface').hide();
//Setup progressbar
+ text.text("Loading ...");
+
bar.progressbar({
value:0
+
});
//Bind click event on button
button.live('click',function(){
- //Hide loading interface
- loading.hide();
//Start scene level 1
Crafty.scene("Level1");
});
-
+
+ $('.skip').live('click',function(){
+ bar.fadeOut(1000,function(){
+ button.show();
+ });
+
+ });
+
Crafty.load(toLoad,
function() {
//Everything is loaded
- bar.fadeOut(2000,function(){
+ bar.fadeOut(1000,function(){
button.show();
});
+
},
function(e) {
var src = e.src ||"";
@@ -46,23 +53,25 @@ Crafty.scene("Loading",function(){
bar.progressbar({
value:~~e.percent
});
+
},
function(e) {
- //uh oh, error loading
-
+ //uh oh, error loading
+ var src = e.src ||"";
+ console.log("Error on loading: "+src.substr(src.lastIndexOf('/') + 1).toLowerCase());
}
);
- Crafty.audio.play("gameover",-1);
+ Crafty.audio.play("intro",-1);
},
//Uninit Scene
function(){
Crafty.audio.stop();
+ //Display loading interface
+ $('#loading').hide();
});
//Level 1 Scene
Crafty.scene("Level1",function(){
- //Stop loading sound
- Crafty.audio.stop();
//Display interface
$('#interface').show();
//Setup background of level
@@ -155,9 +164,9 @@ Crafty.scene("Level1",function(){
});
//Global Event for Game Over
Crafty.bind("GameOver",function(score){
- Crafty.trigger("ShowText","Game Over!");
- Crafty.audio.stop();
- Crafty.audio.play("gameover",-1);
+ Crafty.trigger("ShowText","Game Over!");
+ Crafty.audio.stop();
+ Crafty.audio.play("gameover",-1);
});
//Play background music and repeat
View
@@ -51,21 +51,21 @@ Crafty.extend({
*/
load: function (data, oncomplete, onprogress, onerror) {
- var i = 0, l = data.length, current, obj, total = l, j = 0, ext = "" ,audio,canplay;
+ var i = 0, l = data.length, current, obj, total = l, j = 0, ext = "" ;
//Progress function
function pro(){
var src = this.src;
-
+
//Remove events cause audio trigger this event more than once(depends on browser)
if (this.removeEventListener) {
- this.removeEventListener('canplaythrough', pro, true);
+ this.removeEventListener('canplaythrough', pro, false);
}
++j;
//if progress callback, give information of assets loaded, total and percent
if (onprogress)
- onprogress.call(this,{
+ onprogress({
loaded: j,
total: total,
percent: (j / total * 100),
@@ -78,7 +78,7 @@ Crafty.extend({
function err(){
var src = this.src;
if (onerror)
- onerror.call(this,{
+ onerror({
loaded: j,
total: total,
percent: (j / total * 100),
@@ -94,7 +94,7 @@ Crafty.extend({
ext = current.substr(current.lastIndexOf('.') + 1).toLowerCase();
obj = this.assets[current] || null;
-
+
if (Crafty.support.audio && Crafty.audio.supported[ext]) {
if(!obj){
@@ -110,11 +110,12 @@ Crafty.extend({
played:0
}
}
-
+
+ //addEventListener is supported on IE9 , Audio as well
if (obj.addEventListener) {
- obj.addEventListener('canplaythrough', pro, true);
+ obj.addEventListener('canplaythrough', pro, false);
}
-
+
} else if (ext === "jpg" || ext === "jpeg" || ext === "gif" || ext === "png") {
if(!obj) {
View
@@ -31,5 +31,11 @@ Crafty.audio.add("space",[
game_path + "media/music/through-space.ogg"
]);
-Crafty.audio.add("gameover",game_path + "media/music/ambient.ogg");
-Crafty.audio.add("spaceship", game_path + "media/music/spaceship.mp3"); //Will work only Safari/IE
+Crafty.audio.add("gameover",[
+ game_path + "media/music/ambient.ogg",
+ game_path + "media/music/ambient.mp3"
+ ]);
+ Crafty.audio.add("intro",[
+ game_path + "media/music/through-space.ogg",
+ game_path + "media/music/through-space.mp3"
+ ]);
View
@@ -31,6 +31,7 @@
<p>Get the <a href="https://github.com/BlackScorp/cron">Code</a></p>
<p>Get the <a href="http://opengameart.org">Images and Sounds</a></p>
<p><a href="mozilla-app.html">Install</a> the App in <a href="https://myapps.mozillalabs.com/">Mozilla Appstore</a></p>
+ <p><i><b>Note:</b>Opera has some bugs,if loading not complete <span class="skip">skip</span> it</i></p>
</div>
<div id="cr-stage">
<div id="interface">
No changes.

0 comments on commit 905d322

Please sign in to comment.