Skip to content

Commit

Permalink
Incorporamos herencia
Browse files Browse the repository at this point in the history
  • Loading branch information
ramirob03 committed Nov 4, 2024
1 parent 316e9b7 commit aec7350
Show file tree
Hide file tree
Showing 8 changed files with 146 additions and 152 deletions.
Binary file removed assets/carretera.png
Binary file not shown.
Binary file added assets/explosion.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/gameover.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
75 changes: 21 additions & 54 deletions example.wlk
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ object juegoDeAutos {
game.boardGround("freeway.png")
game.addVisualCharacter(auto)
game.onCollideDo(auto, {visual => visual.chocar()})
//sonido.iniciarFondo()
}

method configurarTeclado() {
Expand All @@ -19,7 +20,6 @@ object juegoDeAutos {
}
}


object auto {
var position = game.at(1, 2)
method image() = "porsche.png"
Expand All @@ -39,10 +39,9 @@ object auto {

}

object gasolina {
var property position = game.at(0.randomUpTo(game.width() - 1), 9)
method image() = "gasolina.png"

class Objeto {
var property position = game.at(0.randomUpTo(game.width() - 1), 12)

method moverseHaciaAbajo() {
if (position.y() > 0) {
position = game.at(position.x(), position.y() - 1)
Expand All @@ -51,71 +50,39 @@ object gasolina {
}
}

method chocar() {
method chocar()
}

class Gasolina inherits Objeto {

method image() = "gasolina.png"

override method chocar() {
contadorNafta.agregarNafta(10)
}

method restaurarUbicacion() {
position = game.at(0.randomUpTo(game.width() - 1), 9)
position = game.at(0.randomUpTo(game.width() - 1), 12)
}
}

class Obstaculo {
var position = game.at(0.randomUpTo(game.width() - 1), 12)
method image() = "cono.png"

method position() = position
method position(newPosition) {
position = newPosition
}
const gasolina = new Gasolina()

method moverseHaciaAbajo() {
if (position.y() > 0) {
position = position.down(1)
} else {
position = game.at(0.randomUpTo(game.width() - 1), game.height() - 1)
}
}
class Cono inherits Objeto {
method image() = "cono.png"

method chocar() {
override method chocar() {
contadorNafta.agregarNafta(-10)
}

}

class AutoEnemigo {
var position = game.at(0.randomUpTo(game.width() - 1), game.height() - 1)
class AutoEnemigo inherits Objeto {

method image() = "policecar.png"

method position() = position
method position(newPosition) {
position = newPosition
}

method moverseHaciaAbajo() {
if (position.y() > 0) {
position = position.down(1)
} else {
position = game.at(0.randomUpTo(game.width() - 1), game.height() - 1)
}
}

method chocar() {
sonido.explosion()
override method chocar() {
//sonido.explosion()
cartelFinal.iniciar()
}
}

object sonido {
const sonidoFondo = game.sound("fondo.mp3")

method iniciarFondo() {
sonidoFondo.shouldLoop(true)
game.schedule(0, {sonidoFondo.play()})
}

method explosion() {
game.sound("explosion.wav").play()
}

}
148 changes: 73 additions & 75 deletions handlers.wlk
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import example.*
import visuales.*
import wollok.game.*

object contador {
var property puntos = 0
Expand All @@ -18,16 +19,23 @@ object contador {

object contadorNafta {
var nafta = 100
var enGameOver = false

method agregarNafta(cantidad) {
if (nafta > 0){
nafta = 100.min(nafta + cantidad)
} else {
} else if (!enGameOver){
enGameOver = true
cartelFinal.iniciar()
}

}

method reiniciarNafta() {
nafta = 100
enGameOver = false
}

const property celeste = "279df5cc"

method position () = game.at(0, 0)
Expand All @@ -37,109 +45,99 @@ object contadorNafta {

}

object manejadorAutos {
const autos = new List()
class Manejador {

const lista = new List()

method agregarAutosFilaSuperior() {
const nuevoAuto = new AutoEnemigo ()
autos.add(nuevoAuto)
game.addVisual(nuevoAuto)
method obtenerLista() = lista

method movimiento() {
lista.forEach{objeto => objeto.moverseHaciaAbajo()}
}

method paraCadaAuto() {
autos.forEach{autoEnemigo => autoEnemigo.moverseHaciaAbajo()}
method sacar(){
lista.forEach{objeto => game.removeVisual(objeto)}
lista.clear()
}

method sacarAutos(){
autos.forEach{autoEnemigo => game.removeVisual(autoEnemigo)}
autos.clear()
}
}

object manejadorObstaculos {
const obstaculos = new List()

method agregarObstaculos() {
const nuevoObstaculo = new Obstaculo ()
obstaculos.add(nuevoObstaculo)
game.addVisual(nuevoObstaculo)
class ManejadorAutos inherits Manejador {
method agregarAutosFilaSuperior() {
const nuevoAuto = new AutoEnemigo ()
lista.add(nuevoAuto)
game.addVisual(nuevoAuto)
}
}

method paraCadaObstaculo() {
obstaculos.forEach{obstaculo => obstaculo.moverseHaciaAbajo()}
}

method sacarObstaculos(){
obstaculos.forEach{obstaculo => game.removeVisual(obstaculo)}
obstaculos.clear()
class ManejadorConos inherits Manejador {
method agregarConosFilaSuperior() {
const nuevoCono = new Cono ()
lista.add(nuevoCono)
game.addVisual(nuevoCono)
}
}

const manejadorAutos = new ManejadorAutos()
const manejadorConos = new ManejadorConos()

object manejadorColisiones {
method iniciar(){
game.onTick(300, "moverAutos", { manejadorAutos.paraCadaAuto() })
game.onTick(300, "moverGasolina", { gasolina.moverseHaciaAbajo() })
game.onTick(300, "moverObstaculos", { manejadorObstaculos.paraCadaObstaculo() })
game.onTick(300, "moverAutos", { manejadorAutos.movimiento() })
game.onTick(300, "moverObstaculos", { manejadorConos.movimiento() })
game.onTick(100, "aumentarPuntos", { contador.aumentarPuntos() })
game.onTick(1000, "disminuirNafta", { contadorNafta.agregarNafta(-2) })
game.onTick(500, "disminuirNafta", { contadorNafta.agregarNafta(-1) })
game.onTick(300, "moverGasolina", { gasolina.moverseHaciaAbajo() })
}

}

object cartelFinal{
var property position = game.origin()
method image() = "gameover.png"
method iniciar(){
game.removeVisual(gasolina)
game.removeTickEvent("moverAutos")
game.removeTickEvent("moverGasolina")
game.removeTickEvent("moverObstaculos")
game.removeTickEvent("aumentarPuntos")
game.removeTickEvent("disminuirNafta")
manejadorAutos.sacarAutos()
manejadorObstaculos.sacarObstaculos()
game.removeVisual(contadorNafta)
game.removeVisual(contador)
game.addVisual(self)
game.addVisual(textoGameOver)
game.addVisual(textoPuntaje)
game.addVisual(textoReinicio)
}
var property position = game.at(0,0)
method image() = "explosion.png"
method iniciar(){
game.removeTickEvent("moverAutos")
game.removeTickEvent("moverObstaculos")
game.removeTickEvent("aumentarPuntos")
game.removeTickEvent("disminuirNafta")
game.removeTickEvent("moverGasolina")
game.removeVisual(gasolina)
game.removeVisual(contadorNafta)
game.removeVisual(contador)
manejadorAutos.sacar()
manejadorConos.sacar()
game.addVisual(self)
const textoPuntaje = new Texto ( texto = "PUNTAJE: " + contador.puntos(), position = game.at(4,6) )
game.addVisual(textoGameOver)
game.addVisual(textoPuntaje)
game.addVisual(textoReinicio)
keyboard.r().onPressDo({game.removeVisual(textoPuntaje)
game.removeVisual(textoGameOver)
game.removeVisual(textoReinicio)
game.removeVisual(self)
reiniciarJuego.iniciar()})
}
}

object textoGameOver {
class Texto {
const texto
var property position
const property negro = "000000e8"
method textColor() = negro
method text () = "GAME OVER"
method position() = game.at(4, 7)
}

object textoPuntaje {
const property negro = "000000e8"
method textColor() = negro
method text () = "PUNTAJE: " + contador.puntos()
method position() = game.at(4, 6)
method text() = texto
}

object textoReinicio {
const property negro = "000000e8"
method textColor() = negro
method text () = "PRESIONE R PARA REINICIAR"
method position() = game.at(4, 5)
}
const textoGameOver = new Texto ( texto = "GAME OVER", position = game.at(4,7) )
const textoReinicio = new Texto( texto = "PRESIONE R PARA REINICIAR" , position = game.at(4,5) )


object reiniciarJuego{
method iniciar() {
game.removeVisual(cartelFinal)
game.removeVisual(textoGameOver)
game.removeVisual(textoPuntaje)
game.removeVisual(textoReinicio)
contadorNafta.agregarNafta(100)
contadorNafta.reiniciarNafta()
manejadorAutos.sacar()
manejadorConos.sacar()
contador.puntos(0)
gasolina.restaurarUbicacion()
game.schedule(300, {
cargarVisuales.iniciar()
manejadorColisiones.iniciar()
})
cargarVisuales.iniciar()
manejadorColisiones.iniciar()
}
}
2 changes: 0 additions & 2 deletions main.wpgm
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,4 @@ program juego {
juegoDeAutos.configurarTeclado()
game.start()

keyboard.r().onPressDo({reiniciarJuego.iniciar()})

}
Loading

0 comments on commit aec7350

Please sign in to comment.