Advertisement
Mackan90096

AsciiRPG dev 2013-06-05

Jun 5th, 2013
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 6.14 KB | None | 0 0
  1. -- Variables --
  2.  
  3. ver = "1.0"
  4. author = "Mackan90096"
  5.  
  6. w, h = term.getSize()
  7.  
  8. -- Level Tables --
  9.  
  10. xpTable = {
  11. [1] = 100,
  12. [2] = 200,
  13. [3] = 500,
  14. [4] = 1000,
  15. [5] = 2500,
  16. [6] = 4000,
  17. [7] = 5000,
  18. [8] = 7500,
  19. [9] = 10000,
  20. [10] = 11500}
  21.  
  22. lvlHPTable= {
  23. [1] = 10,
  24. [2] = 20,
  25. [3] = 40,
  26. [4] = 50,
  27. [5] = 100,
  28. [6] = 200,
  29. [7] = 400,
  30. [8] = 500,
  31. [9] = 750,
  32. [10] = 1000}
  33.  
  34. -- End Level Tables --
  35.  
  36. char = "@"
  37. charX = 2
  38. charY = 10
  39. maxX = w-1
  40. maxY = h-1
  41. lvl = 1
  42. xp = 0
  43. hp = lvlHPTable[lvl]
  44. money = 100
  45. inv = false
  46. shop = false
  47. pause = false
  48. player = "Steve"
  49. wep = "Fists"
  50.  
  51. -- Tables --
  52.  
  53. playerTable = { }
  54. playerTable.charX = charX
  55. playerTable.charY = charY
  56. playerTable.lvl = lvl
  57. playerTable.xp = xp
  58. playerTable.money = money
  59. playerTable.hp = hp
  60.  
  61.  
  62.  
  63.  
  64. --[[Items Declare as:
  65. name
  66. lvlNeeded
  67. atkPoints
  68. Type
  69. cost
  70. ID ]]--
  71.  
  72. item1 = {"Wooden Sword", 1, 1, "Sword", 100, 1}
  73.  
  74. -- End Items --
  75.  
  76. -- End Levels --
  77.  
  78. -- Mobs --
  79. mob_Villager = {x, y}
  80. spawnedVillager = 0
  81. villager = "!"
  82. villagerHP = 5
  83. villagerXP = 2
  84. villagerMoney = 5
  85. villagerCol = colors.brown
  86. maxVillager = 5
  87.  
  88. quest1X = 10
  89. quest1Y = h-10
  90. questChar1 = "?"
  91. quest1Col = colors.orange
  92. -- End Mobs --
  93.  
  94. -- End Tables --
  95.  
  96. -- Keys --
  97.  
  98. up = 200
  99. down = 208
  100. left = 203
  101. right = 205
  102. enter = 28
  103. space = 57
  104. i = 23
  105. p = 25
  106. f4 = 62
  107. q = 16
  108. e = 18
  109. -- End Keys --
  110.  
  111. -- End Variables --
  112.  
  113. -- Functions --
  114.  
  115. -- Text Functions --
  116.  
  117. function centerPrint(string, X, Y)
  118.   term.setCursorPos(math.floor(w-string.len(string))/X, Y)
  119.   print(string)
  120. end
  121.  
  122. -- End Text Functions --
  123.  
  124. -- Moving Functions --
  125.  
  126. function Up()
  127.   term.setCursorPos(charX, charY)
  128.   print(" ")
  129.   charY = charY - 1
  130.   term.setTextColor(colors.yellow)
  131.   term.setCursorPos(charX, charY)
  132.   print(char)
  133. end
  134.  
  135. function Down()
  136.   term.setCursorPos(charX, charY)
  137.   print(" ")
  138.   charY = charY + 1
  139.   term.setTextColor(colors.yellow)
  140.   term.setCursorPos(charX, charY)
  141.   print(char)
  142. end
  143.  
  144. function Left()
  145.   term.setCursorPos(charX, charY)
  146.   print(" ")
  147.   charX = charX - 1
  148.   term.setTextColor(colors.yellow)
  149.   term.setCursorPos(charX, charY)
  150.   print(char)
  151. end
  152.  
  153. function Right()
  154.   term.setCursorPos(charX, charY)
  155.   print(" ")
  156.   charX = charX + 1
  157.   term.setTextColor(colors.yellow)
  158.   term.setCursorPos(charX, charY)
  159.   print(char)
  160. end
  161.  
  162. -- End Moving Functions --
  163.  
  164. function drawVillager()
  165. if spawnedVillager < maxVillager then
  166. term.setBackgroundColor(colors.black)
  167. sleep(0.5)
  168. local randX = math.random(2, w-1)
  169. local randY = math.random(2, h-1)
  170. term.setTextColor(villagerCol)
  171. term.setCursorPos(randX, randY)
  172. local mob = {randX, randY}
  173. table.insert(mob_Villager, mob)
  174. print(villager)
  175. spawnedVillager = spawnedVillager + 1
  176. drawVillager()
  177. end
  178. end
  179.  
  180. function quest1()
  181. term.setBackgroundColor(colors.black)
  182. term.setTextColor(quest1Col)
  183. term.setCursorPos(quest1X, quest1Y)
  184. print(questChar1)
  185. end
  186.  
  187. function Pause()
  188. term.clear()
  189. centerPrint("Paused",2,2)
  190.  
  191. end
  192.  
  193. function Shop()
  194.   term.setBackgroundColor(colors.black)
  195. term.clear()
  196. width = 1
  197.   term.clear()
  198.   term.setBackgroundColor(colors.white)
  199.   for x = 1, width do term.setCursorPos(1, x) term.clearLine() end
  200.   for x = h - width + 1, h do term.setCursorPos(1, x) term.clearLine() end
  201.   for i = 1, width do
  202.     for x = 1, h do term.setCursorPos(i, x) term.write(" ") end
  203.     for x = 1, h do term.setCursorPos(w - i + 1, x) term.write(" ") end
  204.   end
  205.   centerPrint("Shop", 2,1)
  206. end
  207.  
  208. function inventory()
  209.   term.setBackgroundColor(colors.black)
  210.   term.clear()
  211.   width = 1
  212.   term.clear()
  213.   term.setBackgroundColor(colors.white)
  214.   for x = 1, width do term.setCursorPos(1, x) term.clearLine() end
  215.   for x = h - width + 1, h do term.setCursorPos(1, x) term.clearLine() end
  216.   for i = 1, width do
  217.     for x = 1, h do term.setCursorPos(i, x) term.write(" ") end
  218.     for x = 1, h do term.setCursorPos(w - i + 1, x) term.write(" ") end
  219.   end
  220.   centerPrint("Inventory of "..player,2,1)
  221.   term.setCursorPos(2, 3)
  222.   term.setTextColor(colors.white)
  223.   term.setBackgroundColor(colors.black)
  224.   centerPrint(" Level: "..lvl.." Money: "..money.." Health: "..hp.." XP: "..xp ,2, 3)
  225.   centerPrint("Current weapon: "..wep, 2,4)
  226.  
  227.  
  228. end
  229.  
  230.  
  231. function desktop()
  232.   function frame()
  233.     term.clear()
  234.     term.setBackgroundColor(colors.black)
  235.     width = 1
  236.     term.clear()
  237.     term.setBackgroundColor(colors.red)
  238.     for x = 1, width do term.setCursorPos(1, x) term.clearLine() end
  239.     for x = h - width + 1, h do term.setCursorPos(1, x) term.clearLine() end
  240.     for i = 1, width do
  241.       for x = 1, h do term.setCursorPos(i, x) term.write(" ") end
  242.       for x = 1, h do term.setCursorPos(w - i + 1, x) term.write(" ") end
  243.     end
  244.   end
  245.   frame()
  246.   drawVillager()
  247.   quest1()
  248.   term.setBackgroundColor(colors.black)
  249.   term.setTextColor(colors.yellow)
  250.   term.setCursorPos(charX, charY)
  251.   print(char)
  252.   while true do
  253.     e, p1, p2, p3 = os.pullEvent()
  254.     if e == "key" then
  255.       if p1 == up then
  256.         if  inv == false and shop == false and pause == false then
  257.         if charY > 2 then
  258.           Up()
  259.         end
  260.       end
  261.       elseif p1 == down then
  262.         if  inv == false and shop == false and pause == false then
  263.         if charY < h-1 then
  264.           Down()
  265.         end
  266.       end
  267.       elseif p1 == left then
  268.         if  inv == false and shop == false and pause == false then
  269.         if charX > 2 then
  270.           Left()
  271.         end
  272.         end
  273.       elseif p1 == right then
  274.         if  inv == false and shop == false and pause == false then
  275.         if charX < w-1 then
  276.           Right()
  277.         end
  278.         end
  279.       elseif p1 == i then
  280.         if inv == false and shop == false and pause == false then
  281.           inv = true
  282.           inventory()
  283.         else
  284.           inv = false
  285.           desktop()
  286.         end
  287.       elseif p1 == p then
  288.         if shop == false and inv == false and pause == false then
  289.           shop = true
  290.           Shop()
  291.         else
  292.           shop = false
  293.           desktop()
  294.         end
  295.       elseif p1 == f4 then
  296.         if pause == false then
  297.           pause = true
  298.           Pause()
  299.         else
  300.           pause = false
  301.           desktop()
  302.         end
  303.       end
  304.     end
  305.   end
  306. end
  307.  
  308.  
  309. desktop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement