diff --git a/images/explosion_big.png b/images/explosion_big.png new file mode 100644 index 0000000..8ada14a Binary files /dev/null and b/images/explosion_big.png differ diff --git a/images/explosion_small.png b/images/explosion_small.png new file mode 100644 index 0000000..61588d5 Binary files /dev/null and b/images/explosion_small.png differ diff --git a/js/spaceinvaders-animations.js b/js/spaceinvaders-animations.js index f8c876d..8f1549b 100644 --- a/js/spaceinvaders-animations.js +++ b/js/spaceinvaders-animations.js @@ -8,10 +8,126 @@ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -var ALIENS_WIDTH = 24, +var ALIENS_WIDTH = 24, ALIENS_HEIGHT = 17, - IMAGES_PREFIX = "images/"; + IMAGES_PREFIX = "images/", + EXPLOSION_BIG = IMAGES_PREFIX + "explosion_big.png", + EXPLOSION_BIG_RATE = 50, + EXPLOSION_SMALL = IMAGES_PREFIX + "explosion_small.png", + EXPLOSION_SMALL_RATE = 50; +var EXPLOSIONS = { + BIG : [ + { + animation : new $.gQ.Animation({ + imageURL : EXPLOSION_BIG, + numberOfFrame : 8, + delta : 128, + rate : EXPLOSION_BIG_RATE, + type : $.gQ.ANIMATION_HORIZONTAL | $.gQ.ANIMATION_CALLBACK + }), + width : 128, + height: 128 + }, + { + animation : new $.gQ.Animation({ + imageURL : EXPLOSION_BIG, + offsety : 128, + numberOfFrame : 8, + delta : 128, + rate : EXPLOSION_BIG_RATE, + type : $.gQ.ANIMATION_HORIZONTAL | $.gQ.ANIMATION_CALLBACK + }), + width : 128, + height: 128 + }, + { + animation : new $.gQ.Animation({ + imageURL : EXPLOSION_BIG, + offsety : 256, + numberOfFrame : 8, + delta : 128, + rate : EXPLOSION_BIG_RATE, + type : $.gQ.ANIMATION_HORIZONTAL | $.gQ.ANIMATION_CALLBACK + }), + width : 128, + height: 128 + }, + { + animation : new $.gQ.Animation({ + imageURL : EXPLOSION_BIG, + offsety : 384, + numberOfFrame : 8, + delta : 128, + rate : EXPLOSION_BIG_RATE, + type : $.gQ.ANIMATION_HORIZONTAL | $.gQ.ANIMATION_CALLBACK + }), + width : 128, + height: 128 + }, + { + animation : new $.gQ.Animation({ + imageURL : EXPLOSION_BIG, + offsety : 512, + numberOfFrame : 8, + delta : 128, + rate : EXPLOSION_BIG_RATE, + type : $.gQ.ANIMATION_HORIZONTAL | $.gQ.ANIMATION_CALLBACK + }), + width : 128, + height: 128 + }, + { + animation : new $.gQ.Animation({ + imageURL : EXPLOSION_BIG, + offsety : 640, + numberOfFrame : 8, + delta : 128, + rate : EXPLOSION_BIG_RATE, + type : $.gQ.ANIMATION_HORIZONTAL | $.gQ.ANIMATION_CALLBACK + }), + width : 128, + height: 128 + }, + { + animation : new $.gQ.Animation({ + imageURL : EXPLOSION_BIG, + offsety : 768, + numberOfFrame : 8, + delta : 128, + rate : EXPLOSION_BIG_RATE, + type : $.gQ.ANIMATION_HORIZONTAL | $.gQ.ANIMATION_CALLBACK | $.gQ.ANIMATION_ONCE + }), + width : 128, + height: 128 + }, + { + animation : new $.gQ.Animation({ + imageURL : EXPLOSION_BIG, + offsety : 896, + numberOfFrame : 8, + delta : 128, + rate : EXPLOSION_BIG_RATE, + type : $.gQ.ANIMATION_HORIZONTAL | $.gQ.ANIMATION_CALLBACK | $.gQ.ANIMATION_ONCE + }), + width : 128, + height: 128 + } + ], + SMALL : [ + { + animation : new $.gQ.Animation({ + imageURL : EXPLOSION_SMALL, + numberOfFrame : 10, + delta : 64, + rate : EXPLOSION_SMALL_RATE, + type : $.gQ.ANIMATION_HORIZONTAL | $.gQ.ANIMATION_CALLBACK | $.gQ.ANIMATION_ONCE + }), + width : 64, + height: 64 + } + ] +} var WORLD = { farm : { hero : { diff --git a/js/spaceinvaders-core.js b/js/spaceinvaders-core.js index 86f1f6b..263a91a 100644 --- a/js/spaceinvaders-core.js +++ b/js/spaceinvaders-core.js @@ -186,7 +186,7 @@ Game = { Game.game_over(); return false; } - if( alien.health > 0 && Math.random() < alien.aggression ) { + if( alien.health > 0 && Math.random() < (alien.aggression * (Game.wave_index + 1)) ) { alien.fire($("#aliensShots"), "alienShot"); } }); diff --git a/js/spaceinvaders-models.js b/js/spaceinvaders-models.js index fe344f9..5e1ee04 100644 --- a/js/spaceinvaders-models.js +++ b/js/spaceinvaders-models.js @@ -299,7 +299,11 @@ function CornWeapon() { var mediumAlien = getAliensMidHeight(); if( shot.y() < mediumAlien ) { + var explosion = EXPLOSIONS.SMALL[0]; + $("#shipShots").addSprite("cornExplosion", {width: explosion.width, height: explosion.height, posx: shot.x() - explosion.width / 2, posy: shot.y() - explosion.height / 2}); + explosionSmall($("#cornExplosion"), function() {$("#cornExplosion").remove()}); shot.remove(); + var shipShots = $("#shipShots"); for( var i = 0; i < 8; i++) { var cos = Math.cos( (Math.PI / 4) * i ), @@ -573,7 +577,7 @@ Ship.prototype = { Game.game_over(); return true; } - + var _this = this; setTimeout(function() { $("#hero").children().show(); diff --git a/js/spaceinvaders-ui.js b/js/spaceinvaders-ui.js index 9efb7b5..6a909d9 100644 --- a/js/spaceinvaders-ui.js +++ b/js/spaceinvaders-ui.js @@ -26,6 +26,25 @@ var PLAYGROUND_WIDTH = 448, var animations = WORLD.farm; + +function explose( div, explosion, step, callback ) { + if( step < explosion.length - 2 ) { + div.setAnimation( explosion[step].animation, function() { + explose( div, explosion, step + 1, callback ); + }); + } else { + div.setAnimation( explosion[step].animation, callback); + } +}; + +function explosionBig( div, callback ) { + explose(div, EXPLOSIONS.BIG, 0, callback ); +}; + +function explosionSmall( div, callback ) { + explose(div, EXPLOSIONS.SMALL, 0, callback ); +}; + function displayModal(data) { var score = data.score.toString(); $.playground() @@ -107,6 +126,12 @@ $(function(){ posy: PLAYGROUND_HEIGHT - HUD_HEIGHT - 50 }) .end() + .addSprite("explosion", { + width: 64, + height: 64, + posx: 100, + posy: 100 + }) .end() .addGroup( "shipShots", {posx: 0, posy: HUD_HEIGHT, width: PLAYGROUND_WIDTH, height: PLAYGROUND_HEIGHT - HUD_HEIGHT}) .end()