mirror of
https://github.com/Febbweiss/sis.git
synced 2026-03-04 22:25:35 +00:00
Feature: adding CornWeapon
This commit is contained in:
@@ -22,7 +22,7 @@ var WAVES = [
|
|||||||
this.y = (this.y + this.height / 4);
|
this.y = (this.y + this.height / 4);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
bonus : [50, 20]
|
bonus : [40, 20]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
wave : [ [ 0, 0, 0, 0, 0, 0, 0 ],
|
wave : [ [ 0, 0, 0, 0, 0, 0, 0 ],
|
||||||
@@ -84,7 +84,7 @@ Game = {
|
|||||||
if( !Game.running ) {
|
if( !Game.running ) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
console.log( "Game.hit" );
|
|
||||||
var health = Game.ship.hit();
|
var health = Game.ship.hit();
|
||||||
$(".alienShot").remove();
|
$(".alienShot").remove();
|
||||||
$(".shipShot").remove();
|
$(".shipShot").remove();
|
||||||
@@ -193,26 +193,35 @@ Game = {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
$(".shipShot").each(function(i,e) {
|
var shots = $(".shipShot");
|
||||||
var posy = $(this).y();
|
if( shots.length == 0 ) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
shots.each(function(i,e) {
|
||||||
|
var posy = $(this).y(),
|
||||||
|
weapon = $(this)[0].weapon;
|
||||||
if( posy < -$(this).height() ) {
|
if( posy < -$(this).height() ) {
|
||||||
this.remove();
|
this.remove();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
var weapon = $(this)[0].weapon;
|
|
||||||
$(this).y(weapon.directionY * weapon.speed, true);
|
$(this).y(weapon.directionY * weapon.speed, true);
|
||||||
$(this).x(weapon.directionX * weapon.speed, true);
|
$(this).x(weapon.directionX * weapon.speed, true);
|
||||||
|
|
||||||
|
if( weapon.callback ) {
|
||||||
|
weapon.callback($(this));
|
||||||
|
} else {
|
||||||
var collisions = $(this).collision(".alien,."+$.gQ.groupCssClass);
|
var collisions = $(this).collision(".alien,."+$.gQ.groupCssClass);
|
||||||
collisions.each( function() {
|
collisions.each( function() {
|
||||||
var alien = $(this)[0];
|
var alien = $(this)[0],
|
||||||
var aliensNotInArray = $.grep( Game.aliens, function( elementOfArray, index) {
|
aliensNotInArray = $.grep( Game.aliens, function( elementOfArray, index) {
|
||||||
return elementOfArray.id == alien.id;
|
return elementOfArray.id == alien.id;
|
||||||
}, true);
|
}, true);
|
||||||
|
alienX = alien.alien.x,
|
||||||
|
alienY = alien.alien.y,
|
||||||
|
alienWidth = alien.alien.width,
|
||||||
|
alienHeight = alien.alien.height;
|
||||||
Game.aliens = aliensNotInArray;
|
Game.aliens = aliensNotInArray;
|
||||||
var alienX = alien.alien.x;
|
|
||||||
var alienY = alien.alien.y;
|
|
||||||
var alienWidth = alien.alien.width;
|
|
||||||
var alienHeight = alien.alien.height;
|
|
||||||
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 == WAVES[Game.wave].bonus[0] || remainingAliens == WAVES[Game.wave].bonus[1] ) {
|
||||||
@@ -227,6 +236,7 @@ Game = {
|
|||||||
Game.running = false;
|
Game.running = false;
|
||||||
Game.levelComplete();
|
Game.levelComplete();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ WORLD.farm.bonus = [
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
type: "weapon",
|
type: "weapon",
|
||||||
clazz: CarotWeapon,
|
clazz: CornWeapon,
|
||||||
animation: WORLD.farm.weapons.corn
|
animation: WORLD.farm.weapons.corn
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
@@ -42,6 +42,7 @@ Weapon.prototype = {
|
|||||||
directionY : 1,
|
directionY : 1,
|
||||||
animation : null,
|
animation : null,
|
||||||
clazz : "default",
|
clazz : "default",
|
||||||
|
callback : undefined,
|
||||||
|
|
||||||
fire : function() {
|
fire : function() {
|
||||||
if (this.shot_timer || this.load <= 0) {
|
if (this.shot_timer || this.load <= 0) {
|
||||||
@@ -93,6 +94,36 @@ CarotWeapon.prototype = {
|
|||||||
}
|
}
|
||||||
heriter(CarotWeapon.prototype, Weapon.prototype);
|
heriter(CarotWeapon.prototype, Weapon.prototype);
|
||||||
|
|
||||||
|
function CornWeapon() {
|
||||||
|
"use strict";
|
||||||
|
this.directionY = -1;
|
||||||
|
this.stock = 10;
|
||||||
|
this.clazz = "corn";
|
||||||
|
this.load = 1;
|
||||||
|
this.max_load = 1;
|
||||||
|
this.callback = function(shot) {
|
||||||
|
console.log( "CornWeapon.callback", this, shot );
|
||||||
|
var higherAlien = Math.max.apply( null,
|
||||||
|
$(".alien").map(function() {
|
||||||
|
return $(this).y();
|
||||||
|
}).get() ),
|
||||||
|
lowerAlien = Math.min.apply( null,
|
||||||
|
$(".alien").map(function() {
|
||||||
|
return $(this).y();
|
||||||
|
}).get() ),
|
||||||
|
mediumAlien = (higherAlien + lowerAlien) / 2;
|
||||||
|
|
||||||
|
if( shot.y() < mediumAlien ) {
|
||||||
|
console.log( "KABOUM" );
|
||||||
|
shot.remove();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
CornWeapon.prototype = {
|
||||||
|
|
||||||
|
}
|
||||||
|
heriter(CornWeapon.prototype, Weapon.prototype);
|
||||||
|
|
||||||
|
|
||||||
function AlienWeapon() {
|
function AlienWeapon() {
|
||||||
"use strict";
|
"use strict";
|
||||||
@@ -350,7 +381,7 @@ Ship.prototype = {
|
|||||||
this.weapon.stock--;
|
this.weapon.stock--;
|
||||||
if( this.weapon.stock == 0 ) {
|
if( this.weapon.stock == 0 ) {
|
||||||
this.weapon = new HeroWeapon();
|
this.weapon = new HeroWeapon();
|
||||||
$("#current_weapon").setAnimation(bonus.animation);
|
$("#current_weapon").setAnimation(this.weapon.animation);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,8 +21,7 @@ var PLAYGROUND_WIDTH = 448,
|
|||||||
ALIENS_WIDTH = 24,
|
ALIENS_WIDTH = 24,
|
||||||
ALIENS_HEIGHT = 17,
|
ALIENS_HEIGHT = 17,
|
||||||
|
|
||||||
START_Y = 40,
|
START_Y = 40;
|
||||||
IMAGES_PREFIX = "images/";
|
|
||||||
|
|
||||||
var SHIPS = {
|
var SHIPS = {
|
||||||
scout: {width: 30, height: 25},
|
scout: {width: 30, height: 25},
|
||||||
@@ -144,8 +143,8 @@ $(function(){
|
|||||||
$.playground().registerCallback(Game.alienControl, REFRESH_RATE);
|
$.playground().registerCallback(Game.alienControl, REFRESH_RATE);
|
||||||
|
|
||||||
// Collisions management
|
// Collisions management
|
||||||
$.playground().registerCallback(Game.heroShotCollision, REFRESH_RATE);
|
|
||||||
$.playground().registerCallback(Game.bonusCollision, REFRESH_RATE);
|
$.playground().registerCallback(Game.bonusCollision, REFRESH_RATE);
|
||||||
|
$.playground().registerCallback(Game.heroShotCollision, REFRESH_RATE);
|
||||||
$.playground().registerCallback(Game.alienShotCollision, REFRESH_RATE);
|
$.playground().registerCallback(Game.alienShotCollision, REFRESH_RATE);
|
||||||
|
|
||||||
// Refresh playground
|
// Refresh playground
|
||||||
|
|||||||
Reference in New Issue
Block a user