Advertisement
Mackan90096

AsciiRPG

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