Advertisement
BigSHinyToys

RGP game working

Jun 6th, 2013
192
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 7.39 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.char = char
  57. playerTable.lvl = lvl
  58. playerTable.xp = xp
  59. playerTable.money = money
  60. playerTable.hp = hp
  61.  
  62.  
  63.  
  64.  
  65. --[[Items Declare as:
  66. name
  67. lvlNeeded
  68. atkPoints
  69. Type
  70. cost
  71. ID ]]--
  72.  
  73. item1 = {"Wooden Sword", 1, 1, "Sword", 100, 1}
  74.  
  75. -- End Items --
  76.  
  77. -- End Levels --
  78.  
  79. -- Mobs --
  80. mob_Villager = {x, y}
  81. spawnedVillager = 0
  82. villager = "!"
  83. villagerHP = 5
  84. villagerXP = 2
  85. villagerMoney = 5
  86. villagerCol = colors.brown
  87. maxVillager = 5
  88.  
  89. quest1X = 10
  90. quest1Y = h-10
  91. questChar1 = "?"
  92. quest1Col = colors.orange
  93. -- End Mobs --
  94.  
  95. -- End Tables --
  96.  
  97. -- Keys --
  98.  
  99. up = 200
  100. down = 208
  101. left = 203
  102. right = 205
  103. enter = 28
  104. space = 57
  105. i = 23
  106. p = 25
  107. f4 = 62
  108. q = 16
  109. e = 18
  110. -- End Keys --
  111.  
  112. -- End Variables --
  113.  
  114. -- Functions --
  115.  
  116. -- Text Functions --
  117.  
  118. function centerPrint(string, X, Y)
  119.   term.setCursorPos(math.floor(w-string.len(string))/X, Y)
  120.   print(string)
  121. end
  122.  
  123. -- End Text Functions --
  124.  
  125. -- Moving Functions --
  126.  
  127. function Up()
  128.   term.setCursorPos(playerTable.charX, playerTable.charY)
  129.   print(" ")
  130.   playerTable.charY = playerTable.charY - 1
  131.   term.setTextColor(colors.yellow)
  132.   term.setCursorPos(playerTable.charX, playerTable.charY)
  133.   print(playerTable.char)
  134. end
  135.  
  136. function Down()
  137.   term.setCursorPos(playerTable.charX, playerTable.charY)
  138.   print(" ")
  139.   playerTable.charY = playerTable.charY + 1
  140.   term.setTextColor(colors.yellow)
  141.   term.setCursorPos(playerTable.charX, playerTable.charY)
  142.   print(playerTable.char)
  143. end
  144.  
  145. function Left()
  146.   term.setCursorPos(playerTable.charX, playerTable.charY)
  147.   print(" ")
  148.   playerTable.charX = playerTable.charX - 1
  149.   term.setTextColor(colors.yellow)
  150.   term.setCursorPos(playerTable.charX, playerTable.charY)
  151.   print(playerTable.char)
  152. end
  153.  
  154. function Right()
  155.   term.setCursorPos(playerTable.charX, playerTable.charY)
  156.   print(" ")
  157.   playerTable.charX = playerTable.charX + 1
  158.   term.setTextColor(colors.yellow)
  159.   term.setCursorPos(playerTable.charX, playerTable.charY)
  160.   print(playerTable.char)
  161. end
  162.  
  163. -- End Moving Functions --
  164.  
  165. function drawVillager() -- this may causes some probblems calling its self is a bad thing
  166. if spawnedVillager < maxVillager then
  167. term.setBackgroundColor(colors.black)
  168. sleep(0.5)
  169. local randX = math.random(2, w-1)
  170. local randY = math.random(2, h-1)
  171. term.setTextColor(villagerCol)
  172. term.setCursorPos(randX, randY)
  173. local mob = {randX, randY}
  174. table.insert(mob_Villager, mob)
  175. print(villager)
  176. spawnedVillager = spawnedVillager + 1
  177. drawVillager()
  178. end
  179. end
  180.  
  181. function quest1()
  182. term.setBackgroundColor(colors.black)
  183. term.setTextColor(quest1Col)
  184. term.setCursorPos(quest1X, quest1Y)
  185. print(questChar1)
  186. end
  187.  
  188. function Pause()
  189. term.clear()
  190. centerPrint("Paused",2,2)
  191.  
  192. end
  193.  
  194. function Shop()
  195.   term.setBackgroundColor(colors.black)
  196. term.clear()
  197. width = 1
  198.   term.clear()
  199.   term.setBackgroundColor(colors.white)
  200.   for x = 1, width do term.setCursorPos(1, x) term.clearLine() end
  201.   for x = h - width + 1, h do term.setCursorPos(1, x) term.clearLine() end
  202.   for i = 1, width do
  203.     for x = 1, h do term.setCursorPos(i, x) term.write(" ") end
  204.     for x = 1, h do term.setCursorPos(w - i + 1, x) term.write(" ") end
  205.   end
  206.   centerPrint("Shop", 2,1)
  207. end
  208.  
  209. function inventory()
  210.   term.setBackgroundColor(colors.black)
  211.   term.clear()
  212.   width = 1
  213.   term.clear()
  214.   term.setBackgroundColor(colors.white)
  215.   for x = 1, width do term.setCursorPos(1, x) term.clearLine() end
  216.   for x = h - width + 1, h do term.setCursorPos(1, x) term.clearLine() end
  217.   for i = 1, width do
  218.     for x = 1, h do term.setCursorPos(i, x) term.write(" ") end
  219.     for x = 1, h do term.setCursorPos(w - i + 1, x) term.write(" ") end
  220.   end
  221.   centerPrint("Inventory of "..player,2,1)
  222.   term.setCursorPos(2, 3)
  223.   term.setTextColor(colors.white)
  224.   term.setBackgroundColor(colors.black)
  225.   centerPrint(" Level: "..lvl.." Money: "..money.." Health: "..hp.." XP: "..xp ,2, 3)
  226.   centerPrint("Current weapon: "..wep, 2,4)
  227.  
  228.  
  229. end
  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.   --[[ -- For testing perpouses
  253.   for key,value in pairs(mob_Villager) do
  254.     print(key," ",tostring(value))
  255.     if type(value) == "table" then
  256.         for key,value in pairs(value) do
  257.             print("sub ",key," ",tostring(value))
  258.         end
  259.     end
  260.     end
  261.     os.pullEvent()
  262.   ]]--
  263.   while true do
  264.     e, p1, p2, p3 = os.pullEvent()
  265.     if e == "key" then
  266.       if p1 == up then
  267.         if  inv == false and shop == false and pause == false then
  268.         if charY > 2 then
  269.           Up()
  270.         end
  271.       end
  272.       elseif p1 == down then
  273.         if  inv == false and shop == false and pause == false then
  274.         if charY < h-1 then
  275.           Down()
  276.         end
  277.       end
  278.       elseif p1 == left then
  279.         if  inv == false and shop == false and pause == false then
  280.         if playerTable.charX > 2 then
  281.           Left()
  282.         end
  283.         end
  284.       elseif p1 == right then
  285.         if  inv == false and shop == false and pause == false then
  286.         if playerTable.charX < w-1 then
  287.           Right()
  288.         end
  289.         end
  290.       elseif p1 == i then
  291.         if inv == false and shop == false and pause == false then
  292.           inv = true
  293.           inventory()
  294.         else
  295.           inv = false
  296.           desktop()
  297.         end
  298.       elseif p1 == p then
  299.         if shop == false and inv == false and pause == false then
  300.           shop = true
  301.           Shop()
  302.         else
  303.           shop = false
  304.           desktop()
  305.         end
  306.       elseif p1 == f4 then
  307.         if pause == false then
  308.           pause = true
  309.           Pause()
  310.         else
  311.           pause = false
  312.           desktop()
  313.         end
  314.       end
  315.     end
  316.     for i = 1,#mob_Villager do -- as you have no "map" you will have to go throught all mods and see if they match not clean but affective
  317.         if playerTable.charX == mob_Villager[i][1] and playerTable.charY == mob_Villager[i][2] then
  318.             term.setCursorPos(1,1)
  319.             term.clearLine()
  320.             term.write("Mob : "..tostring(i))
  321.             break
  322.         else
  323.             term.setCursorPos(1,1)
  324.             term.clearLine()
  325.             term.write("player X "..tostring(playerTable.charX).." Y "..tostring(playerTable.charY).." ")
  326.             term.write(tostring(mob_Villager[1][1]).." "..tostring(mob_Villager[1][2]))
  327.         end
  328.     end
  329.   end
  330. end
  331.  
  332.  
  333. desktop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement