Mejor comprobación del movimiento de la nave

This commit is contained in:
2025-02-07 12:49:07 +01:00
parent 01b9ce7fc3
commit d0ec48927e

View File

@@ -28,17 +28,23 @@ public class Jugador extends Actor {
public void actua() {
if (movIzq && this.x > 0) this.x -= velocidadX;
if (movDer && this.x + this.ancho < Arkanoid.getInstance().getCanvas().getWidth()) this.x += velocidadX;
// Comprobaciones adicionales para evitar que se pase fuera del borde
if (this.x < 0) this.x = 0;
if (this.x + this.ancho > Arkanoid.getInstance().getCanvas().getWidth())
this.x = Arkanoid.getInstance().getCanvas().getWidth() - this.ancho;
}
public void movimientoRaton(int x, int y) {
x = (x - ancho / 2);
x = x - (this.ancho / 2);
if (x > 0 && x < Arkanoid.getInstance().getCanvas().getWidth() - this.ancho) this.x = x;
if (x >= 0 && x <= Arkanoid.getInstance().getCanvas().getWidth() - this.ancho) this.x = x;
}
public void movimientoTecladoDerecha(boolean derecha) {
this.movDer = derecha;
}
public void movimientoTecladoIzquierda(boolean izquierda) {
this.movIzq = izquierda;
}