Skip to content

Commit

Permalink
95% completed
Browse files Browse the repository at this point in the history
  • Loading branch information
unknown authored and unknown committed Jun 13, 2014
1 parent 1bf56c9 commit 4d52b83
Show file tree
Hide file tree
Showing 9 changed files with 79 additions and 23 deletions.
13 changes: 11 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,18 @@
微信打飞机小游戏
==================
90% complete
95% complete
------------------

###在线试玩
[请戳这里](http://htmlpreview.github.io/?https://github.com/liege/plane/blob/master/index.html)
------------------

###游戏攻略
> 1、游戏刚开始的时候,不要急着打大飞机<br>
> 2、第一个BOSS(你可以叫他“阿欢”)很重要,一定要打爆他<br>
> 3、越到后面,敌机速度越快,数量越多,想要赢,就打够9只BOSS——你将得到神之力量!<br>
###下一版本主要增加武器升级
###你懂的
if(_this.killBossCount == 9){
_this.myPlane.lv++;
}
4 changes: 3 additions & 1 deletion css/view.css
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ body{font: normal normal 16px/30px arial,"微软雅黑"; }
.npc2{width: 46px;height: 60px;background:url(../img/npc2.png); position: absolute; top: 0; left: 45%;}
.npc3{width: 110px;height: 164px;background:url(../img/npc3.png); position: absolute; top: 0; left: 45%;}
.npc4{width: 54px;height: 76px;background:url(../img/npc4.png); position: absolute; top: 0; left: 45%;}
i{position: absolute; width: 6px; height: 14px; background:url(../img/bullet1.png);}
#container i.lv1{position: absolute; width: 6px; height: 14px; background:url(../img/bullet1.png);}
#container i.lv2{position: absolute; width: 32px; height: 39px; background:url(../img/bullet2.png);}
#container i.lv3{position: absolute; width: 66px; height: 62px; background:url(../img/bullet3.png);}
#container span{display: block;position: absolute;}
.bang1{ background:url(../img/plane1.gif); }
.bang2{background:url(../img/plane2.gif); }
Expand Down
Binary file added img/bullet2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added img/bullet3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added img/plane4.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 0 additions & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
</head>
<body>
<!-- <input type="button" value="开始" /> -->
<input type="text" id="t" />
<div id="container">
<div id="begin"><input id="begin_btn" type="button" value="开始游戏" /></div>
<div id="pause"><input id="pause_btn" type="button" value="继续游戏" /></div>
Expand Down
2 changes: 2 additions & 0 deletions js/bullet.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ function Bullet(){
this.direction = null;
this.startPos = {x:0,y:0};
this.timer = null;
this.domClass = "";
}
//子弹销毁
Bullet.prototype.die = function(){
Expand All @@ -23,6 +24,7 @@ Bullet.prototype.fire = function(){
var _this = this;
//创建子弹
_this.bullet = document.createElement("i");
_this.bullet.className = _this.domClass;
document.getElementById("container").appendChild(_this.bullet);
_this.bullet.style.left = _this.startPos.x + "px";
_this.bullet.style.top = _this.startPos.y + "px";
Expand Down
47 changes: 36 additions & 11 deletions js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@ var game = {
allPlane:[],
allBullet:[],
planeSpeed:[4,3,2,1],
planeDensity:[20,200,600,1500],
planeDensity:[20,200,600,1000],
interval:1000/24,
scores:0,
gameTime:0,
num:0,
stageBgY:0,
gameSet:null,
stage:null
stage:null,
killBossCount:0
};
//初始化我机
game.initMyPlane = function(){
Expand Down Expand Up @@ -86,19 +87,19 @@ game.run = function(){
//获取、遍历所有飞机对象
var len = _this.allPlane.length;
for(var i=0;i<len;i++){
//判断飞机销毁或飞出界面
//判断飞机飞出界面
if( _this.allPlane[i].plane.offsetTop>_this.stage.offsetHeight){
_this.allPlane[i].die();
}
//从数组清理出界活销毁的飞机
if(_this.allPlane[i].outside){
_this.allPlane.splice(i,1);
len--;
}
//我机敌机碰撞
if(getCollision(_this.myPlane.plane,_this.allPlane[i].plane)){
_this.over();
}
//从数组清理出界或销毁的飞机
if(_this.allPlane[i].outside){
_this.allPlane.splice(i,1);
len--;
}
}
//敌机移动
for(var i=0;i<_this.allPlane.length;i++){
Expand All @@ -114,10 +115,22 @@ game.run = function(){
//子弹销毁
_this.allBullet[j].die();
//飞机护甲减少
_this.allPlane[i].armor--;
_this.allPlane[i].armor-=_this.allBullet[j].power;
if(_this.allPlane[i].armor<=0){
//得分
_this.scores += _this.allPlane[i].score;
//击杀boss获得奖励
if(_this.allPlane[i].class == "npc4"){
//第一次击杀
if(_this.myPlane.lv == 1){
_this.myPlane.lv++;
}
_this.killBossCount++;
//击杀n次boss得到最终武器
if(_this.killBossCount == 9){
_this.myPlane.lv++;
}
}
//飞机爆炸
_this.allPlane[i].bang();
}
Expand All @@ -133,7 +146,7 @@ game.run = function(){
//游戏进度
if(_this.scores>20 && _this.scores<40){
_this.planeSpeed = [5,4,3,2];
_this.planeDensity = [15,200,600,1500];
_this.planeDensity = [15,200,600,1000];
}
if(_this.scores>40 && _this.scores<80){
_this.planeSpeed = [6,5,4,3];
Expand All @@ -147,6 +160,10 @@ game.run = function(){
_this.planeSpeed = [10,8,6,5];
_this.planeDensity = [10,150,300,1000];
}
if(_this.scores>300){
_this.planeSpeed = [12,10,8,4];
_this.planeDensity = [8,100,200,800];
}
};
//游戏开始,初始化我机,场景运动开始
game.begin = function(){
Expand Down Expand Up @@ -195,9 +212,17 @@ onload = function(){
E.stopPropagation();
E.cancelBubble = true;
};
stage.onclick = function(){
begin.onclick = function(e){
var E = e||event;
E.stopPropagation();
E.cancelBubble = true;
};
stage.onclick = function(e){
var E = e||event;
pause.style.display = "block";
game.pause();
E.stopPropagation();
E.cancelBubble = true;
};
pause_btn.onclick = function(e){
var E = e||event;
Expand Down
35 changes: 27 additions & 8 deletions js/plane.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ function Plane(){
this.class = null;
this.direction = "up";
this.bullets = null;
this.lv = 1;
}
//显示飞机
Plane.prototype.show = function(){
Expand Down Expand Up @@ -43,12 +44,14 @@ Plane.prototype.bang = function(){
window.setTimeout(timer);
timer = window.setTimeout(function(){
document.getElementById("container").removeChild(bangObj);
},400);
},300);
};
//飞机销毁
Plane.prototype.die = function(){
var _this = this;
if(_this.plane){
document.getElementById("container").removeChild(_this.plane);
}
_this.outside = true;
};
//我机
Expand All @@ -57,13 +60,29 @@ myPlane.prototype = new Plane();
//飞机开火
myPlane.prototype.fire = function(){
var _this = this;
_this.position = {
x:_this.plane.offsetLeft + _this.plane.offsetWidth/2 - 2,
y:_this.plane.offsetTop + 40
};
if(_this.lv == 1){
_this.position = {
x:_this.plane.offsetLeft + _this.plane.offsetWidth/2 - 2,
y:_this.plane.offsetTop + 40
};
}
if(_this.lv == 2){
_this.position = {
x:_this.plane.offsetLeft + _this.plane.offsetWidth/2 - 16,
y:_this.plane.offsetTop + 20
};
}
if(_this.lv == 3){
_this.position = {
x:_this.plane.offsetLeft + _this.plane.offsetWidth/2 - 33,
y:_this.plane.offsetTop
};
}
//实例化子弹
var b = new Bullet();
_this.bullets = b;
_this.bullets.power = _this.lv;
_this.bullets.domClass = "lv" + _this.lv;
//子弹方向等于飞机方向
_this.bullets.direction = _this.direction;
//子弹初始坐标等于飞机position值
Expand All @@ -75,8 +94,7 @@ myPlane.prototype.fire = function(){
myPlane.prototype.move = function(state){
var _this = this;
_this.stage = document.getElementById("container");
// alert(state);
if(!state){
//飞机跟随鼠标移动
_this.stage.onmouseover = function(e){
_this.stage.onmousemove = function(e){
var E = e||event;
Expand All @@ -101,8 +119,9 @@ myPlane.prototype.move = function(state){
_this.stage.onmousemove = null;
};
};
}

};
//飞机停止跟随鼠标
myPlane.prototype.stop = function(){
this.stage.onmouseover = null;
this.stage.onmousemove = null;
Expand Down

0 comments on commit 4d52b83

Please sign in to comment.