原生js实现一个坦克大战游戏代码
代码语言:html
所属分类:游戏
代码描述:原生js实现一个坦克大战游戏代码
下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开
<!DOCTYPE html> <html lang="zh-CN"> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <style> *{ margin: 0; padding: 0; } body{ max-width: 500px; height: 60vh; overflow: hidden; position: relative; border: 1px solid red; margin: 0 auto; } .tank,.enemy{ width: 16px; height: 16px; background-color: rgb(66, 218, 104); position: relative; position: absolute; top:calc(100% - 35px); left: 0; transform: rotate(0); } .tank .tube,.enemy .enemy-tube{ width: 5px; height: 30%; position: absolute; left: 50%; transform: translateX(-50%); top: -30%; background-color: rgb(66, 218, 104); } .cannonball{ width: 3px; height: 3px; position: absolute; background-color: rgb(255, 0, 0); } .background{ width: 100%; height: 100%; border-collapse: collapse; background-color: orange; } .background tr{ width: 100%; } .background tr td{ background-color: #000; height: 10px; width: 10px; border: 3px solid transparent; } .background tr .wall{ background-color: red; position: relative; border: 3px solid orange; } .enemy{ top: 0; left: 50%; transform: translateX(-50%); background-color: aqua; } .enemy .enemy-tube{ background-color: aqua; color: transparent; } .background tr .base{ background: rgb(11, 238, 30) ; } .background tr .Invincible{ background: rgb(196, 196, 5) ; } .surplus{ position: relative; top: 50px; } .surplus span{ color: red; font-size: 20px; } </style> </head> <body> <table class="background"></table> <div class="tank"> <div class="tube"></div> </div> <div class="surplus"> 剩余敌人:<span id="surplus"></span> </div> <div class="tips"> ↑↓←→ 空格 </div> <script> class person{ constructor(){ this.el={ //存放标签 tank:document.querySelector(".tank"), tube:document.querySelector(".tube"), background:document.querySelector(".background"), enemyArr:[] }, this.timeID={ //计时器 walkId:0, launchId:0, EMId:0, EMPId:0 }, this.condition={ //判断条件 direction:&q.........完整代码请登录后点击上方下载按钮下载查看
网友评论0