So I’ve managed to make it as far as up to having a moving element in my road crossing game while understanding everything about how the code is making everything works until now.
Can someone explain in simple terms how the code below makes my most left blue element move up and down? I understood how it goes down, but when I had to code it going up and down, my mind gets baffled.
moveVertically() {
if (this.y > screenHeight - 100 || this.y < 50 ) {
this.speed = -this.speed;
}
this.y += this.speed;
}