Amigos, ¿si pongo una condicionante else dentro de la funcion shootingTarget, esta podria arrogar una alerta que le diga al usuario que falló?
<meta charset="UTF-8">
<canvas width="600" height="400"> </canvas>
<script>
var screen = document.querySelector ("canvas");
var pencil = screen.getContext("2d");
pencil.fillStyle = "white";
pencil.fillRect (0,0,600,400);
var vectorRadius = 10;
var randomX;
var randomY;
function makingCircunference (sectorX,sectorY,sectorRadius,sectorColor){
pencil.fillStyle = (sectorColor);
pencil.beginPath();
pencil.arc(sectorX,sectorY,sectorRadius,0,2*Math.PI);
pencil.fill();
}
function clearScreen (){
pencil.clearRect(0,0,600,400);
}
var vectorX = 0;
function makingTarget (vectorX,vectorY){
makingCircunference(vectorX,vectorY,vectorRadius + 20,"red");
makingCircunference(vectorX,vectorY,vectorRadius + 10,"white");
makingCircunference(vectorX,vectorY,vectorRadius,"red");
}
function randomTarget(maximumVector){
return Math.floor(Math.random()*maximumVector);
}
function updatingScreen (){
clearScreen();
randomX = randomTarget (600);
randomY = randomTarget (400);
makingTarget (randomX,randomY);
vectorX++;
}
setInterval(updatingScreen,900);
function shootingTarget(target){
var targetX = target.pageX - screen.offsetLeft;
var targetY = target.pageY - screen.offsetTop;
if ((targetX < randomX + vectorRadius) &&
(targetX > randomX - vectorRadius) &&
(targetY < randomY + vectorRadius) &&
(targetY > randomY - vectorRadius)){
alert ("You made the shoot, man!!");
}
}
screen.onclick = (shootingTarget);
</script>