Advertisement
xXm0dzXx

RoseTown RPG

Nov 10th, 2012
168
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.21 KB | None | 0 0
  1. local x,y = term.getSize()
  2. local currentX = 8
  3. local currentY = 9
  4. local char = "v"
  5. local debugging = false
  6. local hasSword = false
  7. local usingSword = false
  8. local killedGuard = false
  9.  
  10. local function cPrint(text)
  11. x2,y2 = term.getCursorPos()
  12. term.setCursorPos(math.ceil((x / 2) - (text:len() / 2)), y2)
  13. write(text.. "\n")
  14. end
  15.  
  16. local drawingBoard = {
  17. ["A"] = colors.white,
  18. ["B"] = colors.orange,
  19. ["C"] = colors.magenta,
  20. ["D"] = colors.lightBlue,
  21. ["E"] = colors.yellow,
  22. ["F"] = colors.lime,
  23. ["G"] = colors.pink,
  24. ["H"] = colors.gray,
  25. ["I"] = colors.lightGray,
  26. ["J"] = colors.cyan,
  27. ["K"] = colors.purple,
  28. ["L"] = colors.blue,
  29. ["M"] = colors.brown,
  30. ["N"] = colors.green,
  31. ["O"] = colors.red,
  32. ["P"] = colors.black,
  33. ["."] = colors.black,
  34. }
  35.  
  36. function advWrite( pos1, pos2, str )
  37. for i=1,#str do
  38. if pos1 + (i-1) < x-6 then
  39. term.setCursorPos( pos1 + (i-1) , pos2 )
  40. local symb = string.sub( str, i, i)
  41. if maps[ currentMap ]["NPCs"][ symb ] then
  42. local npcData = maps[ currentMap ]["NPCs"][ symb ]
  43. if npcData[ "Message" ] == "This area is too dangerous!" and killedGuard then
  44. term.setBackgroundColour( colors.orange )
  45. write(" ")
  46. else
  47. term.setBackgroundColour( npcData["Background"] )
  48. write( npcData[ "Symbol" ] )
  49.  
  50. if currentX == pos1 + (i-1) then
  51. if currentY == pos2 then
  52. if char == "^" then --Collision Detection
  53. currentY = currentY +1
  54. elseif char == "v" then
  55. currentY = currentY -1
  56. elseif char == ">" then
  57. currentX = currentX -1
  58. elseif char == "<" then
  59. currentX = currentX +1
  60. end
  61.  
  62. term.setCursorPos(1,y)
  63. term.setBackgroundColour( colors.black )
  64. write( npcData[ "Message" ] )
  65. repeat
  66. local event, key = os.pullEvent( "key" )
  67. until key ~= 1
  68.  
  69. if npcData[ "Message" ] == "Here, take this..." and hasSword ~= true then
  70. term.setCursorPos(1,y)
  71. term.setBackgroundColour( colors.black )
  72. write( "You received the..." )
  73. sleep(0.5)
  74. term.setTextColour( colors.red )
  75. write( " Sword!" )
  76. term.setTextColour( colors.white )
  77. hasSword = true
  78. repeat
  79. local event, key = os.pullEvent( "key" )
  80. until key ~= 1
  81. term.setCursorPos(1,y)
  82. term.clearLine()
  83. term.setBackgroundColour( colors.black )
  84. write( "Press the space bar to attack." )
  85. repeat
  86. local event, key = os.pullEvent( "key" )
  87. until key ~= 1
  88. end
  89.  
  90. animation = os.startTimer( 0.7 )
  91. redraw()
  92. end
  93. end
  94. end
  95. elseif drawingBoard[ symb ] then
  96. term.setBackgroundColour( drawingBoard[ symb ] )
  97. local x1 = pos1 + (i-1)
  98. local y1 = pos2
  99. if currentX == x1 and currentY == y1 then
  100. local mapWarps = (maps[ currentMap ])["Warps"]
  101. for i=1,#mapWarps do
  102. if currentX == mapWarps[i]["X"] and currentY == mapWarps[i]["Y"] then
  103. currentMap = mapWarps[i]["To"]
  104. currentX = mapWarps[i]["pX"]
  105. currentY = mapWarps[i]["pY"]
  106.  
  107. redraw()
  108. end
  109. end
  110. local colz = drawingBoard[ string.sub( str, i, i) ]
  111. if colz == colors.gray or colz == colors.green or colz == colors.cyan or symb == "." then
  112. if char == "^" then --Collision Detection
  113. currentY = currentY +1
  114. elseif char == "v" then
  115. currentY = currentY -1
  116. elseif char == ">" then
  117. currentX = currentX -1
  118. elseif char == "<" then
  119. currentX = currentX +1
  120. end
  121.  
  122. redraw()
  123. else
  124. write( char )
  125. end
  126. else
  127. if debugging then
  128. local colz = drawingBoard[ string.sub( str, i, i) ]
  129. if colz == colors.black then
  130. term.setTextColour( colors.lime )
  131. write("D")
  132. term.setTextColour( colors.white )
  133. elseif colz == colors.gray or colz == colors.green or colz == colors.cyan then
  134. term.setTextColour( colors.purple )
  135. write("W")
  136. term.setTextColour( colors.white )
  137. else
  138. term.setTextColour( colors.red )
  139. write("P")
  140. term.setTextColour( colors.white )
  141. end
  142. else
  143. if usingSword then
  144. if char == "^" and x1 == currentX and y1 == currentY -1 then
  145. write("|")
  146. elseif char == "v" and x1 == currentX and y1 == currentY +1 then
  147. write("|")
  148. elseif char == ">" and x1 == currentX +1 and y1 == currentY then
  149. write("-")
  150. elseif char == "<" and x1 == currentX -1 and y1 == currentY then
  151. write("-")
  152. else
  153. if symb == "O" and math.random(1,3) == 3 then
  154. write( "~" )
  155. else
  156. write( " " )
  157. end
  158. end
  159. else
  160. if symb == "O" and math.random(1,3) == 3 then
  161. write( "~" )
  162. else
  163. write( " " )
  164. end
  165. end
  166. end
  167. end
  168. end
  169. end
  170. end
  171. end
  172.  
  173. currentMap = "Room"
  174. maps = {
  175. ["Room"] = {
  176. "NNNNNNNNNNNNNNNNNNNNNN",
  177. "NFFFHHFFFFFNFHFFFFFFHF",
  178. "NFHHPHHFFFFNFFFFFHHFFF",
  179. "NFFFBFFFFBBzBBBHHOOHHF",
  180. "NFFFBBBBBBFHHHBHOOOOHH",
  181. "NFFFFFFBFFHHHHBBBBHOOH",
  182. "NFFFFHHPHHHHHHHHHBBBBP",
  183. "NFFFFHHHHHHOHHHOOHHHHH",
  184. "NFFHHHHHHOOHHHHHOOOOOO",
  185. ["MapLength"] = 9,
  186. ["Offset_X"] = 4,
  187. ["Offest_Y"] = 6,
  188. ["Warps"] = {
  189. [1] = {
  190. ["To"] = "Cave",
  191. ["X"] = 8,
  192. ["Y"] = 8,
  193. ["pX"] = 8,
  194. ["pY"] = 9,
  195. },
  196. [2] = {
  197. ["To"] = "Cave_1",
  198. ["X"] = 11,
  199. ["Y"] = 12,
  200. ["pX"] = 10,
  201. ["pY"] = 7,
  202. },
  203. [3] = {
  204. ["To"] = "Volcano",
  205. ["X"] = 25,
  206. ["Y"] = 12,
  207. ["pX"] = 5,
  208. ["pY"] = 8,
  209. },
  210. },
  211. ["NPCs"] = {
  212. ["z"] = {
  213. ["Symbol"] = "A",
  214. ["Background"] = colors.orange,
  215. ["Message"] = "This area is too dangerous!",
  216. },
  217. },
  218. },
  219. ["Cave"] = {
  220. "HHHHHHHHHHH",
  221. "HHHHHHHHIII",
  222. "HIHHPHHIJJI",
  223. "HIIIMIJJJJI",
  224. "HIHIMIIIMJI",
  225. "HIIIMMMMMII",
  226. ["MapLength"] = 6,
  227. ["Offset_X"] = 4,
  228. ["Offest_Y"] = 6,
  229. ["Warps"] = {
  230. [1] = {
  231. ["To"] = "Room",
  232. ["X"] = 8,
  233. ["Y"] = 8,
  234. ["pX"] = 8,
  235. ["pY"] = 9,
  236. },
  237. },
  238. ["NPCs"] = {
  239. },
  240. },
  241. ["Cave_1"] = {
  242. "HHHHHHPHHHHH",
  243. "HIIIIIMIIIII",
  244. "HIIIIIMIIIII",
  245. "HIIIIImIIIII",
  246. "HIOIOIOIOIOI",
  247. "HIIIIIIIIIII",
  248. ["MapLength"] = 6,
  249. ["Offset_X"] = 4,
  250. ["Offest_Y"] = 6,
  251. ["Warps"] = {
  252. [1] = {
  253. ["To"] = "Room",
  254. ["X"] = 10,
  255. ["Y"] = 6,
  256. ["pX"] = 11,
  257. ["pY"] = 11,
  258. },
  259. },
  260. ["NPCs"] = {
  261. ["m"] = {
  262. ["Symbol"] = "@",
  263. ["Background"] = colors.lightGray,
  264. ["Message"] = "Here, take this...",
  265. },
  266. },
  267. },
  268. ["Volcano"] = {
  269. "HHH",
  270. "HH........HHH",
  271. ".IIIIIIIIIIOH",
  272. "HH........HHH",
  273. "HHH",
  274. ["MapLength"] = 5,
  275. ["Offset_X"] = 4,
  276. ["Offest_Y"] = 6,
  277. ["Warps"] = {
  278. },
  279. ["NPCs"] = {
  280. },
  281. },
  282. }
  283. local stats = {
  284. ["XP"] = 0,
  285. ["$$"] = 25,
  286. ["LVL"] = 1,
  287. }
  288.  
  289. function drawGUI()
  290. for i=1,y do
  291. term.setCursorPos(x-6, i)
  292. write("|")
  293. end
  294.  
  295. term.setCursorPos(x-5,2)
  296. write("Stats")
  297. term.setCursorPos(x-5,4)
  298. write("XP:")
  299. term.setCursorPos(x-5,5)
  300. write("[ ]")
  301. if stats["XP"] == 5 then
  302. stats["XP"] = 1
  303. stats["LVL"] = stats["LVL"] +1
  304. end
  305.  
  306. for i=1,stats["XP"] do
  307. term.setCursorPos(x-5+i,5)
  308. write("|")
  309. end
  310.  
  311. term.setCursorPos( x-5, 6 )
  312. local level = stats["LVL"]
  313. if level < 10 then
  314. write(" >0" ..level.. "< ")
  315. else
  316. write(" >" ..level.. "< ")
  317. end
  318.  
  319. term.setCursorPos( x-5, 8 )
  320. write("Money:")
  321. term.setCursorPos( x-5, 9 )
  322. write("$" ..stats["$$"])
  323.  
  324. if debugging then
  325. term.setCursorPos( x-5, y-1 )
  326. write("X: " ..currentX)
  327. term.setCursorPos( x-5, y )
  328. write("Y: " ..currentY)
  329. end
  330. end
  331.  
  332. function drawMAP()
  333. local offsetX = maps[ currentMap ]["Offset_X"]
  334. local offsetY = maps[ currentMap ]["Offest_Y"]
  335. local mapLength = maps[ currentMap ]["MapLength"]
  336.  
  337. for i=1,mapLength do
  338. advWrite( offsetX, offsetY + (i-1), maps[ currentMap ][i] )
  339. end
  340. end
  341.  
  342. function redraw()
  343. term.setBackgroundColour( colors.black )
  344. term.clear()
  345.  
  346. term.setCursorPos(currentX,currentY)
  347. write( char )
  348.  
  349. drawGUI()
  350. drawMAP()
  351.  
  352. return start()
  353. end
  354.  
  355. function start()
  356. --while true do
  357. term.setBackgroundColour( colors.black )
  358. term.clear()
  359.  
  360. term.setCursorPos(currentX,currentY)
  361. write( char )
  362.  
  363. drawGUI()
  364. drawMAP()
  365.  
  366. local event, key = os.pullEvent()
  367. if event == "key" then
  368. if key == keys.up then
  369. currentY = currentY -1
  370. char = "^"
  371. elseif key == keys.down then
  372. currentY = currentY +1
  373. char = "v"
  374. elseif key == keys.left then
  375. currentX = currentX -1
  376. char = "<"
  377. elseif key == keys.right then
  378. currentX = currentX +1
  379. char = ">"
  380. elseif key == keys.enter then
  381. if debugging then
  382. debugging = false
  383. else
  384. debugging = true
  385. end
  386. elseif key == keys.space and hasSword then
  387. usingSword = true
  388. swordSwing = os.startTimer( 0.3 )
  389.  
  390. if currentX == 14 and currentY == 9 and currentMap == "Room" and char == ">" then
  391. killedGuard = true
  392. end
  393. end
  394. elseif event == "timer" then
  395. if key == animation then
  396. animation = os.startTimer( 0.7 )
  397. elseif key == swordSwing then
  398. usingSword = false
  399. end
  400. end
  401.  
  402. return redraw()
  403. --end
  404. end
  405.  
  406. animation = os.startTimer( 0.7 )
  407. start()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement