diff --git a/assets/cono.png b/assets/cono.png index 5f43860..cc3ac72 100644 Binary files a/assets/cono.png and b/assets/cono.png differ diff --git a/assets/freeway.png b/assets/freeway.png deleted file mode 100644 index b643390..0000000 Binary files a/assets/freeway.png and /dev/null differ diff --git a/assets/freeway_1.jpg b/assets/freeway_1.jpg new file mode 100644 index 0000000..73eae49 Binary files /dev/null and b/assets/freeway_1.jpg differ diff --git a/assets/gasolina.png b/assets/gasolina.png index 361c741..a6cdb5c 100644 Binary files a/assets/gasolina.png and b/assets/gasolina.png differ diff --git a/assets/policecar.png b/assets/policecar.png index 4659bb4..87db67b 100644 Binary files a/assets/policecar.png and b/assets/policecar.png differ diff --git a/assets/porsche.png b/assets/porsche.png new file mode 100644 index 0000000..b9a30a7 Binary files /dev/null and b/assets/porsche.png differ diff --git a/example.wlk b/example.wlk index 44421aa..2bf51b6 100644 --- a/example.wlk +++ b/example.wlk @@ -1,27 +1,34 @@ import wollok.game.* -//Cómo hacer para moverse más rápido? +// Juego de autos con mayor velocidad de movimiento object juegoDeAutos { method iniciar() { - game.width(10) - game.height(9) - game.boardGround("freeway.png") + game.width(9) + game.height(10) + game.cellSize(50) + game.boardGround("freeway_1.jpg") game.addVisualCharacter(auto) - game.addVisualCharacter(obstaculo) + game.addVisual(obstaculo) + game.addVisual(contador) keyboard.left().onPressDo({ auto.moverIzquierda() }) keyboard.right().onPressDo({ auto.moverDerecha() }) - game.onTick(1000, "moverse", {obstaculo.moverseHaciaAbajo()}) + game.onTick(2000, "moverse", {obstaculo.moverseHaciaAbajo() + contador.aumentarPuntos() + auto.perderNafta() + if (auto.nafta <= 0) game.stop() + }) } } object auto { var nafta = 100 - var position = game.at(5, 4) - method image() = "policecar.png" + var position = game.at(1, 0) + + method image() = "porsche.png" method perderNafta() { nafta -= 2 @@ -30,13 +37,14 @@ object auto { method position() = position method moverIzquierda() { - if (position.x() > 0) { + if (position.x() > 1) { position = game.at(position.x() - 1, position.y()) } } + method moverDerecha() { - if (position.x() < game.width() - 1) { + if (position.x() < game.width() - 2) { position = game.at(position.x() + 1, position.y()) } } @@ -51,22 +59,54 @@ object auto { } object obstaculo { - var position = game.at(1.randomUpTo(game.width()), 4) - method image() = "cono.png" - /*method aparecer() { - posicion = game.at(0.randomUpTo(9),0) - }*/ + // Posición inicial aleatoria en la fila superior del tablero + var position = game.at(0.randomUpTo(game.width() - 1), 9) + method image() = "policecar.png" + method position() = position + method position(newPosition) { + position = newPosition + } method moverseHaciaAbajo () { - if (position.y() < game.height() - 1) { - position = game.at(position.x(), position.y() + 1) - } else { + if (position.y() > 0) { + 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), 9) + } + } +} + +class AutoEnemigo { + var position + method image() = "policecar.png" + + method position() = position + method position(newPosition) { + position = newPosition + } + + method moverseHaciaAbajo() { + if (position.y() < game.height() - 1) { + position = game.at(position.x(), position.y() - 1) + } else { position = game.at(0.randomUpTo(game.width() - 1), 0) } } } -//TODO : Implementar la clase obstaculo -//Cómo hacer para moverse más rápido? -//Movimientos con polimorfismo + +object contador { + var puntos = 0 + const property celeste = "279df5cc" + + method position () = game.at(5, 9) + + method aumentarPuntos() { + puntos += 10 + } + + method text() = "Puntos: " + puntos + method textColor() = celeste + +}