diff --git a/assets/fondo.mp3 b/assets/fondo.mp3 new file mode 100644 index 0000000..94f672d Binary files /dev/null and b/assets/fondo.mp3 differ diff --git a/assets/gameover.png b/assets/gameover.png index 2bfc010..7d4ed39 100644 Binary files a/assets/gameover.png and b/assets/gameover.png differ diff --git a/example.wlk b/example.wlk index 5f94e37..d9cb008 100644 --- a/example.wlk +++ b/example.wlk @@ -9,6 +9,8 @@ object juegoDeAutos { game.height(12) game.cellSize(50) game.boardGround("freeway.png") + game.addVisualCharacter(auto) + game.onCollideDo(auto, {visual => visual.chocar()}) } method configurarTeclado() { @@ -20,7 +22,6 @@ object juegoDeAutos { object auto { var position = game.at(1, 2) - method image() = "porsche.png" method position() = position @@ -55,14 +56,12 @@ object gasolina { } method restaurarUbicacion() { - game.removeVisual(self) position = game.at(0.randomUpTo(game.width() - 1), 9) } } class Obstaculo { - // PosiciĆ³n inicial aleatoria en la fila superior del tablero - var position = game.at(0.randomUpTo(game.width() - 1), 9) + var position = game.at(0.randomUpTo(game.width() - 1), 12) method image() = "cono.png" method position() = position @@ -102,8 +101,21 @@ class AutoEnemigo { } method chocar() { + sonido.explosion() cartelFinal.iniciar() - //game.stop() } } +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() + } + +} \ No newline at end of file diff --git a/handlers.wlk b/handlers.wlk index 565fa4c..cb9aa38 100644 --- a/handlers.wlk +++ b/handlers.wlk @@ -1,4 +1,5 @@ import example.* +import visuales.* object contador { var property puntos = 0 @@ -16,7 +17,7 @@ object contador { } object contadorNafta { - var property nafta = 100 + var nafta = 100 method agregarNafta(cantidad) { if (nafta > 0){ @@ -49,11 +50,10 @@ object manejadorAutos { autos.forEach{autoEnemigo => autoEnemigo.moverseHaciaAbajo()} } - /* method sacarAutos(){ autos.forEach{autoEnemigo => game.removeVisual(autoEnemigo)} + autos.clear() } - */ } object manejadorObstaculos { @@ -68,12 +68,11 @@ object manejadorObstaculos { method paraCadaObstaculo() { obstaculos.forEach{obstaculo => obstaculo.moverseHaciaAbajo()} } - - /* + method sacarObstaculos(){ obstaculos.forEach{obstaculo => game.removeVisual(obstaculo)} + obstaculos.clear() } - */ } object manejadorColisiones { @@ -83,48 +82,64 @@ object manejadorColisiones { game.onTick(300, "moverObstaculos", { manejadorObstaculos.paraCadaObstaculo() }) game.onTick(100, "aumentarPuntos", { contador.aumentarPuntos() }) game.onTick(1000, "disminuirNafta", { contadorNafta.agregarNafta(-2) }) - game.onCollideDo(auto, {visual => visual.chocar()}) } } -/*object sonidoExplosion{ - method play(){ - game.sound("explosion.wav").play() - } -} -*/ object cartelFinal{ var property position = game.origin() - method image() = "gameover.png" - method text () = "GAME OVER" 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) - //sonidoExplosion.play() - game.schedule(300, {game.stop()}) + game.addVisual(textoGameOver) + game.addVisual(textoPuntaje) + game.addVisual(textoReinicio) } } -/* -program soundProgram { - const rain = game.sound("light-rain.mp3") - rain.shouldLoop(true) - game.schedule(500, { rain.play()} ) - game.start() +object textoGameOver { + 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) +} + +object textoReinicio { + const property negro = "000000e8" + method textColor() = negro + method text () = "PRESIONE R PARA REINICIAR" + method position() = game.at(4, 5) +} object reiniciarJuego{ method iniciar() { - game.start() - game.clear() game.removeVisual(cartelFinal) - contadorNafta.nafta(100) + game.removeVisual(textoGameOver) + game.removeVisual(textoPuntaje) + game.removeVisual(textoReinicio) + contadorNafta.agregarNafta(100) contador.puntos(0) - manejadorAutos.sacarAutos() - manejadorObstaculos.sacarObstaculos() gasolina.restaurarUbicacion() + game.schedule(300, { + cargarVisuales.iniciar() + manejadorColisiones.iniciar() + }) } -} -*/ \ No newline at end of file +} \ No newline at end of file diff --git a/main.wpgm b/main.wpgm index 100c2c3..69f60dd 100644 --- a/main.wpgm +++ b/main.wpgm @@ -11,6 +11,6 @@ program juego { juegoDeAutos.configurarTeclado() game.start() - //keyboard.r().onPressDo({reiniciarJuego.iniciar()}) + keyboard.r().onPressDo({reiniciarJuego.iniciar()}) -} +} \ No newline at end of file diff --git a/visuales.wlk b/visuales.wlk index dd2869d..f37911b 100644 --- a/visuales.wlk +++ b/visuales.wlk @@ -7,10 +7,8 @@ object cargarVisuales { const tiemposObstaculo = [1500, 3300] method iniciar() { - game.addVisualCharacter(auto) game.addVisual(contador) - game.addVisual(contadorNafta) - game.addVisual(gasolina) + game.addVisual(contadorNafta) tiemposAuto.forEach({tiempo => scheduleAutos.iniciar(tiempo)}) tiemposObstaculo.forEach({tiempo => scheduleObstaculo.iniciar(tiempo)})