Last active
December 30, 2015 12:19
-
-
Save irvingprog/7828479 to your computer and use it in GitHub Desktop.
PilasWeb: Vaca Voladora
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ejemplo { | |
vaca_voladora; | |
constructor() { | |
this.vaca_voladora = Vaca_Voladora; | |
} | |
} | |
class FondoCielo extends Fondo { | |
constructor() { | |
super("fondos/nubes.png", 0, 0); | |
} | |
} | |
class Volando extends Comportamiento { | |
paso; | |
cuadros_de_animacion; | |
iniciar(receptor) { | |
super.iniciar(receptor); | |
this.cuadros_de_animacion = [2,3,4,5,6,7,8,9,10] | |
this.paso = 0; | |
} | |
actualizar() { | |
this.paso += .1; | |
if (this.paso > this.cuadros_de_animacion.length) | |
this.paso = 0; | |
this.receptor._imagen.definir_cuadro(this.cuadros_de_animacion[Math.floor(this.paso)]); | |
this.receptor.y += .03; | |
this.receptor.x += .03; | |
} | |
} | |
class Golpeado extends Comportamiento { | |
iniciar(receptor) { | |
super.iniciar(receptor); | |
this.receptor._imagen.definir_cuadro(1); | |
this.receptor.x = [this.receptor.x - 15]; | |
pilas.mundo.agregar_tarea_una_vez(3, this.receptor.volar, {}, this.receptor); | |
} | |
} | |
class Ganando extends Comportamiento { | |
iniciar(receptor) { | |
super.iniciar(receptor) | |
this.receptor._imagen.definir_cuadro(0); | |
pilas.mundo.agregar_tarea_una_vez(2, this.receptor.volar, {}, this.receptor); | |
} | |
} | |
class Mover extends Comportamiento { | |
iniciar(receptor) { | |
super.iniciar(receptor); | |
this.receptor.x = 320+Math.floor(Math.random()*200); | |
this.receptor.y = -240+Math.floor(Math.random()*480); | |
} | |
actualizar() { | |
this.receptor.x -= 3; | |
if (this.receptor.derecha<-320) | |
this.receptor.eliminar(); | |
} | |
} | |
class Liberar extends Comportamiento { | |
iniciar(receptor) { | |
super.iniciar(receptor); | |
this.receptor.imagen = "estrella_liberada.png"; | |
} | |
actualizar() { | |
this.receptor.x -= 8; | |
this.receptor.escala += 0.1; | |
this.receptor.transparencia += 3; | |
if (this.receptor.transparencia>50) | |
this.receptor.eliminar(); | |
} | |
} | |
class Vaca extends Actor { | |
constructor() { | |
var imagen = pilas.imagenes.cargar_grilla('vaca.png', 11); | |
super(imagen, 0, 0); | |
this.centro_x = 60; | |
this.radio_de_colision = 30; | |
this.aprender(pilas.habilidades.MoverseConElTeclado); | |
this.volar(); | |
} | |
volar() { | |
this.hacer(Volando); | |
} | |
golpeando() { | |
this.hacer(Golpeado); | |
} | |
ganando() { | |
this.hacer(Ganando); | |
} | |
} | |
class BombaConMovimiento extends Bomba { | |
constructor() { | |
super(0, 0); | |
this.hacer(Mover); | |
} | |
} | |
class EstrellaConMovimiento extends Actor { | |
constructor() { | |
super("estrella.png", 0, 0); | |
this.radio_de_colision = 30; | |
this.hacer(Mover); | |
} | |
colision() { | |
this.vivo = false; | |
this.hacer(Liberar); | |
} | |
} | |
class Nube extends Actor { | |
velocidad; | |
constructor() { | |
var imagenes = ['nube1.png', 'nube2.png']; | |
var imagen = imagenes[Math.floor(Math.random()*2)]; | |
var x = -320+Math.floor(Math.random()*640); | |
var y = -240+Math.floor(Math.random()*480); | |
super(imagen, x, y); | |
this.velocidad = [Math.floor(Math.random()*9)+2]; | |
this.escala = this.velocidad / 10.0; | |
this.transparencia = this.velocidad * 6; | |
} | |
actualizar() { | |
this.x -= this.velocidad; | |
if (this.derecha < -320) { | |
this.izquierda = 320; | |
this.y = -240+Math.floor(Math.random()*480); | |
} | |
} | |
} | |
class Vaca_Voladora { | |
fondo; | |
vaca; | |
bombas; | |
estrellas; | |
nubes; | |
puntaje; | |
constructor() { | |
this.fondo = new FondoCielo(); | |
this.vaca = new Vaca(); | |
this.bombas = new pilas.grupo.Grupo(); | |
this.estrellas = new pilas.grupo.Grupo(); | |
this.nubes = pilas.utils.fabricar(Nube,4); | |
this.puntaje = new pilas.actores.Puntaje(-245, 155, 0, pilas.colores.blanco); | |
this.puntaje.escala = 4; | |
pilas.mundo.agregar_tarea_siempre(2, this.crear_bomba, {}, this); | |
pilas.mundo.agregar_tarea_siempre(2, this.crear_estrella, {}, this); | |
pilas.colisiones.agregar(this.vaca, this.bombas, this.colisionar_con_bombas, this); | |
pilas.colisiones.agregar(this.vaca, this.estrellas, this.colisionar_con_estrellas, this); | |
} | |
crear_bomba() { | |
this.bombas.agregar_actor(new BombaConMovimiento()); | |
} | |
crear_estrella() { | |
this.estrellas.agregar_actor(new EstrellaConMovimiento()); | |
} | |
colisionar_con_bombas(vaca, bomba) { | |
vaca.golpeando(); | |
bomba.eliminar(); | |
} | |
colisionar_con_estrellas(vaca, estrella) { | |
vaca.ganando(); | |
estrella.colision(); | |
this.puntaje.aumentar(10); | |
pilas.interpolar(this.puntaje,"escala",[7,4],1); | |
pilas.interpolar(this.puntaje,"rotacion",[-20,20,-10,0],.5); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment