Skip to content

Commit

Permalink
avanzamos con obstaculos y enemigos
Browse files Browse the repository at this point in the history
  • Loading branch information
tommyrios committed Oct 15, 2024
1 parent f1ec3a2 commit a3ad7dd
Show file tree
Hide file tree
Showing 7 changed files with 61 additions and 21 deletions.
Binary file modified assets/cono.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed assets/freeway.png
Binary file not shown.
Binary file added assets/freeway_1.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified assets/gasolina.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified assets/policecar.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/porsche.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
82 changes: 61 additions & 21 deletions example.wlk
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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())
}
}
Expand All @@ -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

}

0 comments on commit a3ad7dd

Please sign in to comment.