Advertisement
xerpi

Mapas sample2

Dec 9th, 2011
183
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.84 KB | None | 0 0
  1. imagen = {w =15,h = 15}
  2.     imagen[1] = image.create(imagen.w,imagen.h,color.new(255,0,0))
  3.     imagen[2] = image.create(imagen.w,imagen.h,color.new(0,255,0))
  4.  
  5.  
  6. mapa = {x = 0, y = 0,actual = 1}
  7.     mapa[1] = {
  8.                 {"1","2","2","2","2","2","2","2","2","2","2","1"},
  9.                 {"1","2","2","2","2","2","2","2","2","2","2","1"},
  10.                 {"1","2","2","2","2","2","2","2","2","2","2","1"},
  11.                 {"1","2","2","2","2","2","2","2","2","2","2","1"},
  12.                 {"1","2","2","2","2","2","2","2","2","2","2","1"},
  13.                 {"1","2","2","2","2","2","2","2","2","2","2","1"},
  14.                 {"1","2","2","2","2","2","2","2","2","2","2","1"},
  15.                 {"1","2","2","2","2","2","2","2","2","2","2","1"},
  16.                 {"1","1","1","1","1","1","1","1","1","1","1","1"}
  17.             }
  18.  
  19.  
  20.  
  21. function mapa.blit()
  22.     for y = 1, #mapa[mapa.actual] do
  23.         for x = 1, #mapa[mapa.actual][y] do
  24.             imagen[tonumber(mapa[mapa.actual][y][x])]:blit(mapa.x + (x-1)*imagen.w, mapa.y + (y-1)*imagen.h)
  25.         end
  26.     end
  27. end
  28.  
  29. function mapa.update(w,h)
  30.     imagen.w = w;
  31.     imagen.h = h;
  32.     for i = 1, #imagen do
  33.         imagen[i]:resize(w,h);
  34.     end
  35.     mapa.y = 272-(#mapa[mapa.actual]*imagen.h)
  36. end
  37.  
  38.  
  39. mapa.update(20,20)
  40.  
  41. while true do
  42.     controls.read();
  43.     screen.clip(0,0,480,272)
  44.  
  45.    
  46.     if controls.right()    then mapa.x = mapa.x +1 end
  47.     if controls.left()     then mapa.x = mapa.x -1 end
  48.    
  49.     if controls.up()       then mapa.y = mapa.y -1 end
  50.     if controls.down()     then mapa.y = mapa.y +1 end
  51.    
  52.     if controls.circle()   then mapa.update(imagen.w+1,imagen.h); end
  53.     if controls.square()   then mapa.update(imagen.w-1,imagen.h); end
  54.    
  55.     if controls.triangle() then mapa.update(imagen.w,imagen.h+1); end
  56.     if controls.cross()    then mapa.update(imagen.w,imagen.h-1); end
  57.    
  58.     mapa.blit();
  59.    
  60.     screen.print(5,5,"@"..screen.fps().."  x: "..mapa.x.."  y: "..mapa.y.."  w"..imagen.w.."  h: "..imagen.h)
  61.     if controls.select() then broke(); end
  62.     screen.flip();
  63. end
  64.  
  65.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement