Advertisement
xerpi

scrolling working!

Jun 5th, 2011
243
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.01 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)), math.min(#mapa,272/h-y/16+1) do
  13.  for b = math.max(1,-math.ceil(x/w)), math.min(#mapa[a],480/w-x/16+1) do
  14.     if tonumber(mapa[a][b]) > 0 then stuff:setframe(tonumber(mapa[a][b])) stuff:resize(w,h) stuff:blit(x+(b-1)*16,y+(a-1)*16) end
  15.  end
  16.  screen.print(5,5,screen.fps().."  "..math.min(#mapa,#mapa+math.ceil(y/h)).."  "..math.min(#mapa[a],#mapa[a]+math.ceil(x/w)))
  17. end
  18.  
  19.  
  20. end
  21.  
  22.  
  23. while true do
  24. controls.read()
  25.  
  26. blit_map(scroll.x,scroll.y,scroll.w,scroll.h)
  27.  
  28. if controls.up() then scroll.y = scroll.y -2 end
  29. if controls.down() then scroll.y = scroll.y +2 end
  30. if controls.right() then scroll.x = scroll.x +2 end
  31. if controls.left() then scroll.x = scroll.x -2 end
  32.  
  33.  
  34. if controls.select() then a() end
  35. screen.flip()
  36. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement