Skip to content

Commit

Permalink
agregamos obstaculo
Browse files Browse the repository at this point in the history
  • Loading branch information
ramirob03 committed Oct 14, 2024
1 parent 7b14c0a commit f1ec3a2
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 27 deletions.
Binary file added 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/fondo.jpg
Binary file not shown.
Binary file added 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.
51 changes: 25 additions & 26 deletions example.wlk
Original file line number Diff line number Diff line change
Expand Up @@ -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())
}
}

Expand All @@ -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
1 change: 0 additions & 1 deletion main.wpgm
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import example.*


program juego {

juegoDeAutos.iniciar()
game.start()
}

0 comments on commit f1ec3a2

Please sign in to comment.