HTML and CSS Reference
In-Depth Information
Code
Explanation
my = ev.layerY;
ev.layerY for my
} else if (ev.offsetX || ev.offsetX == 0) { Does offsetX work?
Use it for mx
mx = ev.offsetX;
my = ev.offsetY;
Use offsetY for my
}
Close if true
cball.sx = mx;
Position ball x
cball.sy = my;
…and y
Position sling bx
mysling.bx = mx;
… and by
mysling.by = my;
drawall();
Draw everything
}
Close if in motion
}
Close function
function finish(ev) {
Function for mousedown
if (inmotion) {
In motion?
Reset inmotion
inmotion = false;
var outofcannon =
distsq(mysling.bx,mysling.by,
mysling.s1x,mysling.s1y)/700;
Base outofcannon proportional to square of
bx,by to s1x,s1y
var angleradians = -Math.atan2
(mysling.s1y-mysling.by,
mysling.s1x-mysling.bx);
Compute angle
horvelocity = outofcannon*Math.cos
(angleradians);
verticalvel1 = - outofcannon*Math.sin
(angleradians);
Search WWH ::




Custom Search