diff --git a/assets/cono.png b/assets/cono.png new file mode 100644 index 0000000..5f43860 Binary files /dev/null and b/assets/cono.png differ diff --git a/assets/fondo.jpg b/assets/fondo.jpg deleted file mode 100644 index 6c511f4..0000000 Binary files a/assets/fondo.jpg and /dev/null differ diff --git a/assets/gasolina.png b/assets/gasolina.png new file mode 100644 index 0000000..361c741 Binary files /dev/null and b/assets/gasolina.png differ diff --git a/example.wlk b/example.wlk index f0a72ea..44421aa 100644 --- a/example.wlk +++ b/example.wlk @@ -9,31 +9,35 @@ object juegoDeAutos { game.height(9) game.boardGround("freeway.png") game.addVisualCharacter(auto) + game.addVisualCharacter(obstaculo) + keyboard.left().onPressDo({ auto.moverIzquierda() }) keyboard.right().onPressDo({ auto.moverDerecha() }) + + game.onTick(1000, "moverse", {obstaculo.moverseHaciaAbajo()}) } } object auto { var nafta = 100 - var posicion = game.at(5, 4) - const property image = "policecar.png" + var position = game.at(5, 4) + method image() = "policecar.png" method perderNafta() { nafta -= 2 } - method position() = posicion + method position() = position method moverIzquierda() { - if (posicion.x() > 0) { - posicion = game.at(posicion.x() - 1, posicion.y()) + if (position.x() > 0) { + position = game.at(position.x() - 1, position.y()) } } method moverDerecha() { - if (posicion.x() < game.width() - 1) { - posicion = game.at(posicion.x() + 1, posicion.y()) + if (position.x() < game.width() - 1) { + position = game.at(position.x() + 1, position.y()) } } @@ -45,29 +49,24 @@ object auto { game.stop() } } - /* - method position() = position - method position(newPosition) { - position = newPosition - } +object obstaculo { + var position = game.at(1.randomUpTo(game.width()), 4) + method image() = "cono.png" + /*method aparecer() { + posicion = game.at(0.randomUpTo(9),0) + }*/ + method position() = position - method mover(direccion){ - const nuevaPosicion = direccion.siguiente(self.position()) - if (nuevaPosicion.x() >= 0 && nuevaPosicion.x() < game.width()) - self.position(nuevaPosicion) + method moverseHaciaAbajo () { + if (position.y() < game.height() - 1) { + position = game.at(position.x(), position.y() + 1) + } else { + // Si el obstáculo llega al final del tablero, reaparece en la parte superior con nueva posición + position = game.at(0.randomUpTo(game.width() - 1), 0) + } } -*/ -/* -object izquierda { - method siguiente(position) = position.left(1) } - -object derecha { - method siguiente(position) = position.right(1) -} - -*/ //TODO : Implementar la clase obstaculo //Cómo hacer para moverse más rápido? //Movimientos con polimorfismo diff --git a/main.wpgm b/main.wpgm index 49a826b..cedb9b2 100644 --- a/main.wpgm +++ b/main.wpgm @@ -3,7 +3,6 @@ import example.* program juego { - juegoDeAutos.iniciar() game.start() }