python 抓取音乐
来源:互联网 发布:卡盟下单源码 编辑:程序博客网 时间:2024/05/16 03:08
<!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta http-equiv="X-UA-Compatible" content="ie=edge"> <title>Document</title> <style> .container{ width:600px; height: 600px; background-color: black; border:1px solid gray; margin :50px auto; position: relative; } .p1{ border :1px solid black; width :60px; height :60px; background-image: url("tankesucai/p1tankU.png"); border-radius: 10px; position: absolute; bottom :0; left :200px; } .bullet{ width : 17px; height : 17px; position : absolute; background:url("tankesucai/tankmissile.png"); border-radius: 50%; } .enemy{ width :60px; height :60px; background: url("tankesucai/enemy1L.gif"); position: absolute; } </style></head><body> <audio src="tankesucai/start.wav" autoplay ></audio> <audio id = "fireAudio" src="tankesucai/fire.wav" ></audio> <audio class = "moveAudio" src="tankesucai/tankeMove.wav"autoplay loop></audio> <div class="container"> <div class="p1"> </div> </div></body><script> Array.prototype.indexOf = function(val){ for(var i= 0;i < this.length;i++){ if(this[i] == val)return i; } return -1; }; Array.prototype.remove = function(val){ var index = this.indexOf(val); if(index > -1){ this.splice(index , 1); } }; var p1 = document.getElementsByClassName("p1")[0]; var container = document.getElementsByClassName("container")[0]; var p1Direction = "up"; var p1Speed = 5; var maxWidth = container.offsetWidth - p1.offsetWidth; var maxHeight = container.offsetHeight - p1.offsetHeight; // var bgAudio = ""; // bgAudio.play(); var moveAudio = document.getElementsByClassName("moveAudio")[0]; moveAudio.volume = 0; var gameTimer = ""; var a = 0; var isKeyDown = false; var bullets = []; var bx = 0; var by = 0; function Enemy(){ this.element = document.createElement("div"); this.element.className = "enemy"; this.speed = 5; this.positionX = parseInt(Math.random() * 540) +1; this.positionY = parseInt(Math.random() * 90) +1; this.move = function(){ switch(this.direction){ case 1: this.element.style.backgroundImage = 'url("tankesucai/enemy1L.gif")'; this.element.style.left = this.element.offsetLeft - this.speed + "px"; break; case 2: this.element.style.backgroundImage = 'url("tankesucai/enemy1R.gif")'; this.element.style.left = this.element.offsetLeft + this.speed + "px"; break; case 3: this.element.style.backgroundImage = 'url("tankesucai/enemy1U.gif")'; this.element.style.top = this.element.offsetTop - this.speed + "px"; break; case 4: this.element.style.backgroundImage = 'url("tankesucai/enemy1D.gif")'; this.element.style.top = this.element.offsetTop + this.speed + "px"; break; } var isLeft = this.element.offsetLeft <= 0; var isRight = this.element.offsetLeft + this.element.offsetWidth >= container.offsetWidth; var isTop = this.element.offsetTop <=0; var isDown = this.element.offsetTop + this.element.offsetHeight >= container.offsetHeight; if(isLeft || isRight || isTop || isDown){ this.isDie = true; } } this.isDie = false; this.direction = parseInt(Math.random() * 4) +1; this.timeout = setTimeout(function() { }, (Math.random()*4 + 3) * 1000); } var enemys = []; function createOneEnemy(){ var oneEnemy = new Enemy(); container.appendChild(oneEnemy.element); oneEnemy.element.style.left = oneEnemy.positionX + "px"; oneEnemy.element.style.top = oneEnemy.positionY + "px"; enemys.push(oneEnemy); return oneEnemy; } function Bullet(){ this.element = document.createElement("div"); this.element.className = "bullet"; this.speed = 10; this.direction = "left"; this.isDie = false; this.move = function(){ switch(this.direction){ case "left": this.element.style.left = this.element.offsetLeft - this.speed + "px"; break; case "right": this.element.style.left = this.element.offsetLeft + this.speed + "px"; break; case "up": this.element.style.top = this.element.offsetTop - this.speed + "px"; break; case "down": this.element.style.top = this.element.offsetTop + this.speed + "px"; break; } var isLeft = this.element.offsetLeft <= 0; var isRight = this.element.offsetLeft + this.element.offsetWidth >= container.offsetWidth; var isTop = this.element.offsetTop <=0; var isDown = this.element.offsetTop + this.element.offsetHeight >= container.offsetHeight; if(isLeft || isRight || isTop || isDown){ this.isDie = true; } } this.positionX = 0; this.positionY = 0; } function createOneBullet(bulletDirection , positionX , positionY){ var oneBullet = new Bullet(); oneBullet.direction = bulletDirection; oneBullet.positionX = positionX; oneBullet.positionY = positionY; container.appendChild(oneBullet.element); oneBullet.element.style.left = oneBullet.positionX + "px"; oneBullet.element.style.top = oneBullet.positionY + "px"; fireAudio.play(); bx = p1.offsetLeft + p1.offsetWidth / 2-5; by = p1.offsetTop - 17; return oneBullet; } gameTimer = setInterval(function(){ a++; if(isKeyDown == true){ moveAudio.volume = 1; p1Move(p1Direction); }else{ moveAudio.volume = 0; } if(bullets.length > 0){ for(var i = 0;i < bullets.length;i++){ if(bullets[i].isDie == false){ bullets[i].move(); }else{ bullets[i].element.remove(); bullets = []; } } } var suijishu = parseInt(Math.random()*50)+20; if(a % suijishu == 0 ){ if(enemys.length >=10){ }else{ createOneEnemy(); } } if(a >= 2000){ a = 20; } if(enemys.length > 0){ for(var i = 0;i < enemys.length;i++){ if(enemys[i]){ if(enemys[i].isDie == false){ enemys[i].move(); }else{ enemys[i].element.remove(); enemys.remove(enemys[i]); i--; } } } } },50); document.onkeydown = function (event){ switch(event.keyCode){ case 37: case 65: p1Direction = "left"; isKeyDown = true; bx = p1.offsetLeft -17; by = p1.offsetTop + p1.offsetHeight /2-14; // p1Move(p1Direction); break; case 38: case 87: p1Direction = "up"; isKeyDown = true; bx = p1.offsetLeft + p1.offsetWidth / 2-5; by = p1.offsetTop - 17; // p1Move(p1Direction); break; case 39: case 68: p1Direction = "right"; isKeyDown = true; bx = p1.offsetLeft + p1.offsetWidth; by = p1.offsetTop + p1.offsetWidth/2 - 8; // p1Move(p1Direction); break; case 40: case 83: p1Direction = "down"; isKeyDown = true; bx = p1.offsetLeft + p1.offsetWidth /2 -5; by = p1.offsetTop + p1.offsetHeight; // p1Move(p1Direction); break; case 32: if(bullets.length > 0){ }else{ var one = createOneBullet(p1Direction , bx , by); bullets.push(one); } break; default: break; } } document.onkeyup = function(){ isKeyDown = false; } function p1Move(direction){ switch (direction){ case "left": p1.style.backgroundImage = 'url("tankesucai/p1tankL.png")'; p1.style.left = p1.offsetLeft - p1Speed + "px"; if(p1.offsetLeft <= 0){ p1.style.left = 0 + "px"; } break; case "right": p1.style.backgroundImage = 'url("tankesucai/p1tankR.png")'; p1.style.left = p1.offsetLeft + p1Speed + "px"; if(p1.offsetLeft >= maxWidth){ p1.style.left = maxWidth + "px"; } break; case "up": p1.style.backgroundImage = 'url("tankesucai/p1tankU.png")'; p1.style.top = p1.offsetTop - p1Speed + "px"; if(p1.offsetTop <= 0){ p1.style.top = 0 + "px"; } break; case "down": p1.style.backgroundImage = 'url("tankesucai/p1tankD.png")'; p1.style.top = p1.offsetTop + p1Speed + "px"; if(p1.offsetTop >= maxHeight){ p1.style.top = maxHeight + "px"; } break; default: break; } }</script></html>
阅读全文
0 0
- python 抓取音乐
- 使用Python抓取网易云音乐所有歌手信息
- xiami音乐抓取
- 百度音乐API抓取
- Python抓取网页云音乐指定歌手的歌曲和评论数量
- Win7,64位,Python使用Beautiful Soup 4抓取网易云音乐歌单中的歌曲
- 关于利用Python无法直接抓取全部网易云音乐评论时怎么解决
- 百度音乐API抓取-Fiddler
- 从豆瓣中抓取图片以及音乐
- Wireshark抓取网易音乐的下载地址
- python 抓取 外汇牌价
- 使用python抓取网页
- Python抓取中文网页
- python抓取网页图片
- Python抓取中文网页
- Python抓取中文网页
- python 抓取网页代码
- Python抓取html内容
- c3p0的jar包加载正常,报错说找不到ComboPooledDataSource
- table边框合并
- 【Python 命令行参数解析: optparse 模块】
- hdu 6090(一)
- java正则表达
- python 抓取音乐
- 在Ubuntu上配置ftp服务
- 关于Android 应用新手引导页面的小例子
- POJ2406——Power Strings(后缀数组)
- hdu 6090(二)
- 前言的闲话以及第一章的入门(三)
- 20、密码验证合格程序
- hdu 6090(三)
- java编程加载窗口,插入图片