方块的移动游戏

*{
padding: 0;
margin: 0;
}
#game {
width: 800px;
height: 600px;

    background: url(img/chengwomen.jpg) repeat-x;

   background-size: cover;
    overflow: hidden;
    position: relative;
}
#bid {
    width: 40px;
    height: 40px;
    background-color: red;
    position: absolute;
    top: 100px;
    left: 100px;
}
</style>

if(running){
sky.x -= 5;
game.style.backgroundPositionX = sky.x + ‘px’;
bird.speedY +=1;
bird.y +=bird.speedY;
if(bird.y<0){
running = false;
bird.y = 0;

}
if(bird.y+birdred.offsetHeight>600){
running = false;
bird.y = 600-birdred.offsetHeight;
console.log(bird.y);
}

birdred.style.top = bird.y + ‘px’;
}

},30);

//点击文档的时候实现小鸟向上运动
document.onclick = function () {
    bird.speedY = -10;
}
function createPipe(position){
    var pipe = {};
    pipe.x = position;
    pipe.uHeight = 200+parseInt(Math.random()*100);
    pipe.dHeight = 400-pipe.uHeight;
    pipe.dtop = pipe.uHeight+200;
      var uPipe = document.createElement('div');
      uPipe.style.width = "50px";
      uPipe.style.height = pipe.uHeight + 'px';
      uPipe.style.position = 'absolute';
      uPipe.style.backgroundColor="red";
      uPipe.style.top = 0;
      uPipe.style.left = pipe.x + 'px';
      game.appendChild(uPipe);

      var dPipe = document.createElement('div');
      dPipe.style.width = "50px";
      dPipe.style.height = pipe.dHeight + 'px';
      dPipe.style.backgroundColor="green";
      dPipe.style.position = 'absolute';
      dPipe.style.top = pipe.dtop+'px';
      dPipe.style.left = pipe.x + 'px';
      game.appendChild(dPipe);

      setInterval(function (){
          if(running){
     pipe.x -= 2;
     uPipe.style.left = pipe.x + 'px';
     dPipe.style.left = pipe.x + 'px';}
     if(pipe.x< -50){
         pipe.x = 800;
     }
      var uCheck = bird.x +40 > pipe.x &&bird.x<pipe.x+ 50&&bird.y<pipe.uHeight;
      var dCheck = bird.x +40 > pipe.x &&bird.x<pipe.x+ 50&&bird.y>pipe.uHeight+200;
   

     if(uCheck||dCheck){
         running = false;
     }
      },30)
}
createPipe(400);
createPipe(600);
createPipe(800);
createPipe(1000);
</script>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值