Advertisement
xerpi

Untitled

Mar 12th, 2011
243
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.44 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.     presentimg:blit(present.x,present.y)
  78.     end
  79.    
  80.    function Presentcreate2()
  81.     x = present2.x
  82.     y = present2.y
  83.     presentimg2:blit(present2.x,present2.y)
  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!",0.7 red,alpha)
  125.                         highscore = level
  126.                         ini.write("scores.ini",highscore,level)
  127.                         end
  128.            dofile("gameover.lua")
  129.          end
  130.          
  131.     end  
  132. --Compruebe si usted coge un regalo, si es así reiniciar los regalos
  133.     function check_for_present()
  134.         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
  135.             presents = presents + 1
  136.             present.y = -20
  137.             present.x = math.random(22,354)
  138.         end
  139.     end
  140.    
  141.     function check_for_present2()
  142.         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
  143.             presents = presents + 1
  144.             present2.y = -20
  145.             present2.x = math.random(22,354)
  146.         end
  147.     end
  148.  
  149.    
  150. while true do
  151. controls.read()
  152.  
  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.     if mode == "game" and counter > 30 and controls.press("start") then
  163.         mode = "pause"
  164.     end
  165.     if mode == "pause" and counter > 30 and controls.press("start") then
  166.         mode = "game"
  167.     end
  168.  
  169.        
  170. if mode == "pause" then
  171. screen.print(160,110,"Pause:",0.7 red,alpha)
  172. screen.print(130,120,"Start = Weiter",0.7 red,alpha)
  173. end
  174.  
  175. blit_player()
  176. Presentcreate()
  177. if level >= 5 then
  178. Presentcreate2()  
  179. leave_present2()     
  180. end
  181.        
  182. if mode == "game" then     
  183.     check_for_present()
  184.     check_for_present2()
  185.     movepresents()
  186.     levelup()
  187.     leave_present()
  188.     gameover()
  189.     check_player_position()
  190.     if controls.left() then playerleft() end
  191.     if controls.right() then playerright() end 
  192. end
  193.     counter = counter+1
  194.     screen.flip()  
  195. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement