Advertisement
Mackan90096

AsciiRPG Pre-Alpha

Jun 5th, 2013
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.18 KB | None | 0 0
  1. -- Variables --
  2.  
  3. ver = "1.0"
  4. author = "Mackan90096"
  5.  
  6. w, h = term.getSize()
  7.  
  8. char = "@"
  9. charX = 2
  10. charY = 10
  11. maxX = w-1
  12. maxY = h-1
  13. lvl = 1
  14. xp = 0
  15. money = 100
  16. inv = false
  17. shop = false
  18. player = "Steve"
  19. -- Tables --
  20.  
  21. -- Levels --
  22.  
  23. xpTable = {
  24. [1] = 100,
  25. [2] = 200,
  26. [3] = 500,
  27. [4] = 1000,
  28. [5] = 2500,
  29. [6] = 4000,
  30. [7] = 5000,
  31. [8] = 7500,
  32. [9] = 10000,
  33. [10] = 11500}
  34.  
  35. lvlHPTable= {
  36. [1] = 10,
  37. [2] = 20,
  38. [3] = 40,
  39. [4] = 50,
  40. [5] = 100,
  41. [6] = 200,
  42. [7] = 400,
  43. [8] = 500,
  44. [9] = 750,
  45. [10] = 1000}
  46.  
  47. --[[Items Declare as:
  48. name
  49. lvlNeeded
  50. atkPoints
  51. Type
  52. cost
  53. ID ]]--
  54.  
  55. item1 = {"Wooden Sword", 1, 1, "Sword", 100, 1}
  56.  
  57. -- End Items --
  58.  
  59. -- End Levels --
  60.  
  61. -- End Tables --
  62.  
  63. -- Keys --
  64.  
  65. up = 200
  66. down = 208
  67. left = 203
  68. right = 205
  69. enter = 28
  70. space = 57
  71. i = 23
  72. p = 25
  73. esc = 1
  74. -- End Keys --
  75.  
  76. -- End Variables --
  77.  
  78. -- Functions --
  79.  
  80. -- Text Functions --
  81.  
  82. function centerPrint(string, X, Y)
  83.   term.setCursorPos(math.floor(w-string.len(string))/X, Y)
  84.   print(string)
  85. end
  86.  
  87. -- End Text Functions --
  88.  
  89. -- Moving Functions --
  90.  
  91. function Up()
  92.   term.setCursorPos(charX, charY)
  93.   print(" ")
  94.   charY = charY - 1
  95.   term.setTextColor(colors.yellow)
  96.   term.setCursorPos(charX, charY)
  97.   print(char)
  98. end
  99.  
  100. function Down()
  101.   term.setCursorPos(charX, charY)
  102.   print(" ")
  103.   charY = charY + 1
  104.   term.setTextColor(colors.yellow)
  105.   term.setCursorPos(charX, charY)
  106.   print(char)
  107. end
  108.  
  109. function Left()
  110.   term.setCursorPos(charX, charY)
  111.   print(" ")
  112.   charX = charX - 1
  113.   term.setTextColor(colors.yellow)
  114.   term.setCursorPos(charX, charY)
  115.   print(char)
  116. end
  117.  
  118. function Right()
  119.   term.setCursorPos(charX, charY)
  120.   print(" ")
  121.   charX = charX + 1
  122.   term.setTextColor(colors.yellow)
  123.   term.setCursorPos(charX, charY)
  124.   print(char)
  125. end
  126.  
  127. -- End Moving Functions --
  128.  
  129. function Shop()
  130.   term.setBackgroundColor(colors.black)
  131. term.clear()
  132. width = 1
  133.   term.clear()
  134.   term.setBackgroundColor(colors.white)
  135.   for x = 1, width do term.setCursorPos(1, x) term.clearLine() end
  136.   for x = h - width + 1, h do term.setCursorPos(1, x) term.clearLine() end
  137.   for i = 1, width do
  138.     for x = 1, h do term.setCursorPos(i, x) term.write(" ") end
  139.     for x = 1, h do term.setCursorPos(w - i + 1, x) term.write(" ") end
  140.   end
  141.   centerPrint("Shop", 2,1)
  142. end
  143.  
  144. function inventory()
  145.   term.setBackgroundColor(colors.black)
  146.   term.clear()
  147.   width = 1
  148.   term.clear()
  149.   term.setBackgroundColor(colors.white)
  150.   for x = 1, width do term.setCursorPos(1, x) term.clearLine() end
  151.   for x = h - width + 1, h do term.setCursorPos(1, x) term.clearLine() end
  152.   for i = 1, width do
  153.     for x = 1, h do term.setCursorPos(i, x) term.write(" ") end
  154.     for x = 1, h do term.setCursorPos(w - i + 1, x) term.write(" ") end
  155.   end
  156.   centerPrint("Inventory of "..player,2,1)
  157. end
  158.  
  159.  
  160. function desktop()
  161.   function frame()
  162.     term.setBackgroundColor(colors.black)
  163.     width = 1
  164.     term.clear()
  165.     term.setBackgroundColor(colors.red)
  166.     for x = 1, width do term.setCursorPos(1, x) term.clearLine() end
  167.     for x = h - width + 1, h do term.setCursorPos(1, x) term.clearLine() end
  168.     for i = 1, width do
  169.       for x = 1, h do term.setCursorPos(i, x) term.write(" ") end
  170.       for x = 1, h do term.setCursorPos(w - i + 1, x) term.write(" ") end
  171.     end
  172.   end
  173.   frame()
  174.   term.setBackgroundColor(colors.black)
  175.   term.setTextColor(colors.yellow)
  176.   term.setCursorPos(charX, charY)
  177.   print(char)
  178.   while true do
  179.     e, p1, p2, p3 = os.pullEvent()
  180.     if e == "key" then
  181.       if p1 == up then
  182.         if charY > 2 then
  183.           Up()
  184.         end
  185.       elseif p1 == down then
  186.         if charY < h-1 then
  187.           Down()
  188.         end
  189.       elseif p1 == left then
  190.         if charX > 2 then
  191.           Left()
  192.         end
  193.       elseif p1 == right then
  194.         if charX < w-1 then
  195.           Right()
  196.         end
  197.       elseif p1 == i then
  198.         if inv == false then
  199.           inv = true
  200.           inventory()
  201.         else
  202.           inv = false
  203.           desktop()
  204.         end
  205.       elseif p1 == p then
  206.         if shop == false then
  207.           shop = true
  208.           Shop()
  209.         else
  210.           shop = false
  211.           desktop()
  212.         end
  213.       end
  214.     end
  215.   end
  216. end
  217.  
  218.  
  219. desktop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement