[(h1 id=" ")]ボール当てゲーム[(/h1)]

title.id=" ".text="ボール当てゲーム"

+

[(p id="msg1")]クリックした方向に飛びます[(/p)]

msg.id="msg1".text="クリックした方向に飛びます"

+

[(div)][(canvas width="640" height="640")][(/canvas)][(/div)]

canvas.width="640".height="640"

+

var ctx=$("canvas")

?ctx=canvas+

+

var msg1=$("#msg1")

?msg1=id.msg1

+

var dist=0

?dist=0

+

var x1=10

?x1=10

+

var y1=10

?y1=10

+

var vX=0

?vX=0

+

var vY=0

?vY=0

+

var x2=0

?x2=0

+

var y2=-40

?y2=-40

+

var posX=0

?posX=0

+

var posY=0

?posY=0

+

ctx.drawEllipse({layer:true, name:"el1", width:20, height:20, x:x1, y:y1, fillStyle:"#ff9999", strokeWidth:0, strokeStyle:"black", fromCenter:true,})

?ctx.drawEllipse (name:"el1".W:20.H:20.x:?x1.y:?y1.fillColor:"#ff9999".lineW:0.lineColor:"black".center:"true".)+

+

ctx.drawEllipse({layer:true, name:"el2", width:20, height:20, x:x2, y:y2, fillStyle:"#9999ff", strokeWidth:0, strokeStyle:"black", fromCenter:true,})

?ctx.drawEllipse (name:"el2".W:20.H:20.x:?x2.y:?y2.fillColor:"#9999ff".lineW:0.lineColor:"black".center:"true".)+

+

ctx.on("touchstart mousedown",function(e){ e.preventDefault(); var offset=ctx.offset()

?ctx.click.function

+

posX=(e.clientX || e.originalEvent.changedTouches[0].clientX)-offset.left; posY=(e.clientY || e.originalEvent.changedTouches[0].clientY)-offset.top

?posX=click.positionX

1

?posY=click.positionY

if(posX<=posY){

if?posX<=?posY+

+

vX=1

in

?vX=1+

+

vY=posY/posX

in

?vY=?posY/?posX+

+

}

}

else if(posX>posY){

else if?posX>?posY+

+

vX=posX/posY

in

?vX=?posX/?posY+

+

vY=1

in

?vY=1+

+

}

}

})

end.function

+

x2=Math.floor(Math.random()*301)+330

?x2=rand330630+

+

var bool=true; (function(){

game loop.?bool=true

y2=y2+1

?y2=?y2+1+

+

ctx.animateLayer ( "el2",{ x:x2, y:y2,},1 )

?ctx.animate (name:"el2".x:?x2.y:?y2.+1/1000)

+

x1=x1+vX

?x1=?x1+?vX+

+

y1=y1+vY

?y1=?y1+?vY+

+

ctx.animateLayer ( "el1",{ x:x1, y:y1,},1 )

?ctx.animate (name:"el1".x:?x1.y:?y1.+1/1000)

+

dist=Math.sqrt(Math.pow(x1-x2, 2) + Math.pow(y1-y2, 2))

?dist=dist.pos1x:?x1.y:?y1.pos2x:?x2.y:?y2.

+

if(dist<20){

if?dist<20+

+

msg1.text("HIT!!")

in

?msg1.text="HIT!!"+

+

ctx.animateLayer ( "el2",{ scaleX:5, scaleY:5, fillStyle:"#ff0000",} )

in

?ctx.animate (name:"el2".scaleX:5.scaleY:5.fillColor:"#ff0000".+1000/1000)

+

bool=false

in

?bool=false

+

}

}

if(y2>650){

if?y2>650+

+

msg1.text("Missed!")

in

?msg1.text="Missed!"+

+

bool=false

in

?bool=false

+

}

}

if(bool){setTimeout(arguments.callee,1000/60);} })()

if?bool==true+loopspeed60fps