Advertisement
xerpi

Untitled

Mar 12th, 2011
337
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.50 KB | None | 0 0
  1.  
  2. --Highscore
  3. highscore = ini.read("scores.ini",highscore,0)
  4. math.randomseed(os.time())
  5.  
  6. --Colors
  7.  
  8. red = color.new(255,0,0)
  9. alpha = color.new(0,0,0,0)
  10.  
  11. --Jugador  
  12. player = { x = 200, y = 200}
  13. player.width = 21 --ancho
  14. player.height = 32 --altura
  15. playerlinks = image.load("playerl.png")
  16. playerrechts = image.load("playerr.png")
  17.  
  18. --Regalo 1
  19. present = { x = math.random(22,354), y = 0 }
  20. present.width = 20 --ancho
  21. present.height = 20 --altura
  22. presentimg = image.load("present.png")
  23.  
  24. --Regalo 2
  25. present2 = { x = math.random(22,354), y = 0 }
  26. present2.width = 20 --ancho
  27. present2.height = 20 --altura
  28. presentimg2 = image.load("present2.png")
  29.  
  30. --Other Images
  31. bg = image.load("bg.png")
  32.  
  33. --Other stuff
  34. speed = 1
  35. speed2 = 1.2
  36. level = 1
  37. presents = 0
  38. verloren = 0 --perdido
  39. leben = 10 --vidas
  40. zaehler = timer.new() --contador
  41. mode = "game" --modo
  42. counter = 0 --contador
  43. musica = sound.load("song.mp3")
  44.  
  45. --Player movimientos
  46.     function playerleft()
  47.         modus = 1
  48.         player.x = player.x - 4
  49.     end
  50.  
  51.     function playerright()
  52.         modus = 2
  53.         player.x = player.x + 4
  54.     end
  55. --Player en pantalla    
  56.     function blit_player()
  57.         if modus == 1 then
  58.             screen.blit(player.x,player.y,playerlinks)
  59.         elseif modus == 2 then
  60.             screen.blit(player.x,player.y,playerrechts)
  61.         end
  62.     end
  63.    
  64. --Player limites pantalla
  65.         function check_player_position()
  66.           if player.x > 342 then
  67.           player.x = 342
  68.           end
  69.           if player.x < 20 then
  70.           player.x = 20
  71.           end
  72.         end
  73. --Regalos ( Objetos )  
  74.     function Presentcreate()
  75.     x = present.x
  76.     y = present.y
  77.     screen.blit(present.x,present.y,presentimg,true)
  78.     end
  79.    
  80.    function Presentcreate2()
  81.     x = present2.x
  82.     y = present2.y
  83.     screen.blit(present2.x,present2.y,presentimg2,true)
  84.     end
  85.    
  86.    function movepresents()
  87.    present.y = present.y + speed
  88.    present2.y = present2.y + speed2
  89.    end
  90.  
  91.  
  92. --Level up
  93. function levelup()
  94.     if not puffer then puffer = 1 end
  95.     if presents == 5*puffer then
  96.         speed = speed + 0.1
  97.         level = level + 1
  98.         puffer = puffer + 1
  99.     end
  100. end
  101.  
  102.        
  103. --Si se olvida de un regalo
  104.     function leave_present()   
  105.          if present.y > 255 then
  106.             verloren = verloren + 1
  107.             leben = leben - 1
  108.             present.y = -20
  109.          end
  110.     end  
  111.    
  112.     function leave_present2()  
  113.          if present2.y > 255 then
  114.             verloren = verloren + 1
  115.             leben = leben - 1
  116.             present2.y = -20
  117.          end
  118.     end  
  119.  
  120. --Gameover
  121.     function gameover()
  122.          if leben == 0 then
  123.          if level > highscore then
  124.                         screen.print(378,16,"Neuer Highscore!",red)
  125.                         highscore = level
  126.                         file = io.open("highscore.txt","w")
  127.                         file:write(level)
  128.                         file:close()    
  129.                     end
  130.            dofile("gameover.lua")
  131.          end
  132.          
  133.     end  
  134. --Compruebe si usted coge un regalo, si es así reiniciar los regalos
  135.     function check_for_present()
  136.         if ( player.x + player.width >= present.x ) and ( player.x <= present.x + present.width ) and ( player.y <= present.y + present.height ) and ( player.y + player.height >= present.y ) then
  137.             presents = presents + 1
  138.             present.y = -20
  139.             present.x = math.random(22,354)
  140.         end
  141.     end
  142.    
  143.     function check_for_present2()
  144.         if ( player.x + player.width >= present2.x ) and ( player.x <= present2.x + present2.width ) and ( player.y <= present2.y + present2.height ) and ( player.y + player.height >= present2.y ) then
  145.             presents = presents + 1
  146.             present2.y = -20
  147.             present2.x = math.random(22,354)
  148.         end
  149.     end
  150.  
  151.    
  152. while true do
  153. musica:play()
  154. bg:blit(0,0)
  155. screen.print(378,16,"Bannanen:"..presents,0.7 red,alpha)
  156. screen.print(378,25,"Level:"..level,0.7 red,alpha)
  157. screen.print(378,35,"Verpasst:"..verloren,0.7 red,alpha)
  158. screen.print(378,45,"Leben:"..leben,0.7 red,alpha)
  159. screen.print(378,65,"Highscore:"..highscore,0.7 red,alpha)
  160.  
  161.  
  162.  
  163.  
  164.    
  165. controls.read()
  166.  
  167.     if mode == "game" and counter > 30 and controls.press("start") then
  168.         mode = "pause"
  169.     end
  170.     if mode == "pause" and counter > 30 and controls.press("start") then
  171.         mode = "game"
  172.     end
  173.  
  174.        
  175. if mode == "pause" then
  176. screen.print(160,110,"Pause:",0.7 red,alpha)
  177. screen.print(130,120,"Start = Weiter",0.7 red,alpha)
  178. end
  179.  
  180. blit_player()
  181. Presentcreate()
  182. if level >= 5 then
  183. Presentcreate2()  
  184. leave_present2()     
  185. end
  186.        
  187. if mode == "game" then     
  188.     check_for_present()
  189.     check_for_present2()
  190.     movepresents()
  191.     levelup()
  192.     leave_present()
  193.     gameover()
  194.     check_player_position()
  195.     if controls.left() then playerleft() end
  196.     if controls.right() then playerright() end 
  197. end
  198.     counter = counter+1
  199.     screen.flip()  
  200. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement