Skip to content

Commit

Permalink
Logica de niveles a la mitad
Browse files Browse the repository at this point in the history
  • Loading branch information
elin-winter committed Oct 10, 2024
1 parent b846e21 commit 781aa8c
Show file tree
Hide file tree
Showing 6 changed files with 119 additions and 135 deletions.
Binary file added assets/f_door.png
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/w_door.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions characters.wlk
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ class Fireboy inherits Character {
override method tipo() = fuego

override method image() {
return "fireboy.png"
return "Fireboy.png"
}
}

Expand All @@ -73,7 +73,7 @@ class Watergirl inherits Character {
override method tipo() = agua

override method image() {
return "watergirl.png"
return "Watergirl.png"
}
}

Expand Down
93 changes: 81 additions & 12 deletions config.wlk
Original file line number Diff line number Diff line change
@@ -1,19 +1,88 @@
import invisible_objects.*
import characters.*
import elements.*

object settings {
method init (){
game.title("FireBoyWaterGirlGame")
game.boardGround("nivel_1.png")
game.height(29)
game.width(39)
game.cellSize(36) // 1404x1044 / 39x29 = 36px
}

method init (background, height, width, cellSize){
game.title("FireBoyWaterGirlGame")
game.boardGround(background)
game.height(height)
game.width(width)
game.cellSize(cellSize) // 1404x1044 // 39x29 = 36px
}
method generarMarco(){
(0..38).forEach { x => game.addVisual(new Border(posX = x, posY = 0))}
(0..38).forEach { x => game.addVisual(new Border(posX = x, posY = 28))}
(0..28).forEach{ y => game.addVisual(new Border(posX = 0, posY = y))}
(0..28).forEach{ y => game.addVisual(new Border(posX = 38, posY = y))}
(0..38).forEach { x => game.addVisual(new Border(posX = x, posY = 0))}
(0..38).forEach { x => game.addVisual(new Border(posX = x, posY = 28))}
(0..28).forEach{ y => game.addVisual(new Border(posX = 0, posY = y))}
(0..28).forEach{ y => game.addVisual(new Border(posX = 38, posY = y))}
}
}

class Level {

// ---------------- REFERENCIAS
const fireboy = new Fireboy(positionX = 3, positionY = 1)
const watergirl = new Watergirl(positionX = 1, positionY = 1)
const puertaFireboy = new Puerta(posX = 30, posY = 22, image = "f_door.png", tipo = fuego)
const puertaWatergirl = new Puerta(posX = 34, posY = 22, image = "w_door.png", tipo = agua)
const diamantes = []

// ---------------- JUEGO PRINCIPAL

method start(nroNivel) {
self.setupCharacters()
self.setupControls()
self.setupCollisions()
self.setupDoors()
self.setupDiamonds(nroNivel)

game.start()
}
method setupCharacters() {
game.addVisual(fireboy)
game.addVisual(watergirl)
}

method setupControls() {
// Controles para Watergirl
keyboard.a().onPressDo({ watergirl.moveLeft() })
keyboard.d().onPressDo({ watergirl.moveRight() })
keyboard.w().onPressDo({ watergirl.jump() })

// Controles para Fireboy
keyboard.left().onPressDo({ fireboy.moveLeft() })
keyboard.right().onPressDo({ fireboy.moveRight() })
keyboard.up().onPressDo({ fireboy.jump() })
}
method setupCollisions() {
game.onCollideDo(fireboy, {element => element.colision(fireboy)})
game.onCollideDo(watergirl, {element => element.colision(watergirl)})
}

method setupDoors() {
game.addVisual(puertaFireboy)
game.addVisual(puertaWatergirl)
}
method setupDiamonds(nroNivel) {

diamantes.clear()

if (nroNivel == 1) {
diamantes.add(new DiamanteRojo(posX = 28, posY = 3))
diamantes.add(new DiamanteRojo(posX = 9, posY = 14))
diamantes.add(new DiamanteRojo(posX = 10, posY = 25))
diamantes.add(new DiamanteRojo(posX = 22, posY = 23))
diamantes.add(new DiamanteAzul(posX = 24, posY = 13))
diamantes.add(new DiamanteAzul(posX = 20, posY = 3))
diamantes.add(new DiamanteAzul(posX = 4, posY = 22))
diamantes.add(new DiamanteAzul(posX = 18, posY = 23))
} else if (nroNivel == 2) {
diamantes.add(new DiamanteRojo(posX = 28, posY = 3))
// agregar mas, lo puse solo para que no saltara error

}

diamantes.forEach { diamante => game.addVisual(diamante) }
}
}

