Skip to content

Commit

Permalink
Bordes implementados | Gravedad arreglada
Browse files Browse the repository at this point in the history
  • Loading branch information
AscarlatoUTN committed Oct 9, 2024
1 parent ac66370 commit 6e47ac7
Show file tree
Hide file tree
Showing 6 changed files with 88 additions and 30 deletions.
Binary file added assets/g_diamond.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
44 changes: 32 additions & 12 deletions characters.wlk
Original file line number Diff line number Diff line change
@@ -1,36 +1,56 @@
class Character {
const position = new MutablePosition(x=1, y=1)

const positionX
const positionY

var property position = new MutablePosition (x=positionX, y=positionY)

method esAtravesable () = true

const unidadMovimiento = 1

method position() = position
method colision(personaje) {}

method image() {
return "" // Sobrescrito en las subclase
}

method moveLeft() {
const nuevaPosicion = position.left(unidadMovimiento)
if (self.puedeAtravesar(nuevaPosicion))
position.goLeft(unidadMovimiento)
}

method moveRight() {
const nuevaPosicion = position.right(unidadMovimiento)
if (self.puedeAtravesar(nuevaPosicion))
position.goRight(unidadMovimiento)
}

method jump() {
position.goUp(unidadMovimiento)
game.schedule(100, {position.goUp(unidadMovimiento)})
game.schedule(200, {position.goUp(unidadMovimiento)})
game.schedule(300, {position.goUp(unidadMovimiento)})
self.fall()
[100, 200, 300].forEach { num => game.schedule(num, { self.moveUp() }) }
game.schedule(800, {game.onTick(100, "Fall", {self.moveDown()})})

}

method moveUp() {
const nuevaPosicion = position.up(unidadMovimiento)
if (self.puedeAtravesar(nuevaPosicion))
position.goUp(unidadMovimiento)
}

method fall() {
game.schedule(800, {position.goDown(unidadMovimiento)})
game.schedule(900, {position.goDown(unidadMovimiento)})
game.schedule(1000, {position.goDown(unidadMovimiento)})
game.schedule(1100, {position.goDown(unidadMovimiento)})
method moveDown() {
const nuevaPosicion = position.down(unidadMovimiento)
if (self.puedeAtravesar(nuevaPosicion)){
position.goDown(unidadMovimiento)
}
else
game.removeTickEvent("Fall")
}

method puedeAtravesar(nuevaPosicion) = game.getObjectsIn(nuevaPosicion).all{obj => obj.esAtravesable()}


}

class Fireboy inherits Character {
Expand Down
18 changes: 18 additions & 0 deletions config.wlk
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import invisible_objects.*
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 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))}
}
}
2 changes: 2 additions & 0 deletions elements.wlk
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ class Diamante {
const posX
const posY

method esAtravesable() = true

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

method colision(personaje) {
Expand Down
17 changes: 17 additions & 0 deletions invisible_objects.wlk
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
class Border {

var posX
var posY

method esAtravesable() = false

method position(positionX, positionY) {
posX = positionX
posY = positionY
}

var property position = new MutablePosition (x=posX, y=posY)


}

37 changes: 19 additions & 18 deletions main.wpgm
Original file line number Diff line number Diff line change
@@ -1,34 +1,36 @@
import wollok.game.*
import characters.*
import elements.*

import invisible_objects.*
import config.*

program FireBoyWaterGirlGame {

// Juego

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

// Personajes

const fireboy = new Fireboy()
const watergirl = new Watergirl()

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

// Diamantes

const diamantesRojos = [
new DiamanteRojo(posX = 5, posY = 1),
new DiamanteRojo(posX = 8, posY = 1)] // Diamantes rojos
new DiamanteRojo(posX = 28, posY = 3),
new DiamanteRojo(posX = 9, posY = 14), // Diamantes rojos
new DiamanteRojo(posX = 10, posY = 25), // Diamantes rojos
new DiamanteRojo(posX = 22, posY = 23)] // Diamantes rojos
const diamantesAzules = [
new DiamanteAzul(posX = 20, posY = 3),
new DiamanteAzul(posX = 3, posY = 1)] // Diamantes azules
new DiamanteAzul(posX = 24, posY = 13), // Diamantes azules
new DiamanteAzul(posX = 20, posY = 3),
new DiamanteAzul(posX = 4, posY = 22),
new DiamanteAzul(posX = 18, posY = 23)]

// Agregar todos los diamantes rojos al juego
diamantesRojos.forEach{diamante => game.addVisual(diamante)}
Expand All @@ -45,12 +47,11 @@ program FireBoyWaterGirlGame {
keyboard.left().onPressDo({ fireboy.moveLeft() })
keyboard.right().onPressDo({ fireboy.moveRight() })
keyboard.up().onPressDo({ fireboy.jump() })


// Manejar Colisiones (por ahora solo esta las de diamantes)

// Manejar Colisiones ()

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

game.start()
}

0 comments on commit 6e47ac7

Please sign in to comment.