Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --main = class()
- displayMode(FULLSCREEN)
- bat = nil
- ball = nil
- ball1 = nil
- lastDelta = 0
- Bola_movimiento = false
- bloques = {}
- nivel=1
- vidas =3
- gravedad= vec2(0,0)
- lluvia = nil
- sonidos = nil
- velocidad = 0
- explotar = nil
- juego_finito = false
- ganar = false
- puntos = 0
- maximo_nivel = table.maxn(niveles)
- function setup()
- bat = Barra()
- ball = Pelota()
- ball1 = Pelota()
- lluvia = lineas()
- sonido_de_lluvia = 0
- sonidoBarra = 0
- ball.velocidad.x = math.random(-3,3)
- Poner_bloques()
- print("juego de ping pong terminado")
- print("toca la barra para empezar a jugar")
- print("una ves se te acaben las 3 vidas pierdes")
- print("si pasas de nivel se te agrefara una vida")
- print("cada ves que subes de nivel la pelota sera mas rapida")
- print("SUERTE!!")
- end
- function Poner_bloques()
- for i = 1,8 do
- c = obtenerColorPorNivel(i)
- for x = 1,10 do
- if niveles[nivel][i][x] > 0 then
- table.insert(bloques, Bloques(35 + (x * 62), HEIGHT - (i * 35 + 35) , c))
- end
- end
- end
- end
- function obtenerColorPorNivel(fila)
- cambiarTono = fila * 35
- if nivel % 4 == 1 then
- c = color(cambiarTono,255,255)
- elseif nivel % 4 == 2 then
- c = color(255,cambiarTono,255)
- elseif nivel % 4 == 3 then
- c = color(255,255,cambiarTono,255)
- else
- c = color(0,255,cambiarTono,255)
- end
- return c
- end
- -- This function gets called once every frame
- function draw()
- background(0, 25, 25, 5)
- noSmooth()
- if Bola_movimiento then
- if ball:paredes() == false then
- perder_vidas()
- end
- end
- if bat:rebote(ball) == false then
- end
- for i = 1, table.maxn(bloques) do
- if bloques[i]:rebote(ball) then
- table.remove(bloques, i)
- puntos = puntos + 50
- break
- end
- -- esta sentncia funciona bien
- if puntos == 1000 then
- -- mostrarTexto("EN RACHA!!" , 380 , 450)
- --mostrarTexto("BARRA ALARGADA !!" , 350 , 400)
- bat.tamano.x = bat.tamano.x + 2
- bat.posicion.y = bat.posicion.y + 0.2
- end
- end
- if table.maxn(bloques) == 1 then
- --ball1:draw()
- ball.posicion.x = bat.posicion.x
- ball1.posicion.x = bat.posicion.x
- ball.radio = 10
- ball1.radio = 10
- end
- --
- if table.maxn(bloques) == 0 then
- nuevo_nivel()
- end
- strokeWidth(2)
- bat:draw()
- ball:draw()
- for i = 1, table.maxn(bloques)do
- bloques[i]:draw()
- end
- if nivel == 2 or nivel == 4 or nivel == 6 or nivel == 7 then
- -- mantiene el sonido equilirado y con mayor fluides y duracion
- if ElapsedTime > sonido_de_lluvia then
- sonido_de_lluvia = ElapsedTime + 2
- sound(DATA, "ZgNAfwBAQj4/Pj9DAACAPwAAAAAAAIA/AABHf0JFQD9AQj9A")
- end
- lluvia:cargar()
- lluvia:dibujar()
- end
- if nivel == 3 then
- bat.posicion.x = bat.posicion.x-lastDelta
- bat.posicion.x = bat.posicion.x-lastDelta
- end
- if nivel == 4 then
- if Bola_movimiento then
- if ball1:paredes() == false then
- perder_vidas()
- end
- end
- if bat:rebote(ball1) == false then
- end
- for u = 1, table.maxn(bloques) do
- if bloques[u]:rebote(ball1) then
- table.remove(bloques, u )
- puntos = puntos + 50
- break
- end
- end
- ball1:draw()
- end
- if nivel == 5 then
- ball.posicion.x = bat.posicion.x
- ball1.posicion.x = bat.posicion.x
- if Bola_movimiento then
- if ball1:paredes() == false then
- perder_vidas()
- end
- end
- if bat:rebote(ball1) == false then
- end
- for u = 1, table.maxn(bloques) do
- if bloques[u]:rebote(ball1) then
- table.remove(bloques, u )
- puntos = puntos + 50
- break
- end
- end
- ball1:draw()
- end
- -- fin del nivel 5
- if nivel == 6 or nivel == 7 then
- bat.posicion.x = bat.posicion.x - lastDelta
- bat.posicion.x = bat.posicion.x - lastDelta
- --bat.tamano.x = bat.tamano.x + 2
- if Bola_movimiento then
- if ball1:paredes() == false then
- perder_vidas()
- end
- end
- if bat:rebote(ball1) == false then
- end
- for u = 1, table.maxn(bloques) do
- if bloques[u]:rebote(ball1) then
- table.remove(bloques, u )
- puntos = puntos + 50
- break
- end
- end
- ball1:draw()
- lluvia:cargar()
- lluvia:dibujar()
- end
- -- fin del level 6 y 7
- if juego_finito then
- mostrarTexto("PERDISTE", 350, 400)
- elseif ganar then
- mostrarTexto("GANASTE" , 350, 400)
- end
- function touched(touch)
- if CurrentTouch.state == BEGAN or
- CurrentTouch.state == MOVING then
- lastDelta = CurrentTouch.deltaX
- if Bola_movimiento == false then
- if CurrentTouch.x < bat:derecha() + 100 and
- CurrentTouch.x > bat:izquierda() - 100 and
- CurrentTouch.y < bat:arriba() + 200 and
- CurrentTouch.y > bat:abajo() then
- sound(DATA, "ZgJANwBAUyFBBgUrFEQgPnuCCD/ggYs9cwB/bUBAP0c/On0N")
- if Bola_movimiento == false then
- Bola_movimiento = true
- end
- end
- else
- --movemos la barra
- bat.posicion.x = bat.posicion.x + lastDelta
- bat.posicion.x = math.min( bat.posicion.x, WIDTH - bat.tamano.x/2 )
- bat.posicion.x = math.max( bat.tamano.x/2, bat.posicion.x )
- end
- elseif juego_finito == true or ganar == true then
- if CurrentTouch.tapCount == 1 then
- resetearJuego()
- end
- end
- end
- lastDelta = 0
- end
- --ceramos una funcion que reseteara el balon una ves se falle con el bate
- function resetearBalon()
- Bola_movimiento = false
- ball.posicion.x = bat.posicion.x
- ball1.posicion.x = bat.posicion.x
- ball.posicion.y = 30
- ball1.posicion.y = 30
- ball.posicion.x = 380
- ball.radio = 12
- ball1.ratio = 12
- bat.posicion.x = 380
- bat.posicion.y = 47
- end
- function nuevo_nivel()
- puntos = puntos + 100 * vidas * nivel
- resetearBalon()
- if nivel <= maximo_nivel then
- --el nivel aumenta a n+1
- nivel = nivel + 1
- --ball.velocidad.y = math.random(0,30)
- -- se colocan los bloques nuevamente del resectivo nivel
- Poner_bloques()
- ball.velocidad.y = ball.velocidad.y * 1.2
- vidas = vidas + 1
- bat.tamano = vec2(120,15)
- -- sound(SOUND_RANDOM, 61)
- else
- ganar = true
- end
- end
- -- creamos una nueva funcion para ir descontando las vidas
- function perder_vidas()
- resetearBalon()
- --se descuenta la vida
- vidas = vidas - 1
- if vidas == 0 then
- juego_finito = true
- -- Poner_bloques()
- end
- end
- function mostrarTexto(str , x , y )
- pushStyle()
- textMode(CORNER)
- fill(255, 255, 0, 255)
- font("Arial")
- fontSize(50)
- text(str,x,y)
- popStyle()
- end
- function mostrar_advertencia(acomodar,x,y)
- pushMatrix()
- fill(255,25,25,255)--rojo
- font("Georgia")
- fontSize(20)
- textWrapWidth(200)
- text(acomodar,x,y)
- popMatrix()
- end
- function resetearJuego()
- vidas = 3
- puntos = 0
- nivel = 1
- bloques = {}
- Poner_bloques()
- juego_finito = false
- ganar = false
- ball.velocidad.y = 15
- --ball1.velocidad.y = math.random(0,15)
- end
- --pelota = class()
- Pelota = class()
- function Pelota:init()
- -- you can accept and set parameters here
- self.posicion = vec2( WIDTH /2,41)
- self.radio = 12
- self.velocidad = vec2(0,15)
- end
- function Pelota:draw()
- local color_adicional = 255
- fill(255,255,255,color_adicional)
- noStroke()
- ellipse (self.posicion.x , self.posicion.y , 2* self.radio)
- local soltar_bola = self.posicion - self.velocidad
- if Bola_movimiento == true then
- for y = 1,2 do
- color_adicional = color_adicional / 2
- fill (255,25,255,color_adicional)
- ellipse(soltar_bola.x , soltar_bola.y ,1* self.radio)
- soltar_bola = soltar_bola - self.velocidad
- end
- end
- end
- function Pelota:paredes()
- self.posicion = self.posicion + self.velocidad
- --pared lateral derecha
- if (self.posicion.x + self.radio) >= WIDTH then
- -- self.posicion.x = WIDTH - self.radio
- --esta linea hace que el balon rebote en la pared derecha
- self.velocidad.x = -self.velocidad.x
- --sound(SOUND_JUMP)
- --pared lateral izquierda
- elseif (self.posicion.x - self.radio) <= 0 then
- -- self.posicion.x = self.radio
- --esta linea hace que el balon rebote en la pared izquierda
- self.velocidad.x = -self.velocidad.x
- --pared de arriba
- elseif (self.posicion.y + self.radio) >= HEIGHT then
- physics.gravity(0,4000)
- -- self.posicion.y = HEIGHT - self.radio
- self.velocidad.y = -self.velocidad.y
- --pared de abajo
- elseif (self.posicion.y - self.radio) <= 0 then
- -- self.posicion.y = self.radio
- self.velocidad.y = -self.velocidad.y
- sound(SOUND_RANDOM, 79)
- return false
- end
- return true
- end
- function Pelota:derecha()
- return self.posicion.x + self.radio
- end
- function Pelota:izquierda()
- return self.posicion.x - self.radio
- end
- function Pelota:arriba()
- return self.posicion.y + self.radio
- end
- function Pelota:abajo()
- return self.posicion.y - self.radio
- end
- --barra = class()
- Barra = class()
- function Barra:init()
- -- se realizaran la implementacion de la barra del juego
- -- el largo y el ancho de la barra
- self.posicion = vec2(380 , 60)
- -- tamano
- self.tamano = vec2(120, 15)
- end
- function Barra:draw()
- -- le damos color a la barra
- fill(45, 197, 200, 255)
- -- sprite("Tyrian Remastered:Boss A",300,400)
- rectMode(CENTER)
- --le damos curvatura a la recta en las esquinas
- ellipse(self.posicion.x - self.tamano.x /1.9 , self.posicion.y, 15)
- ellipse(self.posicion.x + self.tamano.x /1.9 , self.posicion.y, 15)
- --mostramos la recta
- ellipse(self.posicion.x , self.posicion.y , self.tamano.x , self.tamano.y)
- end
- function Barra:rebote(ball)
- if ball:izquierda() <= self:derecha() and ball:derecha() >= self:izquierda()
- and ball:abajo() <= self:arriba() and
- ball:arriba() >= self:abajo() then
- ball.velocidad.y = -ball.velocidad.y
- ball.posicion.y = self:arriba() + ball.radio
- posicion = ball.posicion.x - self.posicion.x
- ball.velocidad.x = posicion /10
- return true
- end
- return false
- end
- function Barra:derecha()
- return self.posicion.x + self.tamano.x /2
- end
- function Barra:izquierda()
- return self.posicion.x - self.tamano.x /2
- end
- function Barra:arriba()
- return self.posicion.y + self.tamano.y /2
- end
- function Barra:abajo()
- return self.posicion.y - self.tamano.y /2
- end
- Luismi 1:11PM Edit
- Posts: 33
- Bloques = class()
- function Bloques:init(x, y , tonos)
- parameter.integer("Texture",1,2)
- allTextures = {
- "Cargo Bot:Star Filled",
- }
- m = mesh()
- m.texture = allTextures[Texture]
- -- parametros aqui
- -- damos posicion a los bloques
- self.posicion = vec2(x , y)
- -- damos tamano a los bloques
- self.tamano = vec2(70 , 43)
- self.mesh = mesh()
- self.color1 = tonos
- --implementamos los bloques en forma de recta
- self.mesh:addRect (self.posicion.x , self.posicion.y , self.tamano.x , self.tamano.y)
- --le da,os tnos de color a los bloques
- local oscuro = self.color1:mix( color(400,400,400), 0.4 )
- self.mesh:color(1 , self.color1)
- self.mesh:color(2 , oscuro)
- self.mesh:color(3 , self.color1)
- self.mesh:color(4 , oscuro)
- self.mesh:color(5 , self.color1)
- self.mesh:color(6 , oscuro)
- self.mesh.shader = shader("Effects:Ripple")
- end
- function Bloques:draw()
- fill(42, 82, 201, 153)
- -- Configure out custom uniforms for the ripple shader
- self.mesh.shader.time = ElapsedTime
- self.mesh.shader.freq =1.5
- noStroke()
- self.mesh:draw()
- rectMode(CENTER)
- -- Codea does not automatically call this method
- end
- function Bloques:rebote(ball)
- if ball:derecha() >= self:izquierda() and ball:izquierda() <= self:derecha() and
- ball:arriba() >= self:abajo() and ball:abajo() <= self:arriba() then
- sound(DATA, "ZgBAZAA+Qi0IQ0IWAAAAAAubAz5sIgq/VgBKU0BKQUBfIWcQ")
- if ball.posicion.y <= self:arriba() and ball.posicion.y >= self:abajo() then
- ball.velocidad.x = -ball.velocidad.x
- else
- ball.velocidad.y = -ball.velocidad.y
- end
- return true
- end
- return false
- end
- function Bloques:rebote(ball1)
- if ball1:derecha() >= self:izquierda() and ball1:izquierda() <= self:derecha() and
- ball1:arriba() >= self:abajo() and ball1:abajo() <= self:arriba() then
- sound(DATA, "ZgBAZAA+Qi0IQ0IWAAAAAAubAz5sIgq/VgBKU0BKQUBfIWcQ")
- if ball1.posicion.y <= self:arriba() and ball1.posicion.y >= self:abajo() then
- ball1.velocidad.x = -ball1.velocidad.x
- else
- ball1.velocidad.y = -ball1.velocidad.y
- end
- return true
- end
- return false
- end
- -- creamos las funciones de arriba, abajo, izquierda, derecha
- function Bloques:derecha()
- return self.posicion.x + self.tamano.x / 2
- end
- function Bloques:izquierda()
- return self.posicion.x - self.tamano.x /2
- end
- function Bloques:arriba()
- return self.posicion.y + self.tamano.y /2
- end
- function Bloques:abajo()
- return self.posicion.y - self.tamano.y /2
- end
- niveles = {
- {{0,0,1,1,1,1,1,1,0,0},{0,0,0,0,0,0,0,0,0,0},
- {0,0,1,0,1,1,0,1,0,0},{0,0,0,0,0,0,0,0,0,0},
- {0,0,0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0,0,0},
- {0,0,0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0,0,0}},
- {{1,1,1,1,1,1,1,1,1,1},{0,1,1,1,1,1,1,1,1,0},
- {0,0,1,1,1,1,1,1,0,0},{0,0,0,1,1,1,1,0,0,0},--nivel2 lluvia
- {0,0,0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0,0,0},
- {0,0,0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0,0,0}},
- {{0,0,0,1,1,1,1,0,0,0},{0,0,1,1,1,1,1,1,0,0}
- ,{0,0,1,1,1,1,1,1,0,0},{0,0,1,1,1,1,1,1,0,0},--nivel3 bate invertido
- {0,0,1,1,1,1,1,1,0,0},{0,0,0,1,1,1,1,0,0,0},
- {0,0,0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0,0,0}},
- {{1,1,1,1,1,1,1,1,1,1},{1,1,1,1,0,0,0,0,1,1},
- {1,1,1,1,0,1,1,0,1,1},{1,1,1,1,0,0,0,0,1,1},--nivel4 doble balon
- {1,1,1,1,0,1,1,1,1,1},{1,1,1,1,0,1,1,1,1,1},
- {1,1,1,1,0,1,1,1,1,1},{1,1,1,1,1,1,1,1,1,1}},
- {{1,1,1,1,1,1,1,1,1,1},{1,1,1,1,1,1,1,1,1,1},
- {1,1,1,1,1,1,1,1,1,1},{1,1,1,1,1,1,1,1,1,1},--nivel5 direccion balon con barra
- {1,1,1,1,1,1,1,1,1,1},{0,0,0,0,0,0,0,0,0,0},
- {0,0,0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0,0,0}},
- {{1,1,1,1,1,1,1,1,1,1},{1,1,1,1,1,1,1,1,1,1},
- {1,1,1,1,1,1,1,1,1,1},{1,1,1,1,1,1,1,1,1,1},--nivel6
- {1,1,1,1,1,1,1,1,1,1},{0,0,0,0,1,1,1,0,0,0},
- {0,0,0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0,0,0}},
- {{1,1,1,1,1,1,1,1,1,1},{1,1,1,1,1,1,1,1,1,1},
- {1,1,1,1,1,1,1,1,1,1},{1,1,1,1,1,1,1,1,1,1},--nivel7
- {1,1,1,1,1,1,1,1,1,1},{0,0,0,0,1,1,1,0,0,0},
- {0,0,0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0,0,0}}
- }
- -- RAIN
- linea = class()
- function linea:init(vel , pos)
- -- you can accept and set parameters here
- self.velocidad = vel
- self.posicion = pos
- end
- function linea:cargar()
- self.posicion.y = self.posicion.y - self.velocidad
- end
- function linea:mostrar()
- if (self.posicion.y + self.velocidad) < 0 then
- return true
- end
- return false
- end
- function linea:dibujar()
- p = self.posicion
- -- gotas = {"Small World:Raindrop"}
- line(p.x,p.y,p.x,p.y + self.velocidad)
- end
- lineas = class()
- function lineas:init()
- self.velocidad_0 = 3
- self.velocidad_1 = 20
- self.rango =1
- self.lines = {}
- end
- function lineas:mostrarTodo()
- for i,v in ipairs(self.lines) do
- if v:mostrar() then
- table.remove(self.lines , i )
- else
- v:cargar()
- end
- end
- end
- function lineas:cargar()
- for i = 1 , self.rango do
- Velocidad = math.random(self.velocidad_0 , self.velocidad_1)
- dato_1 = vec2(math.random(WIDTH/1) , HEIGHT - Velocidad)
- table.insert(self.lines , linea(Velocidad , dato_1))
- end
- self:mostrarTodo()
- end
- function lineas:dibujar()
- --sound(DATA,"ZgNAeABCQj4/Pj1DWQtwPxDT77u1THs/dQBHf0JFQD9AQj9A")
- pushStyle()
- noSmooth()
- stroke(255,255,255,73.9)
- strokeWidth(3)
- for i,v in ipairs(self.lines) do
- v:dibujar()
- end
- popStyle()
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement