Skip to content

Commit

Permalink
Sistema de reinicio y ganar mediante las puertas
Browse files Browse the repository at this point in the history
  • Loading branch information
Valentin-Sosa committed Nov 6, 2024
1 parent e65cf01 commit ff1c8c9
Show file tree
Hide file tree
Showing 9 changed files with 105 additions and 10 deletions.
Binary file added assets/ganaste.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 added assets/ganaste2.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 added assets/perdiste.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 added assets/perdiste2.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 added assets/perdiste3.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
46 changes: 37 additions & 9 deletions elementos.wlk
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ class Elevador

return posicionInicial
}

method reiniciar()
{
activado = false
}
}

const elevadorPorBoton = new Elevador (posicionInicial = game.at(14, 9))
Expand Down Expand Up @@ -86,16 +91,39 @@ object cubo inherits Elemento (position = game.at(6, 10))
position = game.at(position.x() + desplazamiento, position.y())
game.sound("bloque.ogg").play()
}
}

object puertaFuego inherits Elemento (position = game.at(12, 14))
{
method image() = "puertaFuego.png"
override method tratarColision(personaje) {}
method reiniciar()
{
position = game.at(6, 10)
}
}

object puertaAgua inherits Elemento (position = game.at(8, 14))
class Puerta inherits Elemento
{
method image() = "puertaAgua.png"
override method tratarColision(personaje) {}
}
const condicion
const imagenCerrada
var property estaAbierta = false
method puedeAbrirPuertaFuego() = false
method puedeAbrirPuertaAgua() = false
method image()
{
if(estaAbierta) return "puertaAbierta.png"
return imagenCerrada
}

method hayAlguienEnPuerta()
{
const posibles = game.getObjectsIn(self.position())
return posibles.any(condicion)
}

method chequearPuerta()
{
if(self.hayAlguienEnPuerta()) estaAbierta = true
else estaAbierta = false
}
}

const puertaFuego = new Puerta(position = game.at(12, 14), imagenCerrada = "puertaFuego.png", condicion = {p => p.puedeAbrirPuertaFuego()})

const puertaAgua = new Puerta (position = game.at(8, 14), imagenCerrada = "puertaAgua.png", condicion = {p => p.puedeAbrirPuertaAgua()})
9 changes: 8 additions & 1 deletion main.wpgm
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import personajes.*
import elementos.*



program FireboyAndWatergirl {

mapa.inciar()
Expand All @@ -21,9 +20,17 @@ program FireboyAndWatergirl {
keyboard.d().onPressDo({watergirl.movDerecha()})
keyboard.s().onPressDo({watergirl.moverElemento()})

keyboard.r().onPressDo({juego.reiniciar()})

game.whenCollideDo(fireboy, {elemento => elemento.tratarColision(fireboy)})
game.whenCollideDo(watergirl, {elemento => elemento.tratarColision(watergirl)})
game.onTick(1000, "Chequear boton", {botonAbajo.chequearBoton()})
game.onTick(1000, "Chequear puerta agua", {puertaAgua.chequearPuerta()})
game.onTick(1000, "Chequear puerta fuego", {puertaFuego.chequearPuerta()})
game.onTick(1000, "Chequear victoria", {if(juego.condicionesGanadoras()) juego.ganaste()})
game.onTick(1000, "Chequear derrota", {if(juego.condicionesPerdedoras()) juego.perdiste()})



const soundtrack = game.sound("soundtrack.ogg")
soundtrack.shouldLoop(true)
Expand Down
46 changes: 46 additions & 0 deletions mapa.wlk
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import elementos.*
import personajes.fireboy
import personajes.watergirl

object mapa
{
Expand Down Expand Up @@ -133,3 +135,47 @@ class BloquePinchos inherits Bloque
}
}

object juego
{
var cartelActual = cartelGanador
var unCartelActivo = false
const elementos = [elevadorPorBoton, elevadorPorPalanca, fireboy, watergirl, cubo]
method ganaste()
{
game.addVisual(cartelGanador)
cartelActual = cartelGanador
unCartelActivo = true
}

method perdiste()
{
game.addVisual(cartelPerdedor)
cartelActual = cartelPerdedor
unCartelActivo = true
}

method reiniciar()
{
if(unCartelActivo)
{
elementos.forEach({e => e.reiniciar()})
unCartelActivo = false
game.removeVisual(cartelActual)
}
}

method condicionesGanadoras() = puertaFuego.estaAbierta() && puertaAgua.estaAbierta() && !unCartelActivo
method condicionesPerdedoras() = fireboy.estaMuerto() && watergirl.estaMuerto() && !unCartelActivo
}

object cartelGanador
{
method image() = "ganaste2.jpg"
var property position = game.at(3,4)
}

object cartelPerdedor
{
method image() = "perdiste3.jpg"
var property position = game.at(3,4)
}
14 changes: 14 additions & 0 deletions personajes.wlk
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
class Personaje {
var property position
const posicionInicial = position
var cantSaltos = 0
var property estaMuerto = false
var estaSaltando = false

method tratarColision(personaje) {}
method puedeSerAtravesado() = true
method puedePresionarBoton() = true
Expand Down Expand Up @@ -71,12 +73,22 @@ class Personaje {
estaMuerto = true
}

method reiniciar()
{
position = posicionInicial
if(estaMuerto) game.addVisual(self)
estaMuerto = false
}

}

object fireboy inherits Personaje (position = game.at(0, 0)) {
method image() = "fireboy6.png"
method tocarFuego(){}
method tocarAgua(){ self.morir()}
method puedeAbrirPuertaFuego() = true
method puedeAbrirPuertaAgua() = false


method presionar()
{
Expand All @@ -89,6 +101,8 @@ object watergirl inherits Personaje (position = game.at(0, 2)) {
method image() = "watergirl3.png"
method tocarFuego(){self.morir()}
method tocarAgua(){}
method puedeAbrirPuertaFuego() = false
method puedeAbrirPuertaAgua() = true

method moverElemento()
{
Expand Down

0 comments on commit ff1c8c9

Please sign in to comment.