33 changes: 33 additions & 0 deletions elements.wlk
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,39 @@ class DiamanteVerde inherits Diamante {
}
*/



// ------------------- Puerta

class Puerta {
const posX
const posY
const image
const tipo

method position() = game.at(posX, posY)

method esAtravesable() = true

method image() = image

method tipo() = tipo

method colision() {

/*
game.showMessage("¡Nivel completado! Pasando al siguiente nivel...")
game.wait(2) // Esperar 2 segundos antes de pasar al siguiente nivel
*/
}
}






/*
// ------------------ Obstaculos
Expand Down
124 changes: 3 additions & 121 deletions main.wpgm
Original file line number Diff line number Diff line change
@@ -1,132 +1,14 @@
import wollok.game.*
import characters.*
import elements.*
import invisible_objects.*
import config.*

program FireBoyWaterGirlGame {

// Juego

settings.init()
settings.init("nivel_1.png", 29, 39, 36)
settings.generarMarco()

// Personajes

const fireboy = new Fireboy(positionX = 3, positionY = 1)
const watergirl = new Watergirl(positionX = 1, positionY = 1)

game.addVisual(fireboy)
game.addVisual(watergirl)

// Diamantes

const diamantes = [
new DiamanteRojo(posX = 28, posY = 3),
new DiamanteRojo(posX = 9, posY = 14),
new DiamanteRojo(posX = 10, posY = 25),
new DiamanteRojo(posX = 22, posY = 23),
new DiamanteAzul(posX = 24, posY = 13),
new DiamanteAzul(posX = 20, posY = 3),
new DiamanteAzul(posX = 4, posY = 22),
new DiamanteAzul(posX = 18, posY = 23)
]

// Agregar todos los diamantes al juego
diamantes.forEach {diamante => game.addVisual(diamante)}

// Movimientos

keyboard.a().onPressDo({ watergirl.moveLeft()})
keyboard.d().onPressDo({ watergirl.moveRight() })
keyboard.w().onPressDo({ watergirl.jump() })

keyboard.left().onPressDo({ fireboy.moveLeft() })
keyboard.right().onPressDo({ fireboy.moveRight() })
keyboard.up().onPressDo({ fireboy.jump() })

// Manejar Colisiones ()

game.onCollideDo(fireboy, {element => element.colision(fireboy)})
game.onCollideDo(watergirl, {element => element.colision(watergirl)})

game.start()



/*

//////////////////// ELI, NO TOCAR

// Inicializar Juego

settings.init()
settings.generarMarco()

// Empezar con nivel 1

const nivel1 = new Level()
nivel1.start("nivel_1.png", 1)


////////////////////

class Level {
const fireboy = new Fireboy(positionX = 3, positionY = 1)
const watergirl = new Watergirl(positionX = 1, positionY = 1)
const diamantes = []

method start(background, nroNivel) {
game.clear()
game.boardGround(backgroundImage)
nivel1.start(1)

setupCharacters()
setupDiamonds(nroNivel)
setupControls()
setupCollisions()
// FALTA PONER QUE HACER CUANDO TERMINA EL NIVEL, POR EJ PASAR AL

game.start()
}

method setupCharacters() {
game.addVisual(fireboy)
game.addVisual(watergirl)
}

method setupControls() {
// Controles para Watergirl
keyboard.a().onPressDo({ watergirl.moveLeft() })
keyboard.d().onPressDo({ watergirl.moveRight() })
keyboard.w().onPressDo({ watergirl.jump() })

// Controles para Fireboy
keyboard.left().onPressDo({ fireboy.moveLeft() })
keyboard.right().onPressDo({ fireboy.moveRight() })
keyboard.up().onPressDo({ fireboy.jump() })
}

method setupCollisions(onComplete) {
game.onCollideDo(fireboy, { element => colision(fireboy, element) })
game.onCollideDo(watergirl, { element => colision(watergirl, element) })
}

method setupDiamonds(nroNivel) {

if(nroNivel == 1)
const diamantes = [
new DiamanteRojo(posX = 28, posY = 3),
new DiamanteRojo(posX = 9, posY = 14),
new DiamanteAzul(posX = 24, posY = 13)
]
else if(nroNivel == 2)
// conf diamantes nivel 2

diamantes.forEach { diamante =>
game.addVisual(diamante)
}
}
}


*/
}

0 comments on commit 781aa8c

Please sign in to comment.