Advertisement
xerpi

Mapas sample3

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