bullet.prototype.move=function(moveX,moveY){
this.x+=moveX;
this.y+=moveY;
this.e.style.left=this.x+"px";
this.e.style.top=this.y+"px";
}
bullet.prototype.moveTo=function(X,Y){
this.x=X;
this.y=Y;
this.e.style.left=this.x+"px";
this.e.style.top=this.y+"px";
}
//子弹恢复
bullet.prototype.restore=function(){
this.x=Main.self
this.y=-Math.random()*Util.windowHeight-Util.enemyPlaneElement.height;
this.speed=2+Math.random()*4;
this.e.style.left=this.x+"px";
this.e.style.top=this.y+"px";
}
//子弹工厂
var bulletFactory={
bullets:[],
creatBullet:function(n){
for(var i=0;i<n;i++){
var b=new bullet(0,-Util.bulletElement.height,20);
this.bullets.push(b);
}
}
}
util.js:
// JavaScript Document
var Util={
windowWidth:350,
windowHeight:480,
selfPlaneElement:null,
enemyPlaneElement:null,
bulletElement:null,
parentElement:null,
scoreSpan:null,
g:function(id){
return document.getElementById(id);
},
init:function(){
this.parentElement=this.g("parent");
this.selfPlaneElement=this._loadImg("images/self.gif");
this.enemyPlaneElement=this._loadImg("images/boss.gif");
this.bulletElement=this._loadImg("images/bullet.jpg");
this.scoreSpan=this.g("score");
},
_loadImg:function(src){
var e=document.createElement("img");
e.style.position="absolute";
e.src=src;
return e;
}
}
原生JavaScript开发仿微信打飞机小游戏源码下载地址:
具体下载目录在 /2014年资料/2月/8日/原生JavaScript开发仿微信打飞机小游戏