Optim: better waves managment

This commit is contained in:
Fabrice Ecaille
2013-10-09 18:00:04 +02:00
parent 4877555342
commit 29006e138d

View File

@@ -43,7 +43,8 @@ var WAVES = [
Game = { Game = {
running : false, running : false,
wave : -1, wave_index : -1,
wave : undefined,
aliens : [], aliens : [],
ship : null, ship : null,
score : 0, score : 0,
@@ -51,14 +52,16 @@ Game = {
init : function() { init : function() {
"use strict"; "use strict";
animations = WORLD.farm; animations = WORLD.farm;
Game.wave = Game.wave + 1; Game.wave_index = Game.wave_index + 1;
var row, col; Game.wave = WAVES[Math.min(Game.wave_index, WAVES.length - 1)];
var wave = WAVES[Game.wave].wave; console.log(Game.wave_index, Game.wave);
var row, col, wave = Game.wave.wave;
for (row = 0; row < wave.length; row = row + 1) { for (row = 0; row < wave.length; row = row + 1) {
var aliensRow = wave[row], type = aliensRow[0], offset = (PLAYGROUND_WIDTH - ((aliensRow.length - 1) * 0.5 + aliensRow.length) var aliensRow = wave[row], type = aliensRow[0], offset = (PLAYGROUND_WIDTH - ((aliensRow.length - 1) * 0.5 + aliensRow.length)
* ALIENS_WIDTH) / 2; * ALIENS_WIDTH) / 2;
for (col = 0; col < aliensRow.length; col = col + 1) { for (col = 0; col < aliensRow.length; col = col + 1) {
Game.setAlien(col, row, offset, type, WAVES[Game.wave].move); Game.setAlien(col, row, offset, type, Game.wave.move);
} }
} }
@@ -226,7 +229,7 @@ Game = {
Game.aliens = aliensNotInArray; Game.aliens = aliensNotInArray;
alien.alien.hit(); alien.alien.hit();
var remainingAliens = $(".alien").length; var remainingAliens = $(".alien").length;
if( remainingAliens == WAVES[Game.wave].bonus[0] || remainingAliens == WAVES[Game.wave].bonus[1] ) { if( remainingAliens == Game.wave.bonus[0] || remainingAliens == Game.wave.bonus[1] ) {
Game.bonus(alienX, alienY, alienWidth, alienHeight); Game.bonus(alienX, alienY, alienWidth, alienHeight);
} }
}) })