Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- if os.language() == "spanish" then
- level_completed = "Nivel completado."
- c_level = "Nivel actual: "
- game_finished = "Felicidades, has conseguido pasarte el juego entero! ¿Deseas volver a jugar?"
- else
- level_completed = "Level completed."
- c_level = "Current level: "
- game_finished = "Congrats, you have beaten the game! Would you like to play again?"
- end
- dofile("levels.lua");
- cnv=tonumber(ini.read("score.ini","maxscore",1));
- --sound.loop("snd/env.mp3")
- tile={size = 25,mini_size =10}
- puntero={img = image.load("img/puntero.png"),x=100,y=100}
- pos={}
- tiles={}
- mini_tiles={}
- for i = 1, 4 do
- tiles[i] = image.load("img/tiles/"..i..".png")
- mini_tiles[i] = image.load("img/tiles/mini/"..i..".png")
- end
- board={x=15,y=15}
- mini_board={x=340,y=190}
- current_level={}
- --sound_press = sound.load("snd/press.mp3")
- function notout(x,y)
- if pos.y+y+1 > 0 and pos.x+x+1 > 0 and
- pos.y+y <= 7 and pos.x+x+1 <=13 then
- return true else return false end
- end
- function check_level()
- isequal=true
- alllevel = ""
- for i=1,#current_level do
- alllevel = alllevel..string.implode(current_level[i])
- end
- if string.implode(level[cnv]) != alllevel then isequal = false end
- if isequal == true then
- if cnv == #level then
- if os.message(game_finished ,1) == 1 then
- cnv = 1
- ini.write("score.ini","maxscore",tostring(cnv))
- else ini.write("score.ini","maxscore",tostring(cnv)); os.exit(); end
- else
- os.message(level_completed)
- cnv=cnv+1
- load(cnv)
- ini.write("score.ini","maxscore",tostring(cnv))
- end
- end
- end
- function aum(y,x)
- if current_level[y][x] < 4 then current_level[y][x] = current_level[y][x] +1
- elseif current_level[y][x] == 4 then current_level[y][x] = 1 end
- end
- function load(lvl)
- current_level={
- {0,0,0,0,0,0,0,0,0,0,0,0,0},
- {0,0,0,0,0,0,0,0,0,0,0,0,0},
- {0,0,0,0,0,0,0,0,0,0,0,0,0},
- {0,0,0,0,0,0,0,0,0,0,0,0,0},
- {0,0,0,0,0,0,0,0,0,0,0,0,0},
- {0,0,0,0,0,0,0,0,0,0,0,0,0},
- {0,0,0,0,0,0,0,0,0,0,0,0,0}
- }
- pos.x = math.floor((puntero.x-board.x)/25);
- pos.y = math.floor((puntero.y-board.y)/25);
- end
- function blit_level(lvl)
- for y = 1, 7 do
- for x = 1, 13 do
- n = (y-1)*13+x
- if current_level[y][x] != 0 then tiles[current_level[y][x]]:blit(board.x+(x-1)*25,board.y+25*(y-1)) end
- 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
- end
- end
- end
- function tile_goto(x,y,t)
- ix = 227.5
- iy = 272
- x1= board.x+(x)*25
- y1= board.y+(y)*25
- if x1>=ix then
- x2=(480-ix)-(480-x1)
- else x2=ix-x1 end
- if y1>=iy then
- y2=(272-iy)-(272-y1)
- else y2=iy-y1 end
- --y2=iy-y1
- ang = math.atan(y2/x2)
- hi = math.sqrt((x2*x2+y2*y2))
- for i = 1, hi,4 do
- if x1>=ix then
- angx=ix+math.cos(-ang)*i
- angy=iy+math.sin(-ang)*i
- else
- angx=ix+math.cos(math.pi+ang)*i
- angy=iy+math.sin(math.pi+ang)*i
- end
- controls.read() if controls.select() then a() end
- if controls.up() then ang = ang+math.rad(1) end
- if controls.down() then ang = ang-math.rad(1) end
- tiles[t]:blit(angx,angy)
- draw.line(x1,y1,ix,iy,color.new(255,0,0))
- screen.print(5,5,"x1: "..x1.." y1: "..y1.." ang: "..math.deg(ang).." hi: "..hi.." i: "..i)
- screen.print(5,25,"x: "..angx.." y: "..angy.." x2: "..x2.." y2: "..y2)
- screen.flip()
- end
- end
- function move_cursor() --mover el cursor
- if math.abs(controls.analogx())>60 then puntero.x = puntero.x + controls.analogx()/45 end
- if math.abs(controls.analogy())>60 then puntero.y = puntero.y + controls.analogy()/45 end
- if puntero.x <0 then puntero.x = 0 end
- if puntero.y <0 then puntero.y = 0 end
- if puntero.x+puntero.img:width() >480 then
- puntero.x = 480-puntero.img:width()
- end
- if puntero.y+puntero.img:height() >272 then
- puntero.y = 272-puntero.img:height()
- end
- end
- load(cnv)
- while (true) do
- 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
- pos.x = math.floor((puntero.x-board.x)/25)
- pos.y = math.floor((puntero.y-board.y)/25)
- end
- controls.read();
- draw.rect(15,15,325,175,color.new(255,0,0));
- draw.rect(340,190,130,70,color.new(0,255,0));
- if controls.press("r") then load(cnv) end
- if controls.r() and controls.press("l") then cnv = 1; load(cnv) end
- draw.rect(board.x+pos.x*25,board.y+pos.y*25,25,25,color.new(0,255,0));
- draw.rect(mini_board.x+pos.x*10,mini_board.y+pos.y*10,10,10,color.new(255,0,0));
- 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);
- 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);
- 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);
- screen.print(330,190,"a\nb\nc\nd\ne\nf\ng",0.55,color.new(255,255,255),0x0);
- screen.print(355,5,c_level..cnv,0.66,color.new(255,255,255),0x0);
- move_cursor()
- if controls.press("cross") then
- if current_level[pos.y+1][pos.x+1] == 0 then
- --sound_press:play(2)
- tile_goto(pos.x+1,pos.y+1,1)
- current_level[pos.y+1][pos.x+1] = 1
- if pos.y+1+(1) > 0 and pos.x+1+(0) > 0 and
- pos.y+1+(1) <= 7 and pos.x+1+(0) <=13 then
- if current_level[pos.y+1+(1)][pos.x+1+(0)] != 0 then
- aum(pos.y+1+(1),pos.x+1+(0))
- end
- end
- if pos.y+1+(-1) > 0 and pos.x+1+(0) > 0 and
- pos.y+1+(-1) <= 7 and pos.x+1+(0) <=13 then
- if current_level[pos.y+1+(-1)][pos.x+1+(0)] != 0 then
- aum(pos.y+1+(-1),pos.x+1+(0))
- end
- end
- if pos.y+1+(0) > 0 and pos.x+1+(1) > 0 and
- pos.y+1+(0) <= 7 and pos.x+1+(1) <=13 then
- if current_level[pos.y+1+(0)][pos.x+1+(1)] != 0 then
- aum(pos.y+1+(0),pos.x+1+(1))
- end
- end
- if pos.y+1+(0) > 0 and pos.x+1+(-1) > 0 and
- pos.y+1+(0) <= 7 and pos.x+1+(-1) <=13 then
- if current_level[pos.y+1+(0)][pos.x+1+(-1)] != 0 then
- aum(pos.y+1+(0),pos.x+1+(-1))
- end
- end
- end
- blit_level(cnv)
- puntero.img:blit(puntero.x,puntero.y)
- screen.flip()
- check_level()
- else blit_level(cnv); puntero.img:blit(puntero.x,puntero.y); screen.flip() end
- if controls.select() then a() end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement