Skip to content

Commit

Permalink
added .mp3 gameover sound and loadbar skip possibility
Browse files Browse the repository at this point in the history
  • Loading branch information
BlackScorp committed Mar 21, 2012
1 parent 710909a commit 905d322
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 27 deletions.
7 changes: 6 additions & 1 deletion assets/css/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -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%;
Expand Down
39 changes: 24 additions & 15 deletions assets/js/levels.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 ||"";
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
19 changes: 10 additions & 9 deletions assets/js/loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand All @@ -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),
Expand All @@ -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){
Expand All @@ -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) {
Expand Down
10 changes: 8 additions & 2 deletions assets/js/sounds.js
Original file line number Diff line number Diff line change
Expand Up @@ -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"
]);
1 change: 1 addition & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -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">
Expand Down
Empty file added media/music/ambient.mp3
Empty file.

0 comments on commit 905d322

Please sign in to comment.