level 9
13506072314
楼主
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="Generator" content="EditPlus®">
<meta name="Author" content="">
<meta name="Keywords" content="">
<meta name="Description" content="">
<title>Document</title>
</head>
<body onkeydown="getCommand()">
<canvas id="tankmap" width="500px" height="500" style="background-color:black;"></canvas>
<script type="text/javascript" src="tankgame.js"></script>
<script type="text/javascript">
var mycanvas=document.getElementById("tankmap")
var cxt=mycanvas.getContext("2d")
//我的坦克
var hero=new Hero(40,40,0,heroColor);
//定义敌人的坦克
var enemyTanks=new Array();
for(var i=0;i<4;i++)
{
//创建坦克
var enemyTank=new EnemyTank((i+1)*50,0,2);
enemyTanks[i]=enemyTank;
//画出坦克
// drawTank(enemyTanks[i]);
}
//颜色数组
var heroColor=new Array("#ded284","yellow");
//坦克类
function Tank(x,y,direct,color){
this.x=x;
this.y=y;
this.speed=1;
this.direct=direct;
this.color=color;
//上
this. moveUp= function(){
this.y-=this.speed;
this.direct=0;
}
//又
this.moveRight=function(){
this.x+=this.speed;
this.direct=1;
}
//下
this.moveDown=function(){
this.y+=this.speed;
this.direct=2;
}
//左
this.moveLeft=function(){
this.x-=this.speed;
this.direct=3;
}
}
//定义一个Hero类
function Hero(x,y,direct,color){
this.tank=Tank;
this.tank(x,y,direct,color);
}
//定义一个EnemyTank类
function EnemyTank(x,y,direct,color){
this.tank=Tank;
this.tank(x,y,direct,color);
}
drawTank(hero);
//用户按键函数
function getCommand(){
var code=event.keyCode;
switch(code){
case 87:
hero.moveUp();
break;
case 68:
hero.moveRight();
break;
case 83:
hero.moveDown();
break;
case 65:
hero.moveLeft();
break;
}
cxt.clearRect(0,0,500,500);
drawTank(hero);
}
</script>
</body>
</html>
2017年08月23日 13点08分
1
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="Generator" content="EditPlus®">
<meta name="Author" content="">
<meta name="Keywords" content="">
<meta name="Description" content="">
<title>Document</title>
</head>
<body onkeydown="getCommand()">
<canvas id="tankmap" width="500px" height="500" style="background-color:black;"></canvas>
<script type="text/javascript" src="tankgame.js"></script>
<script type="text/javascript">
var mycanvas=document.getElementById("tankmap")
var cxt=mycanvas.getContext("2d")
//我的坦克
var hero=new Hero(40,40,0,heroColor);
//定义敌人的坦克
var enemyTanks=new Array();
for(var i=0;i<4;i++)
{
//创建坦克
var enemyTank=new EnemyTank((i+1)*50,0,2);
enemyTanks[i]=enemyTank;
//画出坦克
// drawTank(enemyTanks[i]);
}
//颜色数组
var heroColor=new Array("#ded284","yellow");
//坦克类
function Tank(x,y,direct,color){
this.x=x;
this.y=y;
this.speed=1;
this.direct=direct;
this.color=color;
//上
this. moveUp= function(){
this.y-=this.speed;
this.direct=0;
}
//又
this.moveRight=function(){
this.x+=this.speed;
this.direct=1;
}
//下
this.moveDown=function(){
this.y+=this.speed;
this.direct=2;
}
//左
this.moveLeft=function(){
this.x-=this.speed;
this.direct=3;
}
}
//定义一个Hero类
function Hero(x,y,direct,color){
this.tank=Tank;
this.tank(x,y,direct,color);
}
//定义一个EnemyTank类
function EnemyTank(x,y,direct,color){
this.tank=Tank;
this.tank(x,y,direct,color);
}
drawTank(hero);
//用户按键函数
function getCommand(){
var code=event.keyCode;
switch(code){
case 87:
hero.moveUp();
break;
case 68:
hero.moveRight();
break;
case 83:
hero.moveDown();
break;
case 65:
hero.moveLeft();
break;
}
cxt.clearRect(0,0,500,500);
drawTank(hero);
}
</script>
</body>
</html>