Guest User

Minecraft RPG

a guest
Jan 24th, 2013
166
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.57 KB | None | 0 0
  1. map = {"x","x","x","x","x","x","x","x","x",
  2.        "x","-","-","x","-","-","x","-","x",
  3.        "x","x","-","x","x","-","x","-","x",
  4.        "x","-","-","-","-","-","x","-","x",
  5.        "x","-","-","-","-","-","-","-","x",
  6.        "x","-","x","-","x","-","x","-","x",
  7.        "x","-","-","x","-","-","-","-","x",
  8.        "x","-","-","x","x","x","-","-","x",
  9.        "x","x","x","x","x","x","x","x","x"}
  10. charx = 2
  11. chary = 2
  12. charpos = 11
  13. turn = 0
  14. npcon = false
  15. start = true
  16. credits = {"Developer: Urumasi", "Map: Urumasi", "Textures: Urumasi"}
  17. function drawNPC(nx,ny,npos,nchar,nmode)
  18.   npcon = true
  19.   npcx = nx
  20.   npcy = ny
  21.   npcchar = nchar
  22.   npcmode = nmode
  23.   npcpos = npos
  24.   drawMap()
  25. end
  26. function updateNPC()
  27.   if npcmode == "dumb" then
  28.     turn = math.random(1,4)
  29.     if (turn == 1) and (map[npcpos-9] == "-") then
  30.       npcpos = npcpos-9
  31.       npcy = npcy-1
  32.     elseif (turn == 2) and (map[npcpos+9] == "-") then
  33.       npcpos = npcpos+9
  34.       npcy = npcy+1
  35.     elseif (turn == 3) and (map[npcpos-1] == "-") then
  36.       npcpos = npcpos-1
  37.       npcy = npcx-1
  38.     elseif (turn == 4) and (map[npcpos+1] == "-") then
  39.       npcpos = npcpos+1
  40.       npcy = npcx+1
  41.     end
  42.   end
  43. end
  44. function drawMap()
  45.   shell.run("clear")
  46.   print("+--+--+-+")
  47.   print("|  |  | |")
  48.   print("+- +- | |")
  49.   print("|     ' |")
  50.   print("|       |")
  51.   print("| O O O |")
  52.   print("|  ,    |")
  53.   print("|  +--  |")
  54.   print("+-------+")
  55.   if npcon then
  56.     term.setCursorPos(npcx,npcy)
  57.     write(npcchar)
  58.   end
  59.   term.setCursorPos(charx,chary)
  60.   print("&")
  61. end
  62. function move(side)
  63.   if (side == "w") and (map[charpos-9] == "-") then
  64.     charpos = charpos-9
  65.     chary = chary-1
  66.   elseif (side == "s") and (map[charpos+9] == "-") then
  67.     charpos = charpos+9
  68.     chary = chary+1
  69.   elseif (side == "a") and (map[charpos-1] == "-") then
  70.     charpos = charpos-1
  71.     charx = charx-1
  72.   elseif (side == "d") and (map[charpos+1] == "-") then
  73.     charpos = charpos+1
  74.     charx = charx+1
  75.   end
  76.   drawMap()
  77. end
  78. function drawCredits()
  79.   shell.run("clear")
  80.   print("\n\n\n"..credits[1])
  81.   sleep(1)
  82.   shell.run("clear")
  83.   print("\n\n"..credits[1])
  84.   print(credits[2])
  85.   sleep(1)
  86.   shell.run("clear")
  87.   print("\n"..credits[1])
  88.   print(credits[2])
  89.   print(credits[3])
  90.   sleep(1)
  91.   shell.run("clear")
  92.   print(credits[1])
  93.   print(credits[2])
  94.   print(credits[3])
  95.   sleep(1)
  96.   shell.run("clear")
  97.   print(credits[2])
  98.   print(credits[3])
  99.   sleep(1)
  100.   shell.run("clear")
  101.   print(credits[3])
  102.   sleep(1)
  103.   shell.run("clear")
  104.   sleep(1)
  105.   drawMap()
  106. end
  107. function drawMenu()
  108.   shell.run("clear")
  109.   print("Back")
  110.   print("Exit game")
  111.   mc = true
  112.   while mc do
  113.     local event, param1, param2, param3 = os.pullEvent("mouse_click")
  114.     if param1 == 1 then
  115.       if (param2 > 0) and (param2 < 5) and (param3 == 1) then
  116.         mc = false
  117.         drawMap()
  118.       end
  119.       if (param2 > 0) and (param2 < 10) and (param3 == 2) then
  120.         mc = false
  121.         start = false
  122.         shell.run("clear")
  123.       end
  124.     end
  125.   end
  126. end
  127.  
  128. drawMap()
  129. while start do
  130.   local event, param1 = os.pullEvent("char")
  131.   if (param1 == "w") or (param1 == "a") or (param1 == "s") or (param1 == "d") then
  132.     move(param1)
  133.   end
  134.   if param1 == "c" then
  135.     drawCredits()
  136.   end
  137.   if param1 == "l" then
  138.     shell.run("clear")
  139.     print("+++ +++ ++++")
  140.     print("+ + + + +")
  141.     print("++  +++ + ++")
  142.     print("+ + +   +  +")
  143.     print("+ + +   ++++")
  144.     print("\nVersion: 0.1")
  145.     print("\n156 lines of code!")
  146.     print("\nChangelog:")
  147.     print("Initial release!")
  148.     print("\nWIP: NPCs")
  149.     print("\n\nPress any key to return.")
  150.     event, param1 = os.pullEvent("char")
  151.     drawMap()
  152.   end
  153.   if param1 == "m" then
  154.     drawMenu()
  155.   end
  156. end
Advertisement
Add Comment
Please, Sign In to add comment