Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- math.randomseed(os.clock())
- --cargamos cosas
- negro=color.new(255,255,255)
- rojo=color.new(255,0,0)
- blanco=color.new(0,0,0)
- roja = {img = image.load ("objetos/roja.png"),x = math.random(22.5+50,459-50), y = math.random(22.5+50,249-50), w = 20, h = 20}
- amarilla = {img = image.load ("objetos/amarilla.png"),w=20 , h=20}
- fondo = image.load("imagenes/fondo.jpg")
- bola={img=image.load("imagenes/bola.jpg"),x=240,y=136,w=40,h=40}
- menu={}
- menu[1]= image.load("imagenes/menu/menu1.jpg")
- menu[2]= image.load("imagenes/menu/menu2.jpg")
- menu[3]= image.load("imagenes/menu/menu3.jpg")
- menu[4]= image.load("imagenes/menu/menu4.jpg")
- menum={}
- menum[1] = image.load("imagenes/menu/menu1m.jpg")
- menum[2] = image.load("imagenes/menu/menu2m.jpg")
- menum[3] = image.load("imagenes/menu/menu3m.jpg")
- creditos = image.load("imagenes/creditos.jpg")
- cmenu=1
- cmenu2=1
- velocidad= 0
- nivel = 1
- mostrar = true
- mostrar2 = false
- tiempo = timer.new(); tiempo:reset(); tiempo:stop();
- crono=timer.new(); crono:reset(); crono:stop();
- inc=timer.new(); inc:reset(); inc:stop();
- os.cpu(225)
- function cambiarsitio(obj)
- tiempo:start()
- obj.x=-100
- obj.y=-100
- end
- function moveaut(incremento)
- if math.floor(crono:time()/1000) < 2 then
- bola.x = bola.x + velocidad
- elseif math.floor(crono:time()/1000) < 4 then
- bola.y = bola.y - velocidad
- elseif math.floor(crono:time()/1000) < 5 then
- bola.y = bola.y + velocidad
- elseif math.floor(crono:time()/1000) < 8 then
- bola.x=bola.x - velocidad
- elseif math.floor(crono:time()/1000) < 10 then
- bola.y=bola.y - velocidad
- elseif math.floor(crono:time()/1000) < 12 then
- bola.x = bola.x - velocidad
- elseif math.floor(crono:time()/1000) < 14 then
- bola.y = bola.y - velocidad
- nivel = nivel + 1
- crono:reset()
- velocidad= velocidad + incremento
- end
- end
- function colision(obj1,obj2)
- if obj1.x + obj1.w >= obj2.x and
- obj1.y + obj1.h >= obj2.y and
- obj1.y<= obj2.y + obj2.h and
- obj1.x<= obj2.x + obj2.w then
- return true
- else
- return false
- end
- end
- function seleccion()
- while true do
- controls.read()
- if controls.press("circle") then
- menuprincipal()
- end
- if controls.press("up") then
- if cmenu <=1 then cmenu = 4 else cmenu = cmenu - 1 end
- elseif controls.press("down") then
- if cmenu >=4 then cmenu = 1 else cmenu = cmenu + 1 end
- end
- menu[cmenu]:blit(0,0)
- if controls.press("cross") then
- if cmenu == 1 then
- juego(3,1,1)
- elseif cmenu == 2 then
- juego(0.5,1,1)
- elseif cmenu == 3 then
- juego(0.2,1,1)
- elseif cmenu == 4 then
- menuprincipal()
- end
- end
- screen.flip()
- end
- end
- function chocar(velinicial,incremento)
- if bola.x < 22.5 or bola.x + bola.w > 459 or bola.y < 22.5 or bola.y + bola.h > 249 then
- os.message("Has chocado , Pulsa O para volver a intentarlo")
- tiempo:reset(); tiempo:stop();
- crono:reset(); crono:stop();
- inc:reset(); inc:stop();
- nivel = 1
- velocidad = 0
- bola.x = 240
- bola.y = 136
- juego(velinicial,incremento)
- end
- end
- function juego(velinicial,incremento)
- velocidad = velinicial
- tiempo:reset(); tiempo:stop();
- crono:reset(); crono:stop();
- inc:reset(); inc:stop();
- crono:start();
- inc:start();
- roja.x = math.random(22.5+50,459-50)
- roja.y = math.random(22.5+50,249-50)
- nivel = 1
- bola.x = 240
- bola.y = 136
- while true do
- controls.read()
- fondo:blit(0,0)
- screen.print(10,10,"Nivel ="..nivel,rojo)
- screen.print(100,10,"Velocidad ="..velocidad,rojo)
- screen.print(300,10,crono:time().." "..tiempo:time().." "..inc:time(),rojo)
- screen.print(10,255,"Pulsa Start para volver al menú", rojo)
- bola.img:blit(bola.x,bola.y)
- if controls.up()then
- bola.y=bola.y - 5
- elseif controls.down() then
- bola.y=bola.y + 5
- else moveaut(incremento)
- end
- if controls.right() then
- bola.x = bola.x + 5
- elseif controls.left() then
- bola.x= bola.x - 5
- else moveaut(incremento)
- end
- if colision(bola,roja) then
- velocidad = velocidad - 0.3
- cambiarsitio(roja)
- end
- if tiempo:time() >= 2000 then
- roja.x = math.random(22.5+50,459-50)
- roja.y = math.random(22.5+50,249-50)
- tiempo:reset(); tiempo:stop();
- end
- if velocidad <=0 then velocidad = 0 end
- roja.img:blit(roja.x,roja.y)
- if controls.select() then a() end
- if controls.press("start") then
- menuprincipal()
- end
- chocar(velinicial,nivel,incremento)
- screen.flip()
- end
- end
- function menuprincipal()
- while true do
- controls.read()
- if controls.press("up") then
- if cmenu2 <=1 then cmenu2 = 3 else cmenu2 = cmenu2 - 1 end
- elseif controls.press("down") then
- if cmenu2 >=3 then cmenu2 = 1 else cmenu2 = cmenu2 + 1 end
- end
- menum[cmenu2]:blit(0,0)
- if controls.press("cross") then
- if cmenu2 == 1 then
- seleccion()
- elseif cmenu2 == 2 then
- while true do controls.read() creditos:blit(0,0) if controls.press("cross") or controls.press("circle") then break end screen.flip() end
- elseif cmenu2 == 3 then
- os.exit()
- end
- end
- if controls.select() then a() end
- screen.flip()
- end
- end
- menuprincipal()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement