Commits

Anonymous committed 455d94d

- add a new level
- add message when the game ends

Comments (0)

Files changed (4)

         - the game_menu entries have to have a background color, so that we can click in the entry (instead of the text)
         - the EnemyKamikaze doesn't work too well
         - when returning from the game_menu with two keys held, top and left arrow for example, it doesn't continue going to the top left corner, but to the left only
+        - tweenjs not working
+        - weapon2-sniper sometimes doesnt appear the image
+        
+        
         
     to doo:
     
+        - mines should go away after some time
+    
  */
 
 
     // has the levels configurations
 var LEVELS = [];
 
-var NUMBER_OF_LEVELS = 1;
+var NUMBER_OF_LEVELS = 2;
 
 
 var CURRENT_LEVEL = 0;
 var level;
 var filePath;
 
+var i = 0;
+
     // load all but the last one
-for (var i = 0 ; i < NUMBER_OF_LEVELS - 1 ; i++)
+for (i = 0 ; i < NUMBER_OF_LEVELS - 1 ; i++)
     {
     filePath = 'maps/level' + i + '.json';
    
         success: function(data)
             {
             LEVELS.push( data );
+            },
+            
+        error: function(jqXHR, textStatus, errorThrown)
+            {
+            console.log(jqXHR, textStatus, errorThrown);
             }
         });
     }
         Maps.loadMap( 0 );
         
         Ticker.addListener( Maps.tick );
+        },
+        
+    error: function(jqXHR, textStatus, errorThrown)
+        {
+        console.log(jqXHR, textStatus, errorThrown);
         }
     });
 }
     CURRENT_LEVEL = 0;
     }
 
-Maps.greetingMessage( CURRENT_LEVEL );
+    // no more levels
+if (CURRENT_LEVEL >= NUMBER_OF_LEVELS)
+    {
+    Maps.noMoreLevels();
+    }
+
+else
+    {
+    COUNT_TICKS = 0;
+    LEVEL_PHASE = 0;
+    ENDING_LEVEL = false;
+    
+    Maps.showMessage( "Level " + CURRENT_LEVEL, 2000 );
+    }
 };
 
 
 COUNT_TICKS = 0;
 LEVEL_PHASE = 0;
 ENDING_LEVEL = false;
+LEVELS.length = 0;
+CURRENT_LEVEL = 0;
+Ticker.removeListener( Maps.tick );
 };
 
 
 
 
 /*
-    A message in the beginning of each level
+    Shows a message in the middle of the canvas for a period of time
+    
+    Arguments:
+    
+        - text : the actual message
+        - timeout : duration of the message (in miliseconds)
+        - timeout_function : executes when the timeout ends (optional)
  */
 
-Maps.greetingMessage = function( levelNumber )
+Maps.showMessage = function( text, timeout, timeout_function )
 {
-var message = new Text("Level " + levelNumber, "30px Arial", "rgb(255, 255, 255)");
+var message = new Text(text, "30px Arial", "rgb(255, 255, 255)");
 
 message.textAlign = 'center';
 
 STAGE.addChild( message );
 
 
-setTimeout( function() { STAGE.removeChild( message ); }, 2000 );
+setTimeout( function() 
+    {
+    STAGE.removeChild( message ); 
+    
+    if (typeof timeout_function != 'undefined' && timeout_function != null)
+        {
+        timeout_function();
+        }
+    
+    }, timeout );
 };
 
 
 
 
+
+/*
+    All levels completed, show a message and then go to the MainMenu
+ */
+
+Maps.noMoreLevels = function()
+{
+Maps.reset();
+
+Maps.showMessage("Congratulations, you finished the game!\nToo easy huh?", 4000, function() { MainMenu(); } );
+};
+
+
+
 Maps.tick = function()
 {  
 COUNT_TICKS++;
     
 var phase = currentLevel[ LEVEL_PHASE ];
 
-	
+
 
 if ( !ENDING_LEVEL && COUNT_TICKS >= phase.tick)
-    {
+    {   
     var enemyType = window[ phase.enemyType ];
     
     var i;
     
         // no more phases of the level
         // game ends when there aren't more enemies
-    if (LEVEL_PHASE + 1 >= currentLevel.length)
+    if (LEVEL_PHASE >= currentLevel.length)
         {
         ENDING_LEVEL = true;
         
     // the level ended
 if ( ENDING_LEVEL === true &&  COUNT_TICKS >= 100 && EnemyShip.all.length === 0 )
     {
-    MainMenu(); //HERE for now
+    Maps.loadMap();
     }
 };
 
     "howMany"   : 5,
     "x"         : -1,
     "y"         : -1
+    },
+    
+    {
+    "tick"      : 80,
+    "enemyType" : "EnemyRotateAround",
+    "howMany"   : 10,
+    "x"         : -1,
+    "y"         : -1
+    },
+    
+    {
+    "tick"      : 150,
+    "enemyType" : "EnemyMoveHorizontally",
+    "howMany"   : 15,
+    "x"         : -1,
+    "y"         : -1
     }
 ]
+[
+    {
+    "tick"      : 20,
+    "enemyType" : "EnemyRocks",
+    "howMany"   : 10,
+    "x"         : -1,
+    "y"         : -1
+    },
+    
+    {
+    "tick"      : 60,
+    "enemyType" : "EnemyRocks",
+    "howMany"   : 10,
+    "x"         : -1,
+    "y"         : -1
+    },
+    
+    {
+    "tick"      : 140,
+    "enemyType" : "EnemyKamikaze",
+    "howMany"   : 10,
+    "x"         : -1,
+    "y"         : -1
+    },
+    
+    {
+    "tick"      : 200,
+    "enemyType" : "EnemyRocks",
+    "howMany"   : 15,
+    "x"         : -1,
+    "y"         : -1
+    }    
+]