Skip to content

Commit

Permalink
final sin sonidos
Browse files Browse the repository at this point in the history
  • Loading branch information
ramirob03 committed Oct 21, 2024
1 parent 648cb21 commit 316e9b7
Show file tree
Hide file tree
Showing 6 changed files with 65 additions and 40 deletions.
Binary file added assets/fondo.mp3
Binary file not shown.
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.
22 changes: 17 additions & 5 deletions example.wlk
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -20,7 +22,6 @@ object juegoDeAutos {

object auto {
var position = game.at(1, 2)

method image() = "porsche.png"
method position() = position

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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()
}

}
75 changes: 45 additions & 30 deletions handlers.wlk
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import example.*
import visuales.*

object contador {
var property puntos = 0
Expand All @@ -16,7 +17,7 @@ object contador {
}

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

method agregarNafta(cantidad) {
if (nafta > 0){
Expand Down Expand Up @@ -49,11 +50,10 @@ object manejadorAutos {
autos.forEach{autoEnemigo => autoEnemigo.moverseHaciaAbajo()}
}

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

object manejadorObstaculos {
Expand All @@ -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 {
Expand All @@ -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()
})
}
}
*/
}
4 changes: 2 additions & 2 deletions main.wpgm
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@ program juego {
juegoDeAutos.configurarTeclado()
game.start()

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

}
}
4 changes: 1 addition & 3 deletions visuales.wlk
Original file line number Diff line number Diff line change
Expand Up @@ -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)})
Expand Down

0 comments on commit 316e9b7

Please sign in to comment.