Quellcode durchsuchen

Feature: adding explosions
Feature: adding CornWeapon explosion animation

Fabrice Ecaille vor 12 Jahren
Ursprung
Commit
fcd9d56df7

BIN
images/explosion_big.png


BIN
images/explosion_small.png


+ 118 - 2
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 : {

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

+ 5 - 1
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();

+ 25 - 0
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()