Skip to content

xuehuaxiaoyouxi #7

@daeme123

Description

@daeme123
<body><canvas id=c></canvas><div id=s>0</div><script>
c=document.getElementById('c'),c.width=innerWidth,c.height=innerHeight;
b={x:0,y:0,w:120,h:25};s=[];setInterval(()=>{s.push({x:Math.random()*innerWidth,y:-10})},300);
function d(){requestAnimationFrame(d);ctx=c.getContext('2d');ctx.clearRect(0,0,c.width,c.height);
s.forEach((s,i)=>{s.y+=2;ctx.fillStyle='white';ctx.fillRect(s.x,s.y,5,5);
if(s.y+5>c.height-80&&s.x>b.x&&s.x<b.x+120){s.splice(i,1);score++}});
ctx.fillStyle='#FF6B6B';ctx.fillRect(b.x,c.height-80,b.w,25);
document.getElementById('s').innerText='得分:'+score;}d();
onmousemove=e=>{b.x=e.clientX-60};ontouchmove=e=>{b.x=e.touches[0].clientX-60}
</script>

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions