Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- os.cpu(333)
- imagen = {w =15,h = 15}
- imagen[1] = image.create(imagen.w,imagen.h,color.new(255,0,0))
- imagen[2] = image.create(imagen.w,imagen.h,color.new(0,255,0))
- imagen[3] = image.create(imagen.w,imagen.h,color.new(0,0,255))
- mapa = {x = 0, y = 0,actual = 1}
- mapa[1] = {
- {"2","2","2","2","2","2","2","2","2","2","2","2"},
- {"2","1","1","1","2","2","2","2","2","2","2","2"},
- {"2","1","2","1","2","2","2","2","2","2","2","2"},
- {"2","1","1","1","1","1","1","1","1","1","2","2"},
- {"2","2","2","2","2","2","2","2","2","2","1","2"},
- {"2","1","1","1","1","1","1","1","1","1","2","2"},
- {"2","1","2","1","2","2","2","2","2","2","2","2"},
- {"2","1","1","1","2","2","2","2","2","2","2","2"},
- {"2","2","2","2","2","2","2","2","2","2","2","2"}
- }
- function mapa.blit()
- for y = 1, #mapa[mapa.actual] do
- for x = 1, #mapa[mapa.actual][y] do
- local tx,ty = mapa.x + (x-1)*imagen.w,mapa.y + (y-1)*imagen.h;
- if (tx+imagen.w) >= 0 and tx <= 480 and (ty+imagen.h) >=0 and ty <= 272 then
- local tmp = imagen[tonumber(mapa[mapa.actual][y][x])]
- tmp:blit(tx,ty)
- tmp = nil;
- end
- end
- end
- end
- function mapa.update(w,h)
- imagen.w = w;
- imagen.h = h;
- for i = 1, #imagen do
- imagen[i]:resize(w,h);
- end
- mapa.y = 272-(#mapa[mapa.actual]*imagen.h)
- end
- function mapa.randomize()
- for y = 1, #mapa[mapa.actual] do
- for x = 1, #mapa[mapa.actual][y] do
- mapa[mapa.actual][y][x] = tostring(math.random(1,#imagen));
- end
- end
- end
- mapa.update(20,20)
- while true do
- controls.read();
- mapa.randomize()
- if controls.right() then mapa.x = mapa.x +1 end
- if controls.left() then mapa.x = mapa.x -1 end
- if controls.up() then mapa.y = mapa.y -1 end
- if controls.down() then mapa.y = mapa.y +1 end
- if controls.circle() then mapa.update(imagen.w+1,imagen.h); end
- if controls.square() then mapa.update(imagen.w-1,imagen.h); end
- if controls.triangle() then mapa.update(imagen.w,imagen.h+1); end
- if controls.cross() then mapa.update(imagen.w,imagen.h-1); end
- mapa.blit();
- screen.print(5,5,"@"..screen.fps().." x: "..mapa.x.." y: "..mapa.y.." w"..imagen.w.." h: "..imagen.h)
- if controls.select() then broke(); end
- screen.flip();
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement