Skip to content
This repository
Browse code

added preloading images/sounds, removed wav files because of size

  • Loading branch information...
commit b9fb881469509e565e2d5c093e382c710844af1e 1 parent 181555b
Witali Mik authored March 01, 2012
8,454  assets/js/crafty.js
8454 additions, 0 deletions not shown
4  assets/js/game.js
@@ -21,6 +21,6 @@ $(function(){
21 21
     bars.shield.progressbar({
22 22
         value: 0
23 23
     });
24  
-    //$('#interface').hide();
25  
-    Crafty.scene("Level1");
  24
+    $('#interface').hide();
  25
+    Crafty.scene("Loading");
26 26
 });
57  assets/js/levels.js
... ...
@@ -1,20 +1,34 @@
1 1
 //Loading Scene
2 2
 Crafty.scene("Loading",function(){
3  
-    
  3
+
4 4
     var toLoad = [
5 5
     //Images
6  
-    game_path + "/assets/img/bg.png",
7  
-    game_path + "/assets/img/ships.png",
8  
-    game_path + "/assets/img/weapon1_small.png",
9  
-    game_path + "/assets/img/weapon2.png",
10  
-    game_path + "/assets/img/dmg.png",
11  
-    game_path + "/assets/img/asteroid64.png",
12  
-    game_path + "/assets/img/asteroid32.png",
13  
-    game_path + "/assets/img/explosion.png",
14  
-    game_path + "/media/sounds/explode.mp3",
15  
-    game_path + "/media/sounds/explode.ogg",
16  
-    game_path + "/media/sounds/explode.wav",
  6
+    game_path + "assets/img/bg.png",
  7
+    game_path + "assets/img/ships.png",
  8
+    game_path + "assets/img/weapon1_small.png",
  9
+    game_path + "assets/img/weapon2.png",
  10
+    game_path + "assets/img/dmg.png",
  11
+    game_path + "assets/img/asteroid64.png",
  12
+    game_path + "assets/img/asteroid32.png",
  13
+    game_path + "assets/img/explosion.png",
  14
+    //Sounds
  15
+    game_path + "media/sounds/explode.mp3",
  16
+    game_path + "media/sounds/explode.ogg",
  17
+    game_path + "media/sounds/explodemini.mp3",
  18
+    game_path + "media/sounds/explodemini.ogg",
  19
+    game_path + "media/sounds/laser1.mp3",
  20
+    game_path + "media/sounds/laser1.ogg",
  21
+    game_path + "media/sounds/laser2.mp3",
  22
+    game_path + "media/sounds/laser2.ogg",
  23
+    game_path + "media/sounds/laser3.mp3",
  24
+    game_path + "media/sounds/laser3.ogg",
  25
+    game_path + "media/sounds/laser4.mp3",
  26
+    game_path + "media/sounds/laser4.ogg",
  27
+    //Music
  28
+    game_path + "media/music/spaceship.mp3",
  29
+    game_path + "media/music/spaceship.ogg",
17 30
     ];
  31
+   
18 32
     Crafty.background("black");
19 33
     Crafty.e("2D","DOM","Text").css({
20 34
         "color":"#ffffff"
@@ -24,21 +38,24 @@ Crafty.scene("Loading",function(){
24 38
     }).css({
25 39
         "color":"#ffffff"
26 40
     });
  41
+    
27 42
     Crafty.load(toLoad,
28 43
         function() {
29  
-        //when loaded
30  
-        //  Crafty.scene("Level1"); //go to Level1 scene
  44
+    
  45
+            //when loaded
  46
+            $('#interface').show();
  47
+            Crafty.scene("Level1"); //go to Level1 scene
31 48
         },
32 49
 
33 50
         function(e) {
34  
-
  51
+ 
35 52
             loaded.text(Math.round(e.percent)+" %");
36 53
         //progress
37 54
         },
38 55
 
39 56
         function(e) {
40  
-            console.log(e);
41  
- 
  57
+            console.log("Error on loading: "+e.src);
  58
+
42 59
         //uh oh, error loading
43 60
         }
44 61
         );
@@ -47,8 +64,7 @@ Crafty.scene("Loading",function(){
47 64
 Crafty.scene("Level1",function(){
48 65
     //Setup background of level
49 66
     Crafty.background("url(" + game_path + "/assets/img/bg.png)");
50  
-    //Play background music and repeat
51  
-    Crafty.audio.play("space",-1);
  67
+   
52 68
     $('.level').text('Level: 1');
53 69
 
54 70
     var spotEnemys = function(frame){   
@@ -77,6 +93,7 @@ Crafty.scene("Level1",function(){
77 93
         Crafty.stage.elem.style.backgroundPosition ="0px "+frame.frame+"px";
78 94
         
79 95
     });
80  
-   
  96
+    //Play background music and repeat
  97
+    Crafty.audio.play("space",-1);
81 98
   
82 99
 });
8  assets/js/sounds.js
... ...
@@ -1,55 +1,47 @@
1 1
 Crafty.audio.add({
2 2
     space: [
3  
-    game_path + "/media/music/through-space.wav",
4 3
     game_path + "/media/music/through-space.mp3",
5 4
     game_path + "/media/music/through-space.ogg"
6 5
     ]
7 6
 });
8 7
 Crafty.audio.add({
9 8
     spaceship: [
10  
-    game_path + "/media/music/spaceship.wav",
11 9
     game_path + "/media/music/spaceship.mp3",
12 10
     game_path + "/media/music/spaceship.ogg"
13 11
     ]
14 12
 });
15 13
 Crafty.audio.add({   
16 14
     explosion0: [
17  
-    game_path + "/media/sounds/explodemini.wav",
18 15
     game_path + "/media/sounds/explodemini.mp3",
19 16
     game_path + "/media/sounds/explodemini.ogg"
20 17
     ]
21 18
 });
22 19
 Crafty.audio.add({
23 20
     explosion1: [
24  
-    game_path + "/media/sounds/explode.wav",
25 21
     game_path + "/media/sounds/explode.mp3",
26 22
     game_path + "/media/sounds/explode.ogg"
27 23
     ]
28 24
     });
29 25
 Crafty.audio.add({
30 26
     laser1: [
31  
-    game_path + "/media/sounds/laser1.wav",
32 27
     game_path + "/media/sounds/laser1.mp3",
33 28
     game_path + "/media/sounds/laser1.ogg"
34 29
     ]
35 30
     });
36 31
 Crafty.audio.add({
37 32
     laser2: [
38  
-    game_path + "/media/sounds/laser2.wav",
39 33
     game_path + "/media/sounds/laser2.mp3",
40 34
     game_path + "/media/sounds/laser2.ogg"
41 35
     ]
42 36
     });
43 37
 Crafty.audio.add({
44 38
     laser3: [
45  
-    game_path + "/media/sounds/laser3.wav",
46 39
     game_path + "/media/sounds/laser3.mp3",
47 40
     game_path + "/media/sounds/laser3.ogg"
48 41
     ]
49 42
     });
50 43
 Crafty.audio.add({
51 44
     laser4: [
52  
-    game_path + "/media/sounds/laser4.wav",
53 45
     game_path + "/media/sounds/laser4.mp3",
54 46
     game_path + "/media/sounds/laser4.ogg"
55 47
     ]
6  index.html
@@ -3,13 +3,13 @@
3 3
     <head>
4 4
         <meta charset="UTF-8" />
5 5
         <title>Cron</title>
6  
-        <script type="text/javascript" src="http://cdn.crafty-modules.com/crafty-DEBUG.js"></script>
7  
-    
  6
+      <!--  <script type="text/javascript" src="http://cdn.crafty-modules.com/crafty-DEBUG.js"></script> -->
  7
+     <script type="text/javascript" src="assets/js/crafty.js"></script>
8 8
         <script>var game_path = location.href.lastIndexOf("/") !== -1 ? location.href.substring(0, location.href.lastIndexOf("/") + 1) : location.href;</script>
9 9
         <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
10 10
         <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.16/jquery-ui.min.js"></script>
11 11
         <script type="text/javascript" src="assets/js/sprites.js"></script>
12  
-        <script type="text/javascript" src="assets/js/sounds.js"></script>
  12
+       <script type="text/javascript" src="assets/js/sounds.js"></script> 
13 13
         <script type="text/javascript" src="assets/js/weapons.js"></script>
14 14
         <script type="text/javascript" src="assets/js/effects.js"></script>
15 15
         <script type="text/javascript" src="assets/js/enemys.js"></script>
BIN  media/music/spaceship.wav
Binary file not shown
BIN  media/music/through-space.wav
Binary file not shown
BIN  media/sounds/explode.wav
Binary file not shown
BIN  media/sounds/explodemini.wav
Binary file not shown
BIN  media/sounds/laser1.wav
Binary file not shown
BIN  media/sounds/laser2.wav
Binary file not shown
BIN  media/sounds/laser3.wav
Binary file not shown
BIN  media/sounds/laser4.wav
Binary file not shown

0 notes on commit b9fb881

Please sign in to comment.
Something went wrong with that request. Please try again.