Advertisement
xerpi

Untitled

May 13th, 2011
261
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.92 KB | None | 0 0
  1. math.randomseed(os.clock())
  2. --cargamos cosas
  3.  
  4. negro=color.new(255,255,255)
  5. rojo=color.new(255,0,0)
  6. blanco=color.new(0,0,0)
  7.  
  8. 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}
  9. amarilla = {img = image.load ("objetos/amarilla.png"),w=20 , h=20}
  10. fondo = image.load("imagenes/fondo.jpg")
  11. bola={img=image.load("imagenes/bola.jpg"),x=240,y=136,w=40,h=40}
  12.  
  13. menu={}
  14. menu[1]= image.load("imagenes/menu/menu1.jpg")
  15. menu[2]= image.load("imagenes/menu/menu2.jpg")
  16. menu[3]= image.load("imagenes/menu/menu3.jpg")
  17. menu[4]= image.load("imagenes/menu/menu4.jpg")
  18. menum={}
  19. menum[1] = image.load("imagenes/menu/menu1m.jpg")
  20. menum[2] = image.load("imagenes/menu/menu2m.jpg")
  21. menum[3] = image.load("imagenes/menu/menu3m.jpg")
  22. creditos = image.load("imagenes/creditos.jpg")
  23.  
  24. cmenu=1
  25. cmenu2=1
  26. velocidad= 0
  27. nivel = 1
  28.  
  29. mostrar = true
  30. mostrar2 = false
  31.  
  32. tiempo = timer.new(); tiempo:reset(); tiempo:stop();
  33. crono=timer.new(); crono:reset(); crono:stop();
  34. inc=timer.new(); inc:reset(); inc:stop();
  35.  
  36. os.cpu(225)
  37.  
  38. function cambiarsitio(obj)
  39. tiempo:start()
  40. obj.x=-100
  41. obj.y=-100
  42. end
  43.  
  44. function moveaut(incremento)
  45.     if math.floor(crono:time()/1000) < 2 then
  46.         bola.x = bola.x + velocidad
  47.     elseif math.floor(crono:time()/1000) < 4 then
  48.         bola.y = bola.y - velocidad
  49.     elseif math.floor(crono:time()/1000) < 5 then
  50.         bola.y = bola.y + velocidad
  51.     elseif math.floor(crono:time()/1000)  < 8 then
  52.         bola.x=bola.x - velocidad
  53.     elseif math.floor(crono:time()/1000) < 10 then
  54.         bola.y=bola.y - velocidad
  55.     elseif math.floor(crono:time()/1000) < 12 then
  56.         bola.x = bola.x - velocidad
  57.     elseif math.floor(crono:time()/1000) < 14 then
  58.         bola.y = bola.y - velocidad
  59.         nivel = nivel + 1
  60.         crono:reset()
  61.         velocidad= velocidad + incremento
  62.     end
  63. end
  64.  
  65. function colision(obj1,obj2)
  66. if obj1.x + obj1.w >= obj2.x and
  67.     obj1.y + obj1.h >= obj2.y and
  68.     obj1.y<= obj2.y + obj2.h and
  69.     obj1.x<= obj2.x + obj2.w then
  70.         return true
  71. else
  72.         return false
  73. end
  74. end
  75.  
  76.  
  77. function seleccion()
  78.     while true do
  79.     controls.read()
  80.     if controls.press("circle") then
  81.         menuprincipal()
  82.     end
  83.     if controls.press("up") then
  84.         if cmenu <=1 then cmenu = 4 else cmenu = cmenu - 1 end
  85.     elseif controls.press("down") then
  86.         if cmenu >=4 then cmenu = 1 else cmenu = cmenu + 1 end
  87.     end
  88.     menu[cmenu]:blit(0,0)
  89.     if  controls.press("cross") then
  90.         if cmenu == 1 then
  91.             juego(3,1,1)
  92.         elseif cmenu == 2 then
  93.             juego(0.5,1,1)
  94.         elseif cmenu == 3 then
  95.             juego(0.2,1,1)
  96.         elseif cmenu == 4 then
  97.             menuprincipal()
  98.         end
  99.     end
  100.     screen.flip()
  101.     end
  102. end
  103.  
  104. function chocar(velinicial,incremento)
  105.  if bola.x < 22.5 or bola.x + bola.w > 459 or bola.y < 22.5 or bola.y + bola.h > 249 then
  106.     os.message("Has chocado , Pulsa O para volver a intentarlo")
  107.     tiempo:reset(); tiempo:stop();
  108.     crono:reset(); crono:stop();
  109.     inc:reset(); inc:stop();
  110.     nivel = 1
  111.     velocidad = 0
  112.     bola.x = 240
  113.     bola.y = 136
  114.     juego(velinicial,incremento)
  115. end
  116. end
  117.  
  118. function juego(velinicial,incremento)
  119. velocidad = velinicial
  120. tiempo:reset(); tiempo:stop();
  121. crono:reset(); crono:stop();
  122. inc:reset(); inc:stop();
  123. crono:start();
  124. inc:start();
  125. roja.x = math.random(22.5+50,459-50)
  126. roja.y = math.random(22.5+50,249-50)
  127. nivel = 1
  128. bola.x = 240
  129. bola.y = 136
  130.  
  131. while true do
  132. controls.read()
  133. fondo:blit(0,0)
  134. screen.print(10,10,"Nivel ="..nivel,rojo)
  135. screen.print(100,10,"Velocidad ="..velocidad,rojo)
  136. screen.print(300,10,crono:time().." "..tiempo:time().." "..inc:time(),rojo)
  137. screen.print(10,255,"Pulsa Start para volver al menú", rojo)
  138. bola.img:blit(bola.x,bola.y)
  139.  
  140.  
  141. if controls.up()then
  142.     bola.y=bola.y - 5
  143. elseif controls.down() then
  144.     bola.y=bola.y + 5
  145. else moveaut(incremento)
  146. end
  147. if controls.right() then
  148.     bola.x = bola.x + 5
  149. elseif controls.left() then
  150.     bola.x= bola.x - 5
  151. else moveaut(incremento)
  152. end
  153.    
  154.    
  155. if colision(bola,roja) then
  156.     velocidad = velocidad - 0.3
  157.     cambiarsitio(roja)
  158. end
  159.  
  160. if tiempo:time() >= 2000 then
  161.     roja.x = math.random(22.5+50,459-50)
  162.     roja.y = math.random(22.5+50,249-50)
  163.     tiempo:reset(); tiempo:stop();
  164. end
  165. if velocidad <=0 then velocidad = 0 end
  166.    
  167. roja.img:blit(roja.x,roja.y)
  168. if controls.select() then a() end
  169. if controls.press("start") then
  170.     menuprincipal()
  171. end
  172.  
  173. chocar(velinicial,nivel,incremento)
  174. screen.flip()
  175. end
  176. end
  177.  
  178.  
  179.  
  180. function menuprincipal()
  181.     while true do
  182.     controls.read()
  183.         if controls.press("up") then
  184.             if cmenu2 <=1 then cmenu2 = 3 else cmenu2 = cmenu2 - 1 end
  185.         elseif controls.press("down") then
  186.             if cmenu2 >=3 then cmenu2 = 1 else cmenu2 = cmenu2 + 1 end
  187.         end
  188.         menum[cmenu2]:blit(0,0)
  189.         if  controls.press("cross") then
  190.             if cmenu2 == 1 then
  191.                 seleccion()
  192.             elseif cmenu2 == 2 then
  193.                 while true do controls.read() creditos:blit(0,0) if controls.press("cross") or controls.press("circle") then break end screen.flip() end
  194.             elseif cmenu2 == 3 then
  195.                 os.exit()
  196.             end
  197.         end
  198.         if controls.select() then a() end
  199.         screen.flip()
  200.     end
  201. end
  202.  
  203. menuprincipal()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement