wyrian/guiltouf/js/layouts/Ennemies.js

45 lines
1,008 B
JavaScript
Raw Normal View History

2011-02-12 14:55:38 +00:00
// -- Init the Background DIV
Layouts.Ennemies = new Layout({
// -- Define elements to draw with options
el: [],
// -- Define current Speed
speed: 7,
direction: 1,
// -- Define canvas parent
dom: $('div#game')
}) ;
// -- Create a random ennemy
Layouts.Ennemies.createRandom = function(opts) {
2011-02-12 21:24:14 +00:00
var self = this ;
2011-02-12 14:55:38 +00:00
var bulletConf = {
name: 'ennemy',
type: 'alien',
2011-02-12 14:55:38 +00:00
width: 60,
height: 60,
power: 40,
imageSrc: '/images/bullet-electric-sprite.png',
sprites: [0,1,2],
2011-02-12 17:54:57 +00:00
speed: Math.round(Math.max(10, Math.random()*20)),
2011-02-12 14:55:38 +00:00
direction: 1,
2011-02-12 21:24:14 +00:00
origin: {x:Math.round(Math.random()*self.width), y:Math.round(-Math.random()*self.height)},
explode: function(obj) {
},
2011-02-12 14:55:38 +00:00
animate: function (obj) {
obj.y += obj.settings.speed*obj.settings.direction ;
2011-02-12 21:24:14 +00:00
if ( obj.y > obj.parent.height+obj.height ) {
obj.x = Math.round(Math.random()*self.width)
obj.y = Math.round(-Math.random()*self.height) ;
2011-02-12 14:55:38 +00:00
}
}
} ;
this.els.push(this.createObj(bulletConf)) ;
} ;