Skip to content

Commit

Permalink
hice un generador de enemigos
Browse files Browse the repository at this point in the history
  • Loading branch information
NahuelMarek committed Oct 2, 2024
1 parent 6524cf0 commit 0d4b43b
Show file tree
Hide file tree
Showing 6 changed files with 86 additions and 12 deletions.
Binary file added assets/zombie.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
16 changes: 16 additions & 0 deletions fantasma.wlk
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
class Fantasmas {
const position = new MutablePosition()
var property estado= "movil"
var property zombie = "zombie"

method position() = position

method movete() {
if(self.estado()=="movil")
position.goLeft(1)
else zombie.moveteDerecha()
}
method moveteDerecha() {
position.goRight(1)
}
}
22 changes: 22 additions & 0 deletions generadorDeEnemigos.wlk
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import zombie.*
object generadorDeEnemigos {
var nombreEnemigo = 0
const enemigo = #{}

method nombre() = nombreEnemigo
method sumarEnemigo() {
nombreEnemigo+=1
}
method generarEnemigo(numero){
if (numero==1) {
var nombreParaEnemigo = self.nombre()
nombreParaEnemigo = new ZombiesNormales()
enemigo.add(nombreParaEnemigo)
return game.addVisual(nombreParaEnemigo)
}
return 0
}
method moverEnemigos() {
enemigo.forEach({zombie => zombie.movete()})
}
}
24 changes: 19 additions & 5 deletions main.wpgm
Original file line number Diff line number Diff line change
@@ -1,16 +1,30 @@
import wollok.game.*

import pepita.*

import zombie.*
import fantasma.*
import generadorDeEnemigos.*
program PepitaGame {
game.title("Pepita")
game.height(10)
game.width(10)
game.height(5)
game.width(15)
game.cellSize(100)

/*game.addVisual(Fantasmas)*/
game.addVisual(pepita)

keyboard.d().onPressDo({ pepita.moverseDerecha(1) })
keyboard.a().onPressDo({ pepita.moverseIzquierda(1) })
keyboard.w().onPressDo({ pepita.moverseArriba(1) })
keyboard.s().onPressDo({ pepita.moverseAbajo(1) })
game.onTick(7000, "generar nuevo Enemigo", {generadorDeEnemigos.generarEnemigo(1)
generadorDeEnemigos.sumarEnemigo()})
game.onTick(7000, "mover enemigo", {generadorDeEnemigos.moverEnemigos()})

keyboard.w().onPressDo({ pepita.fly(1) })
game.whenCollideDo(pepita, { elemento =>
elemento.estado("frenado")
})



game.start()
}
18 changes: 11 additions & 7 deletions pepita.wlk
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
object pepita {
var energy = 100
const position = new MutablePosition(x=0, y=0)

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

method energy() = energy

method fly(minutes) {
energy = energy - minutes * 3
position.goRight(minutes)
position.goUp(minutes)
method moverseDerecha(casillas) {
position.goRight(casillas)
}
method moverseIzquierda(casillas) {
position.goLeft(casillas)
}
method moverseArriba(casillas) {
position.goUp(casillas)
}
method moverseAbajo(casillas) {
position.goDown(casillas)
}

}
18 changes: 18 additions & 0 deletions zombie.wlk
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@

class ZombiesNormales {
const position = new MutablePosition(x=10, y=0.randomUpTo(5).truncate(0))
var property estado= "movil"
method position() = position
var property imagen = "golondrina.png"
method image() = imagen

method movete() {
if(self.estado()=="movil")
return position.goLeft(1)
else self.estado("frenado")
}
method moveteDerecha() {
return position.goRight(1)
}
}

0 comments on commit 0d4b43b

Please sign in to comment.