Feature: adding explosions

Feature: adding CornWeapon explosion animation
This commit is contained in:
Fabrice Ecaille
2013-10-31 18:34:07 +01:00
parent 75828a2c9a
commit fcd9d56df7
6 changed files with 149 additions and 4 deletions

BIN
images/explosion_big.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 360 KiB

BIN
images/explosion_small.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 20 KiB

View File

@@ -10,8 +10,124 @@
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 : {

View File

@@ -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");
}
});

View File

@@ -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 ),

View File

@@ -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()