vreezer

play

Jan 14th, 2015
216
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.77 KB | None | 0 0
  1. function loadAnimation(path, x, y, currentFrame)
  2. local anim = {
  3. type = "animation",
  4. x = x,
  5. y = y,
  6. frames = { },
  7. mirror = { x = false, y = false },
  8. currentFrame = currentFrame
  9. }
  10.  
  11. table.insert(anim.frames, { })
  12. if fs.exists(path) then
  13. local file = io.open(path, "r")
  14. local leftX, rightX = math.huge, 0
  15. local topY, botY = 1,1
  16.  
  17. local lcount = 0
  18. for line in file:lines() do
  19. lcount = lcount+1
  20. local cFrame = #anim.frames
  21. if line == "~" then
  22. anim.frames[cFrame].bounds = {
  23. x = leftX,
  24. y = topY,
  25. width = rightX - leftX + 1,
  26. height = botY - topY + 1
  27. }
  28. anim.frames[cFrame].dimensions = {
  29. width = rightX,
  30. height = botY
  31. }
  32. table.insert(anim.frames, { })
  33. leftX, rightX = math.huge, 0
  34. topY, botY = 1,1
  35. lcount = 0
  36. else
  37. table.insert(anim.frames[cFrame], {})
  38. for i=1,#line do
  39. if string.sub(line, i, i) ~= " " then
  40. leftX = math.min(leftX, i)
  41. rightX = math.max(rightX, i)
  42. if not topY then topY = lcount end
  43. botY = lcount
  44. end
  45. anim.frames[cFrame][#anim.frames[cFrame]] [i] = getColourOf(string.sub(line,i,i))
  46. end
  47. end
  48. end
  49. file:close()
  50. local cFrame = #anim.frames
  51. anim.frames[cFrame].bounds = {
  52. x = leftX,
  53. y = topY,
  54. width = rightX - leftX + 1,
  55. height = botY - topY + 1
  56. }
  57. anim.frames[cFrame].dimensions = {
  58. width = rightX,
  59. height = botY
  60. }
  61. anim.x = anim.x - leftX + 1
  62. anim.y = anim.y - topY + 1
  63.  
  64. if not currentFrame or type(currentFrame) ~= "number" or currentFrame < 1 or
  65. currentFrame > #anim.frames then
  66. anim.currentFrame = 1
  67. end
  68.  
  69. anim.timerID = nil
  70. anim.lowerBound = 1
  71. anim.upperBound = #anim.frames
  72. anim.updating = false
  73.  
  74. anim.repaint = repaintA
  75. anim.rCollidesWith = rCollidesWith
  76. anim.pCollidesWith = pCollidesWith
  77. anim.draw = drawA
  78. anim.update = updateA
  79. anim.next = nextA
  80. anim.previous = previousA
  81. anim.moveTo = moveTo
  82. return anim
  83. else
  84. error(path.." not found!")
  85. end
  86. end
  87.  
  88. mon = peripheral.wrap("right")
  89. mon.setBackgroundColor(colors.black)
  90. mon.clear()
  91.  
  92. loadAnimation("techsoft.nfa",1,1,1)
Advertisement
Add Comment
Please, Sign In to add comment