Skip to content

Commit

Permalink
correcciones
Browse files Browse the repository at this point in the history
  • Loading branch information
ramirob03 committed Oct 21, 2024
1 parent 8ab69de commit 9f6301f
Show file tree
Hide file tree
Showing 8 changed files with 193 additions and 113 deletions.
Binary file added assets/explosion.wav
Binary file not shown.
Binary file removed assets/freeway_1.jpg
Binary file not shown.
Binary file added 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.
118 changes: 16 additions & 102 deletions example.wlk
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import wollok.game.*
import handlers.*
import visuales.*

object juegoDeAutos {

Expand All @@ -7,50 +9,19 @@ object juegoDeAutos {
game.height(12)
game.cellSize(50)
game.boardGround("freeway.png")
game.addVisualCharacter(auto)
game.addVisual(contador)
game.addVisual(contadorNafta)
}

method configurarTeclado() {
keyboard.left().onPressDo({ auto.moverIzquierda() })
keyboard.right().onPressDo({ auto.moverDerecha() })

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

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

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

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

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

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

game.schedule(3300, {manejadorObstaculos.agregarObstaculos()
manejadorObstaculos.agregarObstaculos()
})

}
}

object auto {
method image() = "porsche.png"

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

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

method moverIzquierda() {
Expand All @@ -65,11 +36,6 @@ object auto {
}
}

method chocarConObstaculo() {}

method chocarConAutoEnemigo() {
game.stop()
}
}

object gasolina {
Expand All @@ -89,6 +55,9 @@ object gasolina {
}
}

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

class Obstaculo {
Expand All @@ -109,6 +78,10 @@ class Obstaculo {
}
}

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

}

class AutoEnemigo {
Expand All @@ -127,68 +100,9 @@ class AutoEnemigo {
position = game.at(0.randomUpTo(game.width() - 1), game.height() - 1)
}
}
}

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

method position () = game.at(7, 11)

method aumentarPuntos() {
puntos += 10
}

method text() = " Puntos: " + puntos
method textColor() = celeste

}

object contadorNafta {
var nafta = 100

method perderNafta() {
if (nafta > 0){
nafta = nafta - 2
} else {
game.stop()
}

}

const property celeste = "279df5cc"

method position () = game.at(0, 0)

method text() = " Nafta: " + nafta
method textColor() = celeste

}

object manejadorAutos {
const autos = new List()

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

method paraCadaAuto() {
autos.forEach{autoEnemigo => autoEnemigo.moverseHaciaAbajo()}
method chocar() {
game.stop()
}
}

object manejadorObstaculos {
const obstaculos = new List()

method agregarObstaculos() {
const nuevoObstaculo = new Obstaculo ()
obstaculos.add(nuevoObstaculo)
game.addVisual(nuevoObstaculo)
}

method paraCadaObstaculo() {
obstaculos.forEach{obstaculo => obstaculo.moverseHaciaAbajo()}
}
}
105 changes: 105 additions & 0 deletions handlers.wlk
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
import example.*

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

method position () = game.at(7, 11)

method aumentarPuntos() {
puntos += 10
}

method text() = " Puntos: " + puntos
method textColor() = celeste

}

object contadorNafta {
var nafta = 100

method perderNafta() {
if (nafta > 0){
nafta = nafta - 2
} else {
game.stop()
}

}

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

const property celeste = "279df5cc"

method position () = game.at(0, 0)

method text() = " Nafta: " + nafta
method textColor() = celeste

}

object manejadorAutos {
const autos = new List()

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

method paraCadaAuto() {
autos.forEach{autoEnemigo => autoEnemigo.moverseHaciaAbajo()}
}
}

object manejadorObstaculos {
const obstaculos = new List()

method agregarObstaculos() {
const nuevoObstaculo = new Obstaculo ()
obstaculos.add(nuevoObstaculo)
game.addVisual(nuevoObstaculo)
}

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

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.onCollideDo(auto, {visual => visual.chocar()})
}

}

/*object sonidoExplosion{
method play(){
game.sound("explosion.wav").play()
}
}
object cartelFinal{
var position = game.center()
method image() = "gameover.png"
method text () = "GAME OVER"
method iniciar(){
game.addVisual(self)
sonidoExplosion.play()
game.stop()
}
}
program soundProgram {
const rain = game.sound("light-rain.mp3")
rain.shouldLoop(true)
game.schedule(500, { rain.play()} )
game.start()
}
*/
11 changes: 5 additions & 6 deletions main.wpgm
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
import wollok.game.*
import example.*
import handlers.*
import visuales.*


program juego {
juegoDeAutos.iniciar()
cargarVisuales.iniciar()
manejadorColisiones.iniciar()
juegoDeAutos.configurarTeclado()
game.start()

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(1000, "verificarNafta", {if (contadorNafta.nafta <= 0) game.stop()})
}
27 changes: 22 additions & 5 deletions pruebas.wtest
Original file line number Diff line number Diff line change
@@ -1,9 +1,26 @@
/*import pepita.*
/*import example.*
import handlers.*

describe "group of tests for pepita" {
describe "group of tests for auto" {

test "pepita has initial energy" {
assert.equals(100, pepita.energy())
test "auto has nafta" {
assert.equals(100, contadorNafta.nafta)
}

}*/
test "auto pierde nafta " {

}

test "auto choca " {

}

test "posicion inicial auto" {
auto.position() shouldBe game.at(1, 2)
auto.moverDerecha()
auto.position() shouldBe game.at(2, 2)
}

}

*/
45 changes: 45 additions & 0 deletions visuales.wlk
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import example.*
import wollok.game.*
import handlers.*

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

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()
})

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

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

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

game.schedule(3300, {manejadorObstaculos.agregarObstaculos()
manejadorObstaculos.agregarObstaculos()
})
}
}

0 comments on commit 9f6301f

Please sign in to comment.