Advertisement
xerpi

OTTF V2

Jun 25th, 2011
233
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 5.95 KB | None | 0 0
  1. if os.language() == "spanish" then
  2.     level_completed = "Nivel completado."
  3.     c_level = "Nivel actual: "
  4.     game_finished = "Felicidades, has conseguido pasarte el juego entero! ¿Deseas volver a jugar?"
  5. else
  6.     level_completed = "Level completed."
  7.     c_level = "Current level: "
  8.     game_finished = "Congrats, you have beaten the game! Would you like to play again?"
  9. end
  10.  
  11.  
  12. dofile("levels.lua");
  13. cnv=tonumber(ini.read("score.ini","maxscore",1));
  14. --sound.loop("snd/env.mp3")
  15. tile={size = 25,mini_size =10}
  16. puntero={img = image.load("img/puntero.png"),x=100,y=100}
  17. pos={}
  18. tiles={}
  19. mini_tiles={}
  20. for i = 1, 4 do
  21. tiles[i] = image.load("img/tiles/"..i..".png")
  22. mini_tiles[i] = image.load("img/tiles/mini/"..i..".png")
  23. end
  24. board={x=15,y=15}
  25. mini_board={x=340,y=190}
  26. current_level={}
  27. --sound_press = sound.load("snd/press.mp3")
  28.  
  29.  
  30. function notout(x,y)
  31. if pos.y+y+1 > 0 and  pos.x+x+1 > 0 and
  32. pos.y+y <= 7 and pos.x+x+1 <=13 then
  33. return true else return false end
  34. end
  35.  
  36. function check_level()
  37. isequal=true
  38. alllevel = ""
  39. for i=1,#current_level do
  40.     alllevel = alllevel..string.implode(current_level[i])
  41. end
  42. if string.implode(level[cnv]) != alllevel then isequal = false end
  43. if isequal == true then
  44.     if cnv == #level then
  45.         if os.message(game_finished ,1) == 1 then
  46.             cnv = 1
  47.             ini.write("score.ini","maxscore",tostring(cnv))
  48.         else ini.write("score.ini","maxscore",tostring(cnv)); os.exit(); end
  49.     else
  50.         os.message(level_completed)
  51.         cnv=cnv+1
  52.         load(cnv)
  53.         ini.write("score.ini","maxscore",tostring(cnv))
  54.     end
  55. end
  56. end
  57.  
  58. function aum(y,x)
  59.     if current_level[y][x] < 4 then current_level[y][x] = current_level[y][x] +1
  60.     elseif current_level[y][x] == 4 then current_level[y][x] = 1 end
  61. end
  62.  
  63. function load(lvl)
  64. current_level={
  65.             {0,0,0,0,0,0,0,0,0,0,0,0,0},
  66.             {0,0,0,0,0,0,0,0,0,0,0,0,0},
  67.             {0,0,0,0,0,0,0,0,0,0,0,0,0},
  68.             {0,0,0,0,0,0,0,0,0,0,0,0,0},
  69.             {0,0,0,0,0,0,0,0,0,0,0,0,0},
  70.             {0,0,0,0,0,0,0,0,0,0,0,0,0},
  71.             {0,0,0,0,0,0,0,0,0,0,0,0,0}
  72.             }
  73. pos.x = math.floor((puntero.x-board.x)/25);
  74. pos.y = math.floor((puntero.y-board.y)/25);
  75. end
  76.  
  77. function blit_level(lvl)
  78. for y = 1, 7 do
  79.     for x = 1, 13 do
  80.         n = (y-1)*13+x
  81.         if current_level[y][x] != 0 then  tiles[current_level[y][x]]:blit(board.x+(x-1)*25,board.y+25*(y-1))  end
  82.         if level[lvl][n] != 0 then mini_tiles[level[lvl][n]]:blit(mini_board.x+(x-1)*10,mini_board.y+10*(y-1)) end
  83.     end
  84. end
  85. end
  86.  
  87. function tile_goto(x,y,t)
  88. ix = 227.5
  89. iy = 272
  90. x1= board.x+(x)*25
  91. y1= board.y+(y)*25
  92. if x1>=ix then
  93.     x2=(480-ix)-(480-x1)
  94. else x2=ix-x1 end
  95. if y1>=iy then
  96.     y2=(272-iy)-(272-y1)
  97. else y2=iy-y1 end
  98. --y2=iy-y1
  99. ang = math.atan(y2/x2)
  100. hi = math.sqrt((x2*x2+y2*y2))
  101.  
  102. for i = 1, hi,4 do
  103. if x1>=ix then
  104.     angx=ix+math.cos(-ang)*i
  105.     angy=iy+math.sin(-ang)*i
  106. else
  107.     angx=ix+math.cos(math.pi+ang)*i
  108.     angy=iy+math.sin(math.pi+ang)*i
  109. end
  110.     controls.read() if controls.select() then a() end
  111.     if controls.up() then ang = ang+math.rad(1) end
  112.     if controls.down() then ang = ang-math.rad(1) end
  113.     tiles[t]:blit(angx,angy)
  114.     draw.line(x1,y1,ix,iy,color.new(255,0,0))
  115.     screen.print(5,5,"x1: "..x1.."   y1: "..y1.."    ang: "..math.deg(ang).."   hi: "..hi.."   i: "..i)
  116.     screen.print(5,25,"x: "..angx.."   y: "..angy.."  x2: "..x2.."  y2: "..y2)
  117.     screen.flip()
  118. end
  119. end
  120.  
  121. function move_cursor() --mover el cursor
  122. if math.abs(controls.analogx())>60 then puntero.x = puntero.x + controls.analogx()/45 end
  123. if math.abs(controls.analogy())>60 then puntero.y = puntero.y + controls.analogy()/45 end
  124. if puntero.x <0 then puntero.x = 0 end
  125. if puntero.y <0 then puntero.y = 0 end
  126. if puntero.x+puntero.img:width() >480 then
  127.     puntero.x = 480-puntero.img:width()
  128. end
  129. if puntero.y+puntero.img:height() >272 then
  130.     puntero.y = 272-puntero.img:height()
  131. end
  132. end
  133.  
  134. load(cnv)
  135.  
  136. while (true) do
  137. if puntero.x>board.x and puntero.x<board.x+13*tile.size and puntero.y>board.y and puntero.y<board.y+7*tile.size then
  138.     pos.x = math.floor((puntero.x-board.x)/25)
  139.     pos.y = math.floor((puntero.y-board.y)/25)
  140. end
  141. controls.read();
  142. draw.rect(15,15,325,175,color.new(255,0,0));
  143. draw.rect(340,190,130,70,color.new(0,255,0));
  144.  
  145. if controls.press("r") then load(cnv) end
  146. if controls.r() and controls.press("l") then cnv = 1; load(cnv) end
  147.  
  148. draw.rect(board.x+pos.x*25,board.y+pos.y*25,25,25,color.new(0,255,0));
  149. draw.rect(mini_board.x+pos.x*10,mini_board.y+pos.y*10,10,10,color.new(255,0,0));
  150.  
  151. screen.print(15,3,"1     2     3     4     5    6     7     8    9    10  11  12  13",0.6,color.new(0,0,255),0x0);
  152. screen.print(340,180,"1 2 3 4 5 6 7 8 9 10 11 12 13",0.40,color.new(0,0,255),0x0);
  153. screen.print(3,15,"a\n\nb\n\nc\n\nd\n\ne\n\nf\n\ng",0.77,color.new(155,155,0),0x0);
  154. screen.print(330,190,"a\nb\nc\nd\ne\nf\ng",0.55,color.new(255,255,255),0x0);
  155. screen.print(355,5,c_level..cnv,0.66,color.new(255,255,255),0x0);
  156.  
  157. move_cursor()
  158.  
  159. if controls.press("cross") then
  160.         if current_level[pos.y+1][pos.x+1] == 0 then
  161.             --sound_press:play(2)
  162.             tile_goto(pos.x+1,pos.y+1,1)
  163.             current_level[pos.y+1][pos.x+1] = 1
  164.             if pos.y+1+(1) > 0 and  pos.x+1+(0) > 0 and
  165.                 pos.y+1+(1) <= 7 and pos.x+1+(0) <=13 then
  166.                     if current_level[pos.y+1+(1)][pos.x+1+(0)] != 0 then
  167.                         aum(pos.y+1+(1),pos.x+1+(0))
  168.                     end
  169.             end
  170.             if pos.y+1+(-1) > 0 and  pos.x+1+(0) > 0 and
  171.                 pos.y+1+(-1) <= 7 and pos.x+1+(0) <=13 then
  172.                 if current_level[pos.y+1+(-1)][pos.x+1+(0)] != 0 then
  173.                     aum(pos.y+1+(-1),pos.x+1+(0))
  174.                 end
  175.             end
  176.             if pos.y+1+(0) > 0 and  pos.x+1+(1) > 0 and
  177.                 pos.y+1+(0) <= 7 and pos.x+1+(1) <=13 then
  178.                 if current_level[pos.y+1+(0)][pos.x+1+(1)] != 0 then
  179.                     aum(pos.y+1+(0),pos.x+1+(1))
  180.                 end
  181.             end
  182.             if pos.y+1+(0) > 0 and  pos.x+1+(-1) > 0 and
  183.                 pos.y+1+(0) <= 7 and pos.x+1+(-1) <=13 then
  184.                 if current_level[pos.y+1+(0)][pos.x+1+(-1)] != 0 then
  185.                     aum(pos.y+1+(0),pos.x+1+(-1))
  186.                 end
  187.             end
  188.         end
  189.     blit_level(cnv)
  190.     puntero.img:blit(puntero.x,puntero.y)
  191.     screen.flip()
  192.     check_level()
  193. else blit_level(cnv); puntero.img:blit(puntero.x,puntero.y); screen.flip() end
  194. if controls.select() then a() end
  195. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement