The question is, I managed to develop the exercise to a certain extent, after that, as I do not know much of javascript, if I send the square back diagonally, the square comes back before due to the coordinates that have already been used, it is complex way of explaining, but it is conflicting in the coordinates because they have already been used previously in the path.
The question is, how do I get the square back diagonal as the image demonstrates? (The square on the left, doing the course) 90% of the exercise is done, I just need it.
Thank you
var canvas = document.getElementById('minha-tela');
var ctx = canvas.getContext('2d');
//definir o ínicio do desenho
var x = 0
var y = 150;
var l = 0;
//a função gameloop é chamada aqui
requestAnimationFrame(gameloop);
function gameloop() {
if(x<=700 && y==150)
x = x + 10;
if (x>=700 && y>=0)
y=y-10;
if (x>=350 && y<=0)
x=x-10;
desenharQuadrado(x,y);
//incrementar a variável x indicando o deslocamento para a direita
//chama novamente o ciclo da animação
requestAnimationFrame(gameloop);
}
function desenharQuadrado(pX,pY) {
ctx.clearRect(0, 0, 800, 400); //antes de fazer o desenho é preciso limpar o canvas
ctx.fillStyle = '#00F';
ctx.fillRect(pX, pY, 100, 100);
}
<canvas id="minha-tela" width="800" height="400" style="border: #F00 solid 1px;"> </canvas>