Advertisement
xerpi

scrolling

Jun 5th, 2011
288
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.88 KB | None | 0 0
  1. stuff = image.loadsprite("stuff.png",16,16)
  2. dofile("mapa.txt")
  3.  
  4. scroll={x=0,y=0,w=16,h=16}
  5.  
  6. --initx =  x-480/w  -x*w                              math.floor((480-x)/w)
  7. --inity =
  8.  
  9.  
  10. function blit_map(x,y,w,h)
  11. x,y,w,h = x or 0, y or 0, w or 16, h or 16
  12. for a = math.max(1,-math.ceil(y/h)), #mapa do
  13.  for b = math.max(1,-math.ceil(x/w)), #mapa[a] do
  14.     if tonumber(mapa[a][b]) > 0 then stuff:setframe(tonumber(mapa[a][b])) stuff:blit(x+(b-1)*16,y+(a-1)*16) end
  15.  end
  16. end
  17.  
  18. screen.print(5,5,screen.fps().."  "..math.abs(math.floor(x/16)))
  19. end
  20.  
  21.  
  22. while true do
  23. controls.read()
  24.  
  25. blit_map(scroll.x,scroll.y,scroll.w,scroll.h)
  26.  
  27. if controls.up() then scroll.y = scroll.y -1 end
  28. if controls.down() then scroll.y = scroll.y +1 end
  29. if controls.right() then scroll.x = scroll.x +1 end
  30. if controls.left() then scroll.x = scroll.x -1 end
  31.  
  32.  
  33. if controls.select() then a() end
  34. screen.flip()
  35. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement