采用js技术创作的web版坦克大战,有用js模拟多线程技术,目前只支持IE,其他浏览器未写
具体代码:
目前运行比较占cpu,原因是控制enemy的虚拟线程处理比较慢,若想加快速度,可以固定存储所有操作的对象的属性,不要用
document对象来获取,这个可以在下一版优化。:-)
具体源码可以在resource下下载:
http://d.download.csdn.net/down/667431/chenyijiu
具体代码:
- <!--
- 这是一个web版的tank大战程序,可以进行初步的游戏
- 任何人都可以修改或优化该程序
- 若你修改或优化出更好的web版tank大战,我很乐意你邮寄一份copy给我
- Email:chenyijiu@gmail.com
- Author:陈一九
- Ver:1.00
- -->
- <html>
- <head>
- <meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
- <title>Tank</title>
- <link rel="shortcut icon" href="images/tank.ico" />
- </head>
- <body onload="PlayGame()">
- <div id="Tank">
- </div>
- <div id="CannonBall" style="display:none;">
- </div>
- <div id="Enemy" style="display:none;">
- </div>
- <div id="gameover" style="display:none; position:absolute; left:0; top:156; z-index:90000;"><img src="images/gameover.png" /></div>
- <div id="gamewin" style="display:none; position:absolute; left:0; top:156; z-index:80000;"><img src="images/gamewin.png" /></div>
- <!--<embed name="playerMove" src="sounds/Bank.wmv" loop="false" autostart="false" hidden="true" width="10" height="10" />-->
- <div id="enemyDetail" style="position:absolute; left:600; top:10;">
- <div>
- <b>敌人总数:</b>
- </div>
- <div id="enemyTotalCount">
- 20
- </div>
- <div>
- <b>重型:</b>
- </div>
- <div id="heavyEnemy">
- 5
- </div>
- <div>
- <b>常规:</b>
- </div>
- <div id="normalEnemy">
- 10
- </div>
- <div>
- <b>轻型:</b>
- </div>
- <div id="lightEnemy">
- 5
- </div>
- <div>
- <b>玩家Life:</b>
- </div>
- <div id="playerLife">
- 3
- </div>
- <div>
- <b>玩法:</b>
- </div>
- <div>
- 方向键控制玩家方向<br />
- Enter键暂停/继续<br />
- 空格键开火<br />
- F5键重新开局
- </div>
- </div>
- </body>
- </html>
- <script type="text/javascript" language="javascript">
- var objectid = 0;
- var statePlaying = "none";
- var map = null;
- var tankDraw = null;
- var player = null;
- var currentEnemyCount = 0;
- var canCreateEnemyCount = 3;
- var maxEnemyCount = 20;
- var leftEnemyCount = 20;
- var cannonSpeed = 8;
- var createEnemyPosition = 0;
- var enemyItems = new EnemyList();
- var currentEnemyItems = new EnemyList();
- var t1 = new Date();
- var t2 = new Date();
- var t3 = new Date();
- var tank = new Tank();
- var direction = new Array("left", "right", "up", "down");
- var kc = 0;
- var newkey = false;
- var startNewPlayerFlag = false;
- //function PlaySound(action, o)
- //{
- // if(eval(o) != null)
- // {
- // if(navigator.appName == "Netscape")
- // {
- // eval(o+((action=="stop")?".stop()":"playy(false)"));
- // }
- // else if(eval(o+".FileName"))
- // {
- // eval(o+((action=="stop")?".stop()":".play()"));
- // }
- // }
- //}
- var _st = window.setTimeout;
- window.setTimeout = function(fRef, mDelay) {
- if(typeof fRef == 'function'){
- var argu = Array.prototype.slice.call(arguments,2);
- var f = (function(){ fRef.apply(null, argu); });
- return _st(f, mDelay);
- }
- return _st(fRef,mDelay);
- }
- var _int = window.setInterval;
- window.setInterval = function(fRef, mDelay) {
- if(typeof fRef == 'function'){
- var argu = Array.prototype.slice.call(arguments,2);
- var f = (function(){ fRef.apply(null, argu); });
- return _int(f, mDelay);
- }
- return _st(fRef,mDelay);
- }
- //monitor the enemy
- function startEnemyControl()
- {
- var parameter = {}
- parameter.timer = setInterval(EnemyControl,1,parameter);
- }
- //process function
- function EnemyControl(parameter)
- {
- if(statePlaying == "pause" || statePlaying == "failed")
- return;
- //three create enemy point
- if(currentEnemyCount < canCreateEnemyCount && leftEnemyCount > 0)
- {
- if(createEnemyPosition == 0)
- {
- if((new Date()) - t1 > 2000)
- {
- enemyItems.Enemys[maxEnemyCount - leftEnemyCount].X = 0;
- enemyItems.Enemys[maxEnemyCount - leftEnemyCount].Y = 0;
- startNewEnemy(enemyItems.Enemys[maxEnemyCount - leftEnemyCount]);
- currentEnemyItems.AddEnemy(enemyItems.Enemys[maxEnemyCount - leftEnemyCount]);
- leftEnemyCount --;
- createEnemyPosition ++;
- currentEnemyCount ++;
- t1 = new Date();
- }
- }
- else if(createEnemyPosition == 1)
- {
- if((new Date()) - t2 > 2000)
- {
- enemyItems.Enemys[maxEnemyCount - leftEnemyCount].X = 240;
- enemyItems.Enemys[maxEnemyCount - leftEnemyCount].Y = 0;
- startNewEnemy(enemyItems.Enemys[maxEnemyCount - leftEnemyCount]);
- currentEnemyItems.AddEnemy(enemyItems.Enemys[maxEnemyCount - leftEnemyCount]);
- leftEnemyCount --;
- createEnemyPosition ++;
- currentEnemyCount ++;
- t2 = new Date();
- }
- }
- else if(createEnemyPosition == 2)
- {
- if((new Date()) - t3 > 2000)
- {
- enemyItems.Enemys[maxEnemyCount - leftEnemyCount].X = 480;
- enemyItems.Enemys[maxEnemyCount - leftEnemyCount].Y = 0;
- startNewEnemy(enemyItems.Enemys[maxEnemyCount - leftEnemyCount]);
- currentEnemyItems.AddEnemy(enemyItems.Enemys[maxEnemyCount - leftEnemyCount]);
- leftEnemyCount --;
- createEnemyPosition = 0;
- currentEnemyCount ++;
- t3 = new Date();
- }
- }
- }
- //estimate player is win?
- else if(leftEnemyCount == 0 && currentEnemyCount == 0)
- {
- with(parameter)
- {
- clearInterval(timer);
- setTimeout("",1,"");
- }
- document.getElementById("gamewin").style.display = "block";
- }
- }
- //change tank's direction
- function changeDirection(t, e, d)
- {
- if(e.Direction != d)
- {
- e.Direction = d;
- t.innerHTML = "<img src=/"images/" + e.Type + "_" + e.Direction + ".png/" width=/"32/" height=/"32/" />";
- }
- }
- //tank fire
- function fire(o, w)
- {
- if((new Date()) - o.FireTime > o.FireSpeed)
- {
- switch(o.Direction)
- {
- case "left":
- startNewCannonBall(new Cannonball(cannonSpeed,"",o.Direction, 1, w, document.getElementById(o.ID).style.posLeft, document.getElementById(o.ID).style.posTop + 12));
- break;
- case "right":
- startNewCannonBall(new Cannonball(cannonSpeed,"",o.Direction, 1, w, document.getElementById(o.ID).style.posLeft + 24, document.getElementById(o.ID).style.posTop + 12));
- break;
- case "up":
- startNewCannonBall(new Cannonball(cannonSpeed,"",o.Direction, 1, w, document.getElementById(o.ID).style.posLeft + 12, document.getElementById(o.ID).style.posTop));
- break;
- case "down":
- startNewCannonBall(new Cannonball(cannonSpeed,"",o.Direction, 1, w, document.getElementById(o.ID).style.posLeft + 12, document.getElementById(o.ID).style.posTop + 24));
- break;
- }
- o.FireTime = new Date();
- }
- }
- //function HitTank(t)
- //{
- // var px1 = document.getElementById(player.ID).style.posTop;
- // var py1 = document.getElementById(player.ID).style.posLeft;
- // var x1 = document.getElementById(t.ID).style.posTop;
- // var y1 = document.getElementById(t.ID).style.posLeft;
- // //window.status = x1 + "_" + y1 + "_" + px1 + "_" + py1;
- // if(t.Direction == "left")
- // {
- // if(y1 - py1 < t.Speed && px1 < x1 + 32 && px1 > x1 -32)
- // return true;
- // }
- // else if(t.Direction == "right")
- // {
- // if(py1 - y1 < t.Speed + 32 && px1 < x1 + 32 && px1 > x1 -32)
- // return true;
- // }
- // else if(t.Direction == "up")
- // {
- // if(px1 - x1 < t.Speed && py1 < y1 + 32 && py1 > y1 -32)
- // return true;
- // }
- // else if(t.Direction == "down")
- // {
- // if(px1 - x1 < t.Speed + 32 && py1 < y1 + 32 && py1 > y1 -32)
- // return true;
- // }
- //
- // for(var i = 0; i < currentEnemyItems.Enemys.length; i ++)
- // {
- // if(currentEnemyItems.Enemys[i].ID != t.ID)
- // {
- // var x = document.getElementById(currentEnemyItems.Enemys[i].ID).style.posTop;
- // var y = document.getElementById(currentEnemyItems.Enemys[i].ID).style.posLeft;
- //
- // if(t.Direction == "left")
- // {
- // if(y1 - y < t.Speed && x < x1 + 32 && x > x1 -32)
- // return true;
- // }
- // else if(t.Direction == "right")
- // {
- // if(y - y1 < t.Speed + 32 && x < x1 + 32 && x > x1 -32)
- // return true;
- // }
- // else if(t.Direction == "up")
- // {
- // if(x - x1 < t.Speed && y < y1 + 32 && y > y1 -32)
- // return true;
- // }
- // else if(t.Direction == "down")
- // {
- // if(x - x1 < t.Speed + 32 && y < y1 + 32 && y > y1 -32)
- // return true;
- // }
- // }
- // }
- // return false;
- //}
- //each enemy is virtual thread
- function startNewEnemy(e)
- {
- var target = document.getElementById("Enemy").cloneNode(true);
- with (target){
- var type = (e.Type=="heavy")?"heavy":(e.Type=="normal"?"normal":"light");
- id=e.ID;style.display="block";style.zIndex=e.ID + 5000;style.position="absolute";style.posLeft=e.X;style.posTop=e.Y;style.width=32;style.height=32;innerHTML="<img src=/"images/" + type + "_" + e.Direction + ".png/" width=/"32/" height=/"32/" />";
- }
- document.body.insertBefore(target,document.body.lastChild);
- var parameter = {target:target,e:e}
- parameter.timer = setInterval(EnemyMove,1,parameter);
- }
- function EnemyMove(parameter)
- {
- if(statePlaying == "pause" || statePlaying == "failed")
- return;
- with(parameter)
- {
- var y = (document.getElementById(target.id).style.posLeft - (document.getElementById(target.id).style.posLeft%16)) / 16;
- var x = (document.getElementById(target.id).style.posTop - (document.getElementById(target.id).style.posTop%16)) / 16;
- var y1 = document.getElementById(target.id).style.posLeft%16;
- var x1 = document.getElementById(target.id).style.posTop%16;
- if(e.Direction == "left")
- {
- // if(HitTank(e))
- // {
- // changeDirection(target, e, direction[parseInt(4*Math.random())]);
- // }
- // else
- if(y > 0 && x1 == 0 && map[x][y - 1].Cross != 1 && map[x + 1][y - 1].Cross != 1)
- {
- document.getElementById(target.id).style.posLeft -= parseInt(e.Speed, 10);
- }
- else if(y > 0 && x != 0 && map[x][y - 1].Cross != 1 && map[x + 1][y - 1].Cross != 1 && map[x + 2][y - 1].Cross != 1)
- {
- document.getElementById(target.id).style.posLeft -= parseInt(e.Speed, 10);
- }
- else if(y1 > 0)
- {
- document.getElementById(target.id).style.posLeft -= parseInt(e.Speed, 10);
- }
- else if(y == 0 && document.getElementById(target.id).style.posLeft > 0)
- {
- document.getElementById(target.id).style.posLeft -= parseInt(e.Speed, 10);
- }
- else
- {
- //fire or change direction
- if((parseInt(100*Math.random()))%100 < 30)
- {
- changeDirection(target, e, direction[parseInt(4*Math.random())]);
- }
- else
- {
- fire(e, "enemy");
- }
- }
- }
- else if(e.Direction == "right")
- {
- // if(HitTank(e))
- // {
- // changeDirection(target, e, direction[parseInt(4*Math.random())]);
- // }
- // else
- if(y < (count-1)*2 && x1 == 0 && map[x][y + 2].Cross != 1 && map[x + 1][y + 2].Cross != 1)
- {
- document.getElementById(target.id).style.posLeft += parseInt(e.Speed, 10);
- }
- else if(y < (count-1)*2 && x1 != 0 && map[x][y + 2].Cross != 1 && map[x + 1][y + 2].Cross != 1 && map[x + 2][y + 2].Cross != 1)
- {
- document.getElementById(target.id).style.posLeft += parseInt(e.Speed, 10);
- }
- else if(y == (count-1)*2 && document.getElementById(target.id).style.posLeft < 480)
- {
- document.getElementById(target.id).style.posLeft += parseInt(e.Speed, 10);
- }
- else
- {
- //fire or change direction
- if((parseInt(100*Math.random()))%100 < 30)
- {
- changeDirection(target, e, direction[parseInt(4*Math.random())]);
- }
- else
- {
- fire(e, "enemy");
- }
- }
- }
- else if(e.Direction == "up")
- {
- // if(HitTank(e))
- // {
- // changeDirection(target, e, direction[parseInt(4*Math.random())]);
- // }
- // else
- if(x > 0 && y1 == 0 && map[x - 1][y].Cross != 1 && map[x - 1][y + 1].Cross != 1)
- {
- document.getElementById(target.id).style.posTop -= parseInt(e.Speed, 10);
- }
- else if(x > 0 && y1 != 0 && map[x - 1][y].Cross != 1 && map[x - 1][y + 1].Cross != 1 && map[x - 1][y + 2].Cross)
- {
- document.getElementById(target.id).style.posTop -= parseInt(e.Speed, 10);
- }
- else if(x1 > 0)
- {
- document.getElementById(target.id).style.posTop -= parseInt(e.Speed, 10);
- }
- else if(x == 0 && document.getElementById(target.id).style.posTop > 0)
- {
- document.getElementById(target.id).style.posTop -= parseInt(e.Speed, 10);
- }
- else
- {
- //fire or change direction
- if((parseInt(100*Math.random()))%100 < 30)
- {
- changeDirection(target, e, direction[parseInt(4*Math.random())]);
- }
- else
- {
- fire(e, "enemy");
- }
- }
- }
- else
- {
- // if(HitTank(e))
- // {
- // changeDirection(target, e, direction[parseInt(4*Math.random())]);
- // }
- // else
- if(x < (count - 1) * 2 && y1 == 0 && map[x + 2][y].Cross != 1 && map[x + 2][y + 1].Cross != 1)
- {
- document.getElementById(target.id).style.posTop += parseInt(e.Speed, 10);
- }
- else if(x < (count - 1) * 2 && y1 != 0 && map[x + 2][y].Cross != 1 && map[x + 2][y + 1].Cross != 1 && map[x + 2][y + 2].Cross != 1)
- {
- document.getElementById(target.id).style.posTop += parseInt(e.Speed, 10);
- }
- else if(x == (count -1)*2 && document.getElementById(target.id).style.posTop < 480)
- {
- document.getElementById(target.id).style.posTop += parseInt(e.Speed, 10);
- }
- else
- {
- //fire or change direction
- if((parseInt(100*Math.random()))%100 < 30)
- {
- changeDirection(target, e, direction[parseInt(4*Math.random())]);
- }
- else
- {
- fire(e, "enemy");
- }
- }
- }
- if(((new Date()) - e.FireTime) > e.AutoFireSpeed)
- {
- if((parseInt(100*Math.random()))%100 < 30)
- {
- changeDirection(target, e, direction[parseInt(4*Math.random())]);
- e.FireTime = new Date();
- }
- else
- {
- fire(e, "enemy");
- }
- }
- if(e.HP <= 0)
- {
- clearInterval(timer);
- if(e.Type == "heavy")
- {
- document.getElementById("heavyEnemy").innerHTML = parseInt(document.getElementById("heavyEnemy").innerHTML, 10) - 1;
- }
- else if(e.Type == "normal")
- {
- document.getElementById("normalEnemy").innerHTML = parseInt(document.getElementById("normalEnemy").innerHTML, 10) - 1;
- }
- else if(e.Type == "light")
- {
- document.getElementById("lightEnemy").innerHTML = parseInt(document.getElementById("lightEnemy").innerHTML, 10) - 1;
- }
- document.getElementById("enemyTotalCount").innerHTML = parseInt(document.getElementById("enemyTotalCount").innerHTML, 10) - 1;
- currentEnemyItems.RemoveEnemy(e);
- currentEnemyCount --;
- target.innerHTML="<img src=/"images/explode.png/" width=/"32/" height=/"32/" />";
- setTimeout(function(elm){document.body.removeChild(elm);},100,target);
- }
- }
- }
- function startNewPlayer(p)
- {
- var parameter = {target:p}
- parameter.timer = setInterval(PlayerMove,1,parameter);
- }
- function PlayerMove(parameter)
- {
- if(player.HP <= 0)
- {
- with(parameter)
- {
- document.getElementById(player.ID).innerHTML="<img src=/"images/explode.png/" width=/"32/" height=/"32/" />";
- clearInterval(timer);
- player.Life --;
- document.getElementById("playerLife").innerHTML = player.Life;
- setTimeout(function(){
- if(player.Life > 0)
- {
- document.getElementById(player.ID).style.posLeft = 192;
- document.getElementById(player.ID).style.posTop = 480;
- document.getElementById(player.ID).innerHTML="<img src=/"images/player_up.png/" width=/"32/" height=/"32/" />";
- player.Direction = "up";
- player.HP = 1;
- startNewPlayer(player);
- }
- else
- {
- statePlaying="failed";
- document.getElementById("gameover").style.display = "block";
- with(parameter)
- {
- clearInterval(timer);
- setTimeout("",1,target);
- }
- }},100,"");
- }
- }
- if(!newkey)
- return;
- newkey = false;
- var y = (document.getElementById(player.ID).style.posLeft - (document.getElementById(player.ID).style.posLeft%16)) / 16;
- var x = (document.getElementById(player.ID).style.posTop - (document.getElementById(player.ID).style.posTop%16)) / 16;
- var y1 = document.getElementById(player.ID).style.posLeft%16;
- var x1 = document.getElementById(player.ID).style.posTop%16;
- switch(kc)
- {
- case 37:
- if(player.Direction == "left")
- {
- if(y > 0 && x1 == 0 && map[x][y - 1].Cross != 1 && map[x + 1][y - 1].Cross != 1)
- {
- document.getElementById(player.ID).style.posLeft -= parseInt(player.Speed, 10);
- }
- else if(y > 0 && x != 0 && map[x][y - 1].Cross != 1 && map[x + 1][y - 1].Cross != 1 && map[x + 2][y - 1].Cross != 1)
- {
- document.getElementById(player.ID).style.posLeft -= parseInt(player.Speed, 10);
- }
- else if(y1 > 0)
- {
- document.getElementById(player.ID).style.posLeft -= parseInt(player.Speed, 10);
- }
- else if(y == 0 && document.getElementById(player.ID).style.posLeft > 0)
- {
- document.getElementById(player.ID).style.posLeft -= parseInt(player.Speed, 10);
- }
- // PlaySound("play","playerMove");
- }
- else
- {
- document.getElementById(player.ID).innerHTML = document.getElementById(player.ID).innerHTML.replace(player.Direction, "left");
- player.Direction = "left";
- }
- break;
- case 39:
- if(player.Direction == "right")
- {
- if(y < (count-1)*2 && x1 == 0 && map[x][y + 2].Cross != 1 && map[x + 1][y + 2].Cross != 1)
- {
- document.getElementById(player.ID).style.posLeft += parseInt(player.Speed, 10);
- }
- else if(y < (count-1)*2 && x1 != 0 && map[x][y + 2].Cross != 1 && map[x + 1][y + 2].Cross != 1 && map[x + 2][y + 2].Cross != 1)
- {
- document.getElementById(player.ID).style.posLeft += parseInt(player.Speed, 10);
- }
- else if(y == (count-1)*2 && document.getElementById(player.ID).style.posLeft < 480)
- {
- document.getElementById(player.ID).style.posLeft += parseInt(player.Speed, 10);
- }
- // PlaySound("play","playerMove");
- }
- else
- {
- document.getElementById(player.ID).innerHTML = document.getElementById(player.ID).innerHTML.replace(player.Direction, "right");
- player.Direction = "right";
- }
- break;
- case 38:
- if(player.Direction == "up")
- {
- if(x > 0 && y1 == 0 && map[x - 1][y].Cross != 1 && map[x - 1][y + 1].Cross != 1)
- {
- document.getElementById(player.ID).style.posTop -= parseInt(player.Speed, 10);
- }
- else if(x > 0 && y1 != 0 && map[x - 1][y].Cross != 1 && map[x - 1][y + 1].Cross != 1 && map[x - 1][y + 2].Cross)
- {
- document.getElementById(player.ID).style.posTop -= parseInt(player.Speed, 10);
- }
- else if(x1 > 0)
- {
- document.getElementById(player.ID).style.posTop -= parseInt(player.Speed, 10);
- }
- else if(x == 0 && document.getElementById(player.ID).style.posTop > 0)
- {
- document.getElementById(player.ID).style.posTop -= parseInt(player.Speed, 10);
- }
- // PlaySound("play","playerMove");
- }
- else
- {
- document.getElementById(player.ID).innerHTML = document.getElementById(player.ID).innerHTML.replace(player.Direction, "up");
- player.Direction = "up";
- }
- break;
- case 40:
- if(player.Direction == "down")
- {
- if(x < (count - 1) * 2 && y1 == 0 && map[x + 2][y].Cross != 1 && map[x + 2][y + 1].Cross != 1)
- {
- document.getElementById(player.ID).style.posTop += parseInt(player.Speed, 10);
- }
- else if(x < (count - 1) * 2 && y1 != 0 && map[x + 2][y].Cross != 1 && map[x + 2][y + 1].Cross != 1 && map[x + 2][y + 2].Cross != 1)
- {
- document.getElementById(player.ID).style.posTop += parseInt(player.Speed, 10);
- }
- else if(x == (count -1)*2 && document.getElementById(player.ID).style.posTop < 480)
- {
- document.getElementById(player.ID).style.posTop += parseInt(player.Speed, 10);
- }
- // PlaySound("play","playerMove");
- }
- else
- {
- document.getElementById(player.ID).innerHTML = document.getElementById(player.ID).innerHTML.replace(player.Direction, "down");
- player.Direction = "down";
- }
- break;
- case 32:
- {
- fire(player, "player");
- }
- break;
- }
- }
- function startNewCannonBall(c){
- var target = document.getElementById("CannonBall").cloneNode(true);
- with (target){
- id="cannon_" + c.ID;style.display="block";style.zIndex=c.ID + 20000;style.position="absolute";style.posLeft=c.X;style.posTop=c.Y;style.width=8;style.height=8;innerHTML="<img src=/"images/cannonball_" + c.Direction + ".png/" width=/"8/" height=/"8/" />";
- }
- document.body.insertBefore(target,document.body.lastChild);
- var parameter = {target:target,c:c}
- parameter.timer = setInterval(CannonBallMove,1,parameter);
- }
- function CannonBallMove(parameter){
- if(statePlaying == "pause" || statePlaying == "failed")
- return;
- with (parameter){
- switch(c.Direction)
- {
- case "up":
- target.style.posTop -= c.Speed;
- break;
- case "down":
- target.style.posTop += c.Speed;
- break;
- case "left":
- target.style.posLeft -= c.Speed;
- break;
- case "right":
- target.style.posLeft += c.Speed;
- break;
- }
- Hit(c);
- if (target.style.posLeft > 512 || target.style.posTop > 512 || target.style.posLeft < -8 || target.style.posTop < -8 || !c.Active){
- clearInterval(timer);
- target.innerHTML="<img src=/"images/explode.png/" width=/"8/" height=/"8/" />";
- setTimeout(function(elm){document.body.removeChild(elm)},100,target);
- }
- }
- }
- function Graphics(parent)
- {
- this.P = parent;
- this.HTML = "";
- this.DrawImage = function(id,imgSrc, x, y, w, h,z,a)
- {
- this.HTML += '<div id="'+ id + '" style="z-index:' + z + ';position:absolute;'+
- 'left:' + x + 'px;'+
- 'top:' + y + 'px;'+
- (w? ('width:' + w + 'px;') : '') +
- (h? ('height:' + h + 'px;'):'')+'">'+
- '<img src="' + imgSrc +'"'+ (w ? (' width="' + w + '"'):'')+ (h ? (' height="' + h + '"'):'') + ('alt=' + y/16 + ':' + x/16 + '') + ' />'+
- '<//div>';
- };
- //背景图片擦除
- this.Earse = function(id, imgSrc,w, h, z)
- {
- document.getElementById(id).style.zIndex = z;
- document.getElementById(id).innerHTML ='<img src="' + imgSrc +'"'+ (w ? (' width="' + w + '"'):'')+ (h ? (' height="' + h + '"'):'') + ' />';
- };
- this.Paint = function()
- {
- thisthis.P.innerHTML = this.HTML;
- };
- }
- function MapItem(type, src, row, col, cross,r)
- {
- this.ID = objectid ++;
- this.Type = type;
- this.Src = src;
- this.Row = row;
- this.Col = col;
- this.Cross = cross;
- this.Recovery = r;
- }
- function Barrier(name, type, recovery, cross, src)
- {
- this.ID = objectid ++;
- this.Name = name;
- this.Type = type;
- this.Recovery = recovery;
- this.Cross = cross;
- this.Src = src;
- }
- function Enemy(name, src, speed, power, hp, t, d)
- {
- this.ID = objectid ++;
- this.Name = name;
- this.Src = src;
- this.Speed = speed;
- this.Power = power;
- this.HP = hp;
- tthis.Type = t;
- this.Direction = d;
- this.X = 0;
- this.Y = 0;
- this.FireSpeed = 400;
- this.AutoFireSpeed = 2000;
- this.FireTime = new Date();
- }
- function Player(name, src, speed, power, hp, life)
- {
- this.ID = objectid ++;
- this.Name = name;
- this.Src = src;
- this.Speed = speed;
- this.Power = power;
- this.HP = hp;
- this.Life = life;
- this.Direction = "";
- this.X = 0;
- this.Y = 0;
- this.FireSpeed = 400;
- this.FireTime = new Date();
- }
- function Cannonball(speed,src,d,p,o,x,y)
- {
- this.ID = objectid ++;
- this.Speed = speed;
- this.Src = src;
- this.Direction = d;
- this.Power = p;
- this.Owner = o;
- this.X = x;
- this.Y = y;
- this.Active = true;
- }
- function OtherItem(name, src)
- {
- this.ID = objectid ++;
- this.Name = name;
- this.Src = src;
- }
- function BarrierList()
- {
- this.Barriers = new Array();
- this.AddBarrier = function(barrier)
- {
- this.Barriers.push(barrier);
- };
- }
- function EnemyList()
- {
- this.Enemys = new Array();
- this.AddEnemy = function(enemy)
- {
- this.Enemys.push(enemy);
- };
- this.RemoveEnemy = function(enemy)
- {
- var newnewEnemys = new Array();
- for(var i = 0; i < this.Enemys.length; i ++)
- {
- if(enemy.ID == this.Enemys[i].ID)
- {
- continue;
- }
- newEnemys.push(this.Enemys[i]);
- }
- this.Enemys = newEnemys;
- };
- }
- function setBase(src, type, cross,recovery, size)
- {
- tankDraw.Earse(map[31][14].ID, src, size, size, map[31][14].ID);
- tankDraw.Earse(map[30][14].ID, src, size, size, map[30][14].ID);
- tankDraw.Earse(map[29][14].ID, src, size, size, map[29][14].ID);
- tankDraw.Earse(map[29][15].ID, src, size, size, map[29][15].ID);
- tankDraw.Earse(map[29][16].ID, src, size, size, map[29][16].ID);
- tankDraw.Earse(map[29][17].ID, src, size, size, map[29][17].ID);
- tankDraw.Earse(map[30][17].ID, src, size, size, map[30][17].ID);
- tankDraw.Earse(map[31][17].ID, src, size, size, map[31][17].ID);
- map[31][14].Type = type;
- map[31][14].Cross = cross;
- map[31][14].Recovery = recovery;
- map[30][14].Type = type;
- map[30][14].Cross = cross;
- map[30][14].Recovery = recovery;
- map[29][14].Type = type;
- map[29][14].Cross = cross;
- map[29][14].Recovery = recovery;
- map[29][15].Type = type;
- map[29][15].Cross = cross;
- map[29][15].Recovery = recovery;
- map[29][16].Type = type;
- map[29][16].Cross = cross;
- map[29][16].Recovery = recovery;
- map[29][17].Type = type;
- map[29][17].Cross = cross;
- map[29][17].Recovery = recovery;
- map[31][17].Type = type;
- map[31][17].Cross = cross;
- map[31][17].Recovery = recovery;
- map[30][17].Type = type;
- map[30][17].Cross = cross;
- map[30][17].Recovery = recovery;
- }
- function Tank()
- {
- xmlDoc = null;
- barrierItems = new BarrierList();
- size = null;
- bgColor = null;
- count = null;
- LoadValueIE = function()
- {
- if(xmlDoc != null)
- {
- //栅栏类型,配置文件按type排序
- var barrier = xmlDoc.selectNodes("//TankConfig/Barrier/BarrierItem");
- for(var i = 0; i < barrier.length; i ++)
- {
- barrierItems.AddBarrier(new Barrier(barrier.item(i).attributes(0).value, barrier.item(i).attributes(1).value, barrier.item(i).attributes(2).value, barrier.item(i).attributes(3).value, barrier.item(i).attributes(4).value));
- }
- //敌人配置
- var enemys = xmlDoc.selectNodes("//TankConfig/Enemy/EnemyItem");
- //重型数量
- var heavy = parseInt(enemys.item(0).attributes(1).value, 10);
- document.getElementById("heavyEnemy").innerHTML = heavy;
- //一般
- var normal = parseInt(enemys.item(1).attributes(1).value, 10);
- document.getElementById("normalEnemy").innerHTML = normal;
- //轻型
- var light = parseInt(enemys.item(2).attributes(1).value, 10);
- document.getElementById("lightEnemy").innerHTML = light;
- var total = heavy + normal + light;
- document.getElementById("enemyTotalCount").innerHTML = total;
- //打乱出场顺序
- var enemysarray = new Array(total);
- for(var i = 0; i < total; i ++)
- {
- enemysarray[i] = i;
- }
- leftEnemyCount = total;
- maxEnemyCount = total;
- for(var i = 0; i < total; i ++)
- {
- var j = Math.floor(((Math.random()*total)) % total);
- var temp = enemysarray[i];
- enemysarray[i] = enemysarray[j];
- enemysarray[j] = temp;
- }
- for(var i = 0; i < total; i ++)
- {
- if(enemysarray[i] < heavy)
- enemyItems.AddEnemy(new Enemy(enemys.item(0).attributes(0).value, enemys.item(0).attributes(2).value.replace("heavy","heavy_down"), enemys.item(0).attributes(3).value, enemys.item(0).attributes(4).value, enemys.item(0).attributes(5).value,"heavy", "down"));
- else if(enemysarray[i] < heavy + normal)
- enemyItems.AddEnemy(new Enemy(enemys.item(1).attributes(0).value, enemys.item(1).attributes(2).value.replace("normal","normal_down"), enemys.item(1).attributes(3).value, enemys.item(1).attributes(4).value, enemys.item(1).attributes(5).value, "normal", "down"));
- else if(enemysarray[i] < total)
- enemyItems.AddEnemy(new Enemy(enemys.item(2).attributes(0).value, enemys.item(2).attributes(2).value.replace("light","light_down"), enemys.item(2).attributes(3).value, enemys.item(2).attributes(4).value, enemys.item(2).attributes(5).value, "light", "down"));
- }
- //玩家
- var players = xmlDoc.selectNodes("//TankConfig/Player");
- player = new Player(players.item(0).attributes(0).value, players.item(0).attributes(1).value, players.item(0).attributes(2).value, players.item(0).attributes(3).value, players.item(0).attributes(4).value, players.item(0).attributes(5).value);
- document.getElementById("playerLife").innerHTML = player.Life;
- //地图
- var maps = xmlDoc.selectNodes("//TankConfig/Map");
- size = parseInt(maps.item(0).attributes(0).value, 10);
- bgColor = maps.item(0).attributes(1).value;
- count = parseInt(maps.item(0).attributes(2).value, 10);
- map = new Array(count * 2);
- for(var i = 0; i < count * 2; i ++)
- {
- map[i] = new Array(count * 2);
- }
- var rows = xmlDoc.selectNodes("//TankConfig/Map/Rows");
- for(var i = 0; i < rows.length; i ++)
- {
- var rowNumber = parseInt(rows.item(i).attributes(0).value, 10);
- for(var j = 0; j < rows.item(i).childNodes.length; j ++)
- {
- var colNumber = parseInt(rows.item(i).childNodes.item(j).attributes(0).value, 10);
- var type = parseInt(rows.item(i).childNodes.item(j).attributes(1).value, 10);
- var cross = barrierItems.Barriers[parseInt(rows.item(i).childNodes.item(j).attributes(1).value, 10)].Cross;
- var r = barrierItems.Barriers[parseInt(rows.item(i).childNodes.item(j).attributes(1).value, 10)].Recovery;
- map[rowNumber*2][colNumber*2] = new MapItem(type, barrierItems.Barriers[type].Src, rowNumber, colNumber, cross,r);
- map[rowNumber*2 + 1][colNumber*2] = new MapItem(type, barrierItems.Barriers[type].Src, rowNumber, colNumber, cross,r);
- map[rowNumber*2][colNumber*2 + 1] = new MapItem(type, barrierItems.Barriers[type].Src, rowNumber, colNumber, cross,r);
- map[rowNumber*2 + 1][colNumber*2 + 1] = new MapItem(type, barrierItems.Barriers[type].Src, rowNumber, colNumber, cross,r);
- }
- }
- }
- else
- {
- alert("请先导入配置文件");
- }
- };
- LoadValueFF = function()
- {
- };
- InitMap = function()
- {
- size /= 2;
- tankDraw = new Graphics(document.getElementById("Tank"));
- for(var i = 0; i < count; i ++)
- {
- for(var j = 0; j < count ; j ++)
- {
- if(map[i*2][j*2].Type == 3)
- {
- tankDraw.DrawImage(map[i*2][j*2].ID, map[i*2][j*2].Src, j*2 * size, i*2 * size, size, size, map[i*2][j*2].ID + 10000);
- tankDraw.DrawImage(map[i*2][j*2 + 1].ID, map[i*2][j*2 + 1].Src, (j*2 + 1) * size, i*2 * size, size, size, map[i*2][j*2 + 1].ID + 10000);
- tankDraw.DrawImage(map[i*2 + 1][j*2].ID, map[i*2][j*2].Src, j*2 * size, (i*2 + 1) * size, size, size, map[i*2 + 1][j*2].ID + 10000);
- tankDraw.DrawImage(map[i*2 + 1][j*2 + 1].ID, map[i*2][j*2].Src, (j*2 + 1) * size, (i*2 + 1) * size, size, size, map[i*2 + 1][j*2 + 1].ID + 10000);
- }
- else
- {
- tankDraw.DrawImage(map[i*2][j*2].ID, map[i*2][j*2].Src, j*2 * size, i*2 * size, size, size, map[i*2][j*2].ID);
- tankDraw.DrawImage(map[i*2][j*2 + 1].ID, map[i*2][j*2 + 1].Src, (j*2 + 1) * size, i*2 * size, size, size, map[i*2][j*2 + 1].ID);
- tankDraw.DrawImage(map[i*2 + 1][j*2].ID, map[i*2][j*2].Src, j*2 * size, (i*2 + 1) * size, size, size, map[i*2 + 1][j*2].ID);
- tankDraw.DrawImage(map[i*2 + 1][j*2 + 1].ID, map[i*2][j*2].Src, (j*2 + 1) * size, (i*2 + 1) * size, size, size, map[i*2 + 1][j*2 + 1].ID);
- }
- }
- }
- tankDraw.DrawImage(15000, "images/basecamp.png", 15*16, 30*16, 32, 32, 15000);
- map[30][15].Cross = 1;
- map[30][16].Cross = 1;
- map[31][15].Cross = 1;
- map[31][16].Cross = 1;
- tankDraw.DrawImage(player.ID, player.Src.replace("player","player_up"), 12 * size, 30 * size, size*2, size*2,player.ID + 3000);
- tankDraw.Paint();
- //擦除enemy起始位置
- var i = 0;
- var j = 0;
- tankDraw.Earse(map[i][j].ID, "images/flat.png", size, size, map[i][j].ID);
- tankDraw.Earse(map[i + 1][j].ID, "images/flat.png", size, size, map[i][j + 1].ID);
- tankDraw.Earse(map[i + 1][j].ID, "images/flat.png", size, size, map[i + 1][j].ID);
- tankDraw.Earse(map[i + 1][j + 1].ID, "images/flat.png", size, size, map[i + 1][j + 1].ID);
- map[i][j].Cross = 0;
- map[i + 1][j].Cross = 0;
- map[i][j + 1].Cross = 0;
- map[i + 1][j + 1].Cross = 0;
- map[i][j].Type = 0;
- map[i + 1][j].Type = 0;
- map[i][j + 1].Type = 0;
- map[i + 1][j + 1].Type = 0;
- map[i][j].Recovery = 0;
- map[i + 1][j].Recovery = 0;
- map[i][j + 1].Recovery = 0;
- map[i + 1][j + 1].Recovery = 0;
- i = 0;
- j = 15;
- tankDraw.Earse(map[i][j].ID, "images/flat.png", size, size, map[i][j].ID);
- tankDraw.Earse(map[i + 1][j].ID, "images/flat.png", size, size, map[i][j + 1].ID);
- tankDraw.Earse(map[i + 1][j].ID, "images/flat.png", size, size, map[i + 1][j].ID);
- tankDraw.Earse(map[i + 1][j + 1].ID, "images/flat.png", size, size, map[i + 1][j + 1].ID);
- map[i][j].Cross = 0;
- map[i + 1][j].Cross = 0;
- map[i][j + 1].Cross = 0;
- map[i + 1][j + 1].Cross = 0;
- map[i][j].Type = 0;
- map[i + 1][j].Type = 0;
- map[i][j + 1].Type = 0;
- map[i + 1][j + 1].Type = 0;
- map[i][j].Recovery = 0;
- map[i + 1][j].Recovery = 0;
- map[i][j + 1].Recovery = 0;
- map[i + 1][j + 1].Recovery = 0;
- i = 0;
- j = 30;
- tankDraw.Earse(map[i][j].ID, "images/flat.png", size, size, map[i][j].ID);
- tankDraw.Earse(map[i + 1][j].ID, "images/flat.png", size, size, map[i][j + 1].ID);
- tankDraw.Earse(map[i + 1][j].ID, "images/flat.png", size, size, map[i + 1][j].ID);
- tankDraw.Earse(map[i + 1][j + 1].ID, "images/flat.png", size, size, map[i + 1][j + 1].ID);
- map[i][j].Cross = 0;
- map[i + 1][j].Cross = 0;
- map[i][j + 1].Cross = 0;
- map[i + 1][j + 1].Cross = 0;
- map[i][j].Type = 0;
- map[i + 1][j].Type = 0;
- map[i][j + 1].Type = 0;
- map[i + 1][j + 1].Type = 0;
- map[i][j].Recovery = 0;
- map[i + 1][j].Recovery = 0;
- map[i][j + 1].Recovery = 0;
- map[i + 1][j + 1].Recovery = 0;
- //player
- i = 30;
- j = 12;
- tankDraw.Earse(map[i][j].ID, "images/flat.png", size, size, map[i][j].ID);
- tankDraw.Earse(map[i + 1][j].ID, "images/flat.png", size, size, map[i][j + 1].ID);
- tankDraw.Earse(map[i + 1][j].ID, "images/flat.png", size, size, map[i + 1][j].ID);
- tankDraw.Earse(map[i + 1][j + 1].ID, "images/flat.png", size, size, map[i + 1][j + 1].ID);
- map[i][j].Cross = 0;
- map[i + 1][j].Cross = 0;
- map[i][j + 1].Cross = 0;
- map[i + 1][j + 1].Cross = 0;
- map[i][j].Type = 0;
- map[i + 1][j].Type = 0;
- map[i][j + 1].Type = 0;
- map[i + 1][j + 1].Type = 0;
- map[i][j].Recovery = 0;
- map[i + 1][j].Recovery = 0;
- map[i][j + 1].Recovery = 0;
- map[i + 1][j + 1].Recovery = 0;
- //base
- setBase("images/wall.png", 1, 1, 1,size);
- size *= 2;
- };
- InitPlayer = function()
- {
- player.Direction = "up";
- player.X = 30;
- player.Y = 12;
- startNewPlayer(player)
- };
- AddEventHandler = function(oTarget, sEventType, fnHandler)
- {
- if (oTarget.addEventListener)
- {
- oTarget.addEventListener(sEventType, fnHandler, false);
- }
- else if (oTarget.attachEvent)
- {
- oTarget.attachEvent("on" + sEventType, fnHandler);
- }
- else
- {
- oTarget["on" + sEventType] = fnHandler;
- }
- };
- PlayerKeyHandle = function()
- {
- kc = event.keyCode;
- if(kc == 13)
- {
- if(statePlaying == "playing" || statePlaying == "none")
- statePlaying = "pause";
- else if(statePlaying == "pause")
- statePlaying = "playing";
- window.status = statePlaying;
- }
- if(statePlaying == "pause" || statePlaying == "failed")
- return;
- newkey = true;
- }
- this.LoadConfig = function(filename)
- {
- if(window.ActiveXObject)
- {
- xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
- xmlDoc.async = "false";
- xmlDoc.load(filename);
- if(xmlDoc.parseError.errorCode !== 0)
- {
- alert("Tank配置文件错误");
- return;
- }
- else
- {
- new LoadValueIE();
- }
- }
- else if(document.implementation && document.implementation.createDocument)
- {
- xmlDoc = document.implementation.createDocument("", "TankConfig", null);
- xmlDoc.load(filename);
- xmlDoc.onLoad = LoadValueFF;
- }
- else
- {
- alert("该浏览器目前不支持");
- }
- };
- this.Play = function()
- {
- new InitMap();
- new InitPlayer();
- AddEventHandler(document, "keydown", PlayerKeyHandle);
- startEnemyControl();
- };
- }
- function Hit(c)
- {
- var target = document.getElementById("cannon_" + c.ID);
- var y = (target.style.posLeft - (target.style.posLeft%16)) / 16;
- var x = (target.style.posTop - (target.style.posTop%16)) / 16;
- var y1 = (target.style.posLeft + 8 - ((target.style.posLeft+8)%16)) / 16;
- var x1 = (target.style.posTop + 8 - ((target.style.posTop+8)%16)) / 16;
- if(y<0||x<0||y1<0||x1<0)
- return;
- if(y>31||x>31||x1>31||y1>31)
- return;
- if((x<=31&&x>=30&&y<=16&&y>=15) || (x1<=31&&x1>=30&&y1<=16&&y1>=15))
- {
- document.getElementById(15000).innerHTML = "<img src=/"images/basedestory.png/" width=/"32/" height=/"32/" />";
- statePlaying="failed";
- document.getElementById("gameover").style.display = "block";
- }
- if(c.Owner == "player")
- {
- for(var i = 0; i < currentEnemyItems.Enemys.length; i ++)
- {
- var ex1 = document.getElementById(currentEnemyItems.Enemys[i].ID).style.posTop;
- var ey1 = document.getElementById(currentEnemyItems.Enemys[i].ID).style.posLeft;
- if(target.style.posLeft > ey1 && target.style.posLeft < ey1 + 32 && target.style.posTop < ex1 + 32 && target.style.posTop > ex1)
- {
- c.Active = false;
- currentEnemyItems.Enemys[i].HP = 0;
- break;
- }
- }
- }
- else if(c.Owner == "enemy")
- {
- var px1 = document.getElementById(player.ID).style.posTop;
- var py1 = document.getElementById(player.ID).style.posLeft;
- if(target.style.posLeft > py1 && target.style.posLeft < py1 + 32 && target.style.posTop < px1 + 32 && target.style.posTop > px1)
- {
- c.Active = false;
- player.HP = 0;
- }
- }
- if(c.Direction == "left")
- {
- if(x == x1 && (map[x][y].Type == 1 || map[x][y].Type == 2))
- {
- if(c.Power >= map[x][y].Recovery)
- {
- tankDraw.Earse(map[x][y].ID, "images/flat.png", 16, 16, map[x][y].ID);
- map[x][y].Cross = 0;
- map[x][y].Type = 0;
- map[x][y].Recovery = 0;
- }
- c.Active = false;
- }
- else if(x!=x1 && (map[x][y].Type == 1 || map[x][y].Type == 2) || (map[x1][y].Type == 1 || map[x1][y].Type == 2))
- {
- if(c.Power >= map[x][y].Recovery && map[x][y].Recovery != 0)
- {
- tankDraw.Earse(map[x][y].ID, "images/flat.png", 16, 16, map[x][y].ID);
- map[x][y].Cross = 0;
- map[x][y].Type = 0;
- map[x][y].Recovery = 0;
- }
- if(c.Power >= map[x1][y].Recovery && map[x1][y].Recovery != 0)
- {
- tankDraw.Earse(map[x1][y].ID, "images/flat.png", 16, 16, map[x1][y].ID);
- map[x1][y].Cross = 0;
- map[x1][y].Type = 0;
- map[x1][y].Recovery = 0;
- }
- c.Active = false;
- }
- }
- else if(c.Direction == "right")
- {
- if(x == x1 && (map[x1][y1].Type == 1 || map[x1][y1].Type == 2))
- {
- if(c.Power >= map[x1][y1].Recovery)
- {
- tankDraw.Earse(map[x1][y1].ID, "images/flat.png", 16, 16, map[x1][y1].ID);
- map[x1][y1].Cross = 0;
- map[x1][y1].Type = 0;
- map[x1][y1].Recovery = 0;
- }
- c.Active = false;
- }
- else if(x!=x1 && (map[x][y1].Type == 1 || map[x][y1].Type == 2) || (map[x1][y1].Type == 1 || map[x1][y1].Type == 2))
- {
- if(c.Power >= map[x][y1].Recovery && map[x][y1].Recovery != 0)
- {
- tankDraw.Earse(map[x][y1].ID, "images/flat.png", 16, 16, map[x][y1].ID);
- map[x][y1].Cross = 0;
- map[x][y1].Type = 0;
- map[x][y1].Recovery = 0;
- }
- if(c.Power >= map[x1][y1].Recovery && map[x1][y1].Recovery != 0)
- {
- tankDraw.Earse(map[x1][y1].ID, "images/flat.png", 16, 16, map[x1][y1].ID);
- map[x1][y1].Cross = 0;
- map[x1][y1].Type = 0;
- map[x1][y1].Recovery = 0;
- }
- c.Active = false;
- }
- }
- else if(c.Direction == "up")
- {
- if(y == y1 && (map[x][y].Type == 1 || map[x][y].Type == 2))
- {
- if(c.Power >= map[x][y].Recovery)
- {
- tankDraw.Earse(map[x][y].ID, "images/flat.png", 16, 16, map[x][y].ID);
- map[x][y].Cross = 0;
- map[x][y].Type = 0;
- map[x][y].Recovery = 0;
- }
- c.Active = false;
- }
- else if(y!=y1 && (map[x][y].Type == 1 || map[x][y].Type == 2 || map[x][y1].Type == 1 || map[x][y1].Type == 2))
- {
- if(c.Power >= map[x][y].Recovery && map[x][y].Recovery != 0)
- {
- tankDraw.Earse(map[x][y].ID, "images/flat.png", 16, 16, map[x][y].ID);
- map[x][y].Cross = 0;
- map[x][y].Type = 0;
- map[x][y].Recovery = 0;
- }
- if(c.Power >= map[x][y1].Recovery && map[x][y1].Recovery != 0)
- {
- tankDraw.Earse(map[x][y1].ID, "images/flat.png", 16, 16, map[x][y1].ID);
- map[x][y1].Cross = 0;
- map[x][y1].Type = 0;
- map[x][y1].Recovery = 0;
- }
- c.Active = false;
- }
- }
- else if(c.Direction == "down")
- {
- if(y == y1 && (map[x1][y1].Type == 1 || map[x1][y1].Type == 2))
- {
- if(c.Power >= map[x1][y1].Recovery)
- {
- tankDraw.Earse(map[x1][y1].ID, "images/flat.png", 16, 16, map[x1][y1].ID);
- map[x1][y1].Cross = 0;
- map[x1][y1].Type = 0;
- map[x1][y1].Recovery = 0;
- }
- c.Active = false;
- }
- else if(y!=y1 && (map[x1][y].Type == 1 || map[x1][y].Type == 2 || map[x1][y1].Type == 1 || map[x1][y1].Type == 2))
- {
- if(c.Power >= map[x1][y].Recovery && map[x1][y].Recovery != 0)
- {
- tankDraw.Earse(map[x1][y].ID, "images/flat.png", 16, 16, map[x1][y].ID);
- map[x1][y].Cross = 0;
- map[x1][y].Type = 0;
- map[x1][y].Recovery = 0;
- }
- if(c.Power >= map[x1][y1].Recovery && map[x1][y1].Recovery != 0)
- {
- tankDraw.Earse(map[x1][y1].ID, "images/flat.png", 16, 16, map[x1][y1].ID);
- map[x1][y1].Cross = 0;
- map[x1][y1].Type = 0;
- map[x1][y1].Recovery = 0;
- }
- c.Active = false;
- }
- }
- }
- function PlayGame()
- {
- tank.LoadConfig("tank.xml");
- tank.Play();
- }
- </script>
document对象来获取,这个可以在下一版优化。:-)
具体源码可以在resource下下载:
http://d.download.csdn.net/down/667431/chenyijiu