Skip to content

Commit

Permalink
Correcciones en vivo
Browse files Browse the repository at this point in the history
  • Loading branch information
ramirob03 committed Oct 21, 2024
1 parent 9f6301f commit 648cb21
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 54 deletions.
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.
23 changes: 12 additions & 11 deletions example.wlk
Original file line number Diff line number Diff line change
Expand Up @@ -26,26 +26,21 @@ object auto {

method moverIzquierda() {
if (position.x() > 0) {
position = game.at(position.x() - 1, position.y())
position = position.left(1)
}
}

method moverDerecha() {
if (position.x() < game.width() - 1) {
position = game.at(position.x() + 1, position.y())
position = position.right(1)
}
}

}

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

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

method moverseHaciaAbajo() {
if (position.y() > 0) {
Expand All @@ -58,6 +53,11 @@ object gasolina {
method chocar() {
contadorNafta.agregarNafta(10)
}

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

class Obstaculo {
Expand All @@ -72,7 +72,7 @@ class Obstaculo {

method moverseHaciaAbajo() {
if (position.y() > 0) {
position = game.at(position.x(), position.y() - 1)
position = position.down(1)
} else {
position = game.at(0.randomUpTo(game.width() - 1), game.height() - 1)
}
Expand All @@ -95,14 +95,15 @@ class AutoEnemigo {

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

method chocar() {
game.stop()
cartelFinal.iniciar()
//game.stop()
}
}

53 changes: 39 additions & 14 deletions handlers.wlk
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import example.*

object contador {
var puntos = 0
var property puntos = 0
const property celeste = "279df5cc"

method position () = game.at(7, 11)
Expand All @@ -16,21 +16,17 @@ object contador {
}

object contadorNafta {
var nafta = 100
var property nafta = 100

method perderNafta() {
method agregarNafta(cantidad) {
if (nafta > 0){
nafta = nafta - 2
nafta = 100.min(nafta + cantidad)
} else {
game.stop()
cartelFinal.iniciar()
}

}

method agregarNafta(cantidad) {
nafta = nafta + cantidad
}

const property celeste = "279df5cc"

method position () = game.at(0, 0)
Expand All @@ -52,6 +48,12 @@ object manejadorAutos {
method paraCadaAuto() {
autos.forEach{autoEnemigo => autoEnemigo.moverseHaciaAbajo()}
}

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

object manejadorObstaculos {
Expand All @@ -66,15 +68,21 @@ object manejadorObstaculos {
method paraCadaObstaculo() {
obstaculos.forEach{obstaculo => obstaculo.moverseHaciaAbajo()}
}

/*
method sacarObstaculos(){
obstaculos.forEach{obstaculo => game.removeVisual(obstaculo)}
}
*/
}

object manejadorColisiones {
method iniciar(){
game.onTick(300, "moverAutos", { manejadorAutos.paraCadaAuto() })
game.onTick(300, "moverGasolina", { gasolina.moverseHaciaAbajo() })
game.onTick(300, "moverObstaculos", { manejadorObstaculos.paraCadaObstaculo() })
game.onTick(100, "contadores", { contador.aumentarPuntos() })
game.onTick(1000, "contadores", { contadorNafta.perderNafta() })
game.onTick(100, "aumentarPuntos", { contador.aumentarPuntos() })
game.onTick(1000, "disminuirNafta", { contadorNafta.agregarNafta(-2) })
game.onCollideDo(auto, {visual => visual.chocar()})
}

Expand All @@ -85,21 +93,38 @@ object manejadorColisiones {
game.sound("explosion.wav").play()
}
}
*/
object cartelFinal{
var position = game.center()
var property position = game.origin()

method image() = "gameover.png"
method text () = "GAME OVER"
method iniciar(){
game.addVisual(self)
sonidoExplosion.play()
game.stop()
//sonidoExplosion.play()
game.schedule(300, {game.stop()})
}
}
/*
program soundProgram {
const rain = game.sound("light-rain.mp3")
rain.shouldLoop(true)
game.schedule(500, { rain.play()} )
game.start()
}
object reiniciarJuego{
method iniciar() {
game.start()
game.clear()
game.removeVisual(cartelFinal)
contadorNafta.nafta(100)
contador.puntos(0)
manejadorAutos.sacarAutos()
manejadorObstaculos.sacarObstaculos()
gasolina.restaurarUbicacion()
}
}
*/
2 changes: 2 additions & 0 deletions main.wpgm
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,6 @@ program juego {
juegoDeAutos.configurarTeclado()
game.start()

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

}
48 changes: 19 additions & 29 deletions visuales.wlk
Original file line number Diff line number Diff line change
Expand Up @@ -3,43 +3,33 @@ import wollok.game.*
import handlers.*

object cargarVisuales {
const tiemposAuto = [300, 1200, 2100, 3000]
const tiemposObstaculo = [1500, 3300]

method iniciar() {
game.addVisualCharacter(auto)
game.addVisual(contador)
game.addVisual(contadorNafta)
game.addVisual(gasolina)

game.schedule(300, {manejadorAutos.agregarAutosFilaSuperior()
manejadorAutos.agregarAutosFilaSuperior()
manejadorAutos.agregarAutosFilaSuperior()
manejadorAutos.agregarAutosFilaSuperior()
})

game.schedule(1200, {manejadorAutos.agregarAutosFilaSuperior()
manejadorAutos.agregarAutosFilaSuperior()
manejadorAutos.agregarAutosFilaSuperior()
manejadorAutos.agregarAutosFilaSuperior()
})

game.schedule(2100, {manejadorAutos.agregarAutosFilaSuperior()
manejadorAutos.agregarAutosFilaSuperior()
manejadorAutos.agregarAutosFilaSuperior()
manejadorAutos.agregarAutosFilaSuperior()
})
tiemposAuto.forEach({tiempo => scheduleAutos.iniciar(tiempo)})
tiemposObstaculo.forEach({tiempo => scheduleObstaculo.iniciar(tiempo)})
game.schedule(3300, {game.addVisual(gasolina)})
}
}

game.schedule(3000, {manejadorAutos.agregarAutosFilaSuperior()
manejadorAutos.agregarAutosFilaSuperior()
object scheduleAutos {
method iniciar(contador){
game.schedule(contador, {manejadorAutos.agregarAutosFilaSuperior()
manejadorAutos.agregarAutosFilaSuperior()
manejadorAutos.agregarAutosFilaSuperior()
})

game.schedule(3300, {game.addVisual(gasolina)})

game.schedule(1500, {manejadorObstaculos.agregarObstaculos()
manejadorObstaculos.agregarObstaculos()
})
manejadorAutos.agregarAutosFilaSuperior()})
}
}

game.schedule(3300, {manejadorObstaculos.agregarObstaculos()
manejadorObstaculos.agregarObstaculos()
})
object scheduleObstaculo {
method iniciar(contador){
game.schedule(contador, {manejadorObstaculos.agregarObstaculos()
manejadorObstaculos.agregarObstaculos()})
}
}

0 comments on commit 648cb21

Please sign in to comment.