Guest User

Laserbox 2 Game

a guest
Nov 5th, 2013
184
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 6.90 KB | None | 0 0
  1. lives = 5
  2. px = 1
  3. py = 4
  4. p2x = 49
  5. p2y = 4
  6. p1p = 0
  7. p2p = 0
  8. p1b = 3
  9. p2b = 3
  10. p1ba = down
  11. p2ba = down
  12. bar = paintutils.loadImage("lbbar")
  13. field = paintutils.loadImage("lbback")
  14. char1 = paintutils.loadImage("lbc1")
  15. char2 = paintutils.loadImage("lbc2")
  16. run = true
  17.  
  18.  
  19.  
  20.  
  21. function p1()
  22. while run do
  23. local event, button, X, Y = os.pullEvent("key")
  24. if button == keys.w then
  25.   if py ~= 2 then
  26.   py = py - 1
  27.   sleep(0.010)
  28. term.setBackgroundColor(colors.lightBlue)
  29. term.clear()
  30. term.setBackgroundColor(colors.orange)
  31. term.setCursorPos(1,1)
  32. print("P1: "..p1p.."/"..lives)
  33. term.setCursorPos(45,1)
  34. print("P2: "..p2p.."/"..lives)
  35. term.setBackgroundColor(colors.lightBlue)
  36. paintutils.drawImage(field,2,2)
  37. if p1ba == "up" then
  38. paintutils.drawImage(bar,px+1,py-1)
  39. end
  40.  
  41. if p2ba == "up" then
  42. paintutils.drawImage(bar,p2x-1,p2y-1)
  43. end
  44. paintutils.drawImage(char1,px,py)
  45. paintutils.drawImage(char2,p2x,p2y)
  46. if p1ba == "up" then
  47. paintutils.drawImage(bar,px+1,py-1)
  48. end
  49. end
  50. end
  51.  
  52. if button == keys.s then
  53.  if py ~= 17 then
  54.   py = py + 1
  55.   sleep(0.010)
  56. term.setBackgroundColor(colors.lightBlue)
  57. term.clear()
  58. term.setBackgroundColor(colors.orange)
  59. term.setCursorPos(1,1)
  60. print("P1: "..p1p.."/"..lives)
  61. term.setCursorPos(45,1)
  62. print("P2: "..p2p.."/"..lives)
  63. term.setBackgroundColor(colors.lightBlue)
  64. paintutils.drawImage(field,2,2)
  65. if p1ba == "up" then
  66. paintutils.drawImage(bar,px+1,py-1)
  67. end
  68.  
  69. if p2ba == "up" then
  70. paintutils.drawImage(bar,p2x-1,p2y-1)
  71. end
  72. paintutils.drawImage(char1,px,py)
  73. paintutils.drawImage(char2,p2x,p2y)
  74. if p1ba == "up" then
  75. paintutils.drawImage(bar,px+1,py-1)
  76. end
  77. end
  78. end
  79.  
  80.  
  81. if button == keys.leftShift then
  82. lx = px+1
  83. term.setCursorPos(lx,py)
  84. term.setBackgroundColor(colors.red)
  85. print "================================================"
  86. sleep(0.2)
  87. term.setBackgroundColor(colors.orange)
  88. term.setCursorPos(1,1)
  89. print("P1: "..p1p.."/"..lives)
  90. term.setCursorPos(45,1)
  91. print("P2: "..p2p.."/"..lives)
  92. if p1p == lives - 1 then
  93. p1p = p1p + 1
  94. term.setBackgroundColor(colors.orange)
  95. term.setCursorPos(1,1)
  96. term.setBackgroundColor(colors.orange)
  97. print("P1: "..p1p.."/"..lives)
  98. term.setCursorPos(45,1)
  99. print("P2: "..p2p.."/"..lives)
  100. print "PLayer 1 Wins!"
  101. run = false
  102. return
  103. elseif py == p2y then
  104.   if p2ba == "up" then
  105.      p2ba = down
  106.      term.setCursorPos(1,1)
  107. term.setBackgroundColor(colors.orange)
  108. print("P1: "..p1p.."/"..lives)
  109. term.setCursorPos(45,1)
  110. print("P2: "..p2p.."/"..lives)
  111.      else
  112. p1p = p1p + 1
  113. term.setCursorPos(1,1)
  114. term.setBackgroundColor(colors.orange)
  115. print("P1: "..p1p.."/"..lives)
  116. term.setCursorPos(45,1)
  117. print("P2: "..p2p.."/"..lives)
  118. end
  119. end
  120.  
  121. sleep(0.2)
  122. term.setBackgroundColor(colors.lightBlue)
  123. term.clear()
  124. term.setCursorPos(1,1)
  125. print("P1: "..p1p.."/"..lives)
  126. term.setCursorPos(45,1)
  127. print("P2: "..p2p.."/"..lives)
  128. term.setBackgroundColor(colors.lightBlue)
  129. paintutils.drawImage(field,2,2)
  130. term.setBackgroundColor(colors.orange)
  131. if p1ba == "up" then
  132. paintutils.drawImage(bar,px+1,py-1)
  133. end
  134.  
  135. if p2ba == "up" then
  136. paintutils.drawImage(bar,p2x-1,p2y-1)
  137. end
  138. paintutils.drawImage(char1,px,py)
  139. paintutils.drawImage(char2,p2x,p2y)
  140. end
  141.  
  142. if button == keys.d then
  143. if p1b == 0 then
  144.  
  145. else
  146. paintutils.drawImage(bar,px+1,py-1)
  147. p1b = p1b - 1
  148. p1ba = "up"
  149. end
  150. end
  151. end
  152. end
  153.  
  154.  
  155.  
  156. function p2()
  157. while run do
  158. local event, button, X, Y = os.pullEvent("key")
  159.  
  160.  
  161. if button == keys.down then
  162.    if p2y ~= 17 then
  163.   p2y = p2y + 1
  164. sleep(0.010)
  165. term.setBackgroundColor(colors.lightBlue)
  166. term.clear()
  167. term.setBackgroundColor(colors.orange)
  168. term.setCursorPos(1,1)
  169. print("P1: "..p1p.."/"..lives)
  170. term.setCursorPos(45,1)
  171. print("P2: "..p2p.."/"..lives)
  172. term.setBackgroundColor(colors.lightBlue)
  173. paintutils.drawImage(field,2,2)
  174. term.setBackgroundColor(colors.orange)
  175. if p1ba == "up" then
  176. paintutils.drawImage(bar,px+1,py-1)
  177. end
  178.  
  179. if p2ba == "up" then
  180. paintutils.drawImage(bar,p2x-1,p2y-1)
  181. end
  182. paintutils.drawImage(char1,px,py)
  183. paintutils.drawImage(char2,p2x,p2y)
  184. end
  185. end
  186.  
  187.  
  188. if button == keys.up then
  189.     if p2y ~= 2 then
  190.   p2y = p2y - 1
  191.   sleep(0.010)
  192. term.setBackgroundColor(colors.lightBlue)
  193. term.clear()
  194. term.setBackgroundColor(colors.orange)
  195. term.setCursorPos(1,1)
  196. print("P1: "..p1p.."/"..lives)
  197. term.setCursorPos(45,1)
  198. print("P2: "..p2p.."/"..lives)
  199. term.setBackgroundColor(colors.lightBlue)
  200. paintutils.drawImage(field,2,2)
  201. term.setBackgroundColor(colors.orange)
  202. if p1ba == "up" then
  203. paintutils.drawImage(bar,px+1,py-1)
  204. end
  205.  
  206. if p2ba == "up" then
  207. paintutils.drawImage(bar,p2x-1,p2y-1)
  208. end
  209. paintutils.drawImage(char1,px,py)
  210. paintutils.drawImage(char2,p2x,p2y)
  211. end
  212. end
  213.  
  214.  
  215. if button == keys.rightShift then
  216. l2y = p2y - 1
  217. term.setCursorPos(p2x,l2y)
  218. term.setBackgroundColor(colors.blue)
  219. print "================================================"
  220. sleep(0.2)
  221. term.setBackgroundColor(colors.orange)
  222. term.setCursorPos(1,1)
  223. print("P1: "..p1p.."/"..lives)
  224. term.setCursorPos(45,1)
  225. print("P2: "..p2p.."/"..lives)
  226. if p2p == lives - 1 then
  227. p2p = p2p + 1
  228. term.setBackgroundColor(colors.orange)
  229. if p1ba == "up" then
  230. paintutils.drawImage(bar,px+1,py-1)
  231. end
  232.  
  233. if p2ba == "up" then
  234. paintutils.drawImage(bar,p2x-1,p2y-1)
  235. end
  236. term.setBackgroundColor(colors.orange)
  237. term.setCursorPos(1,1)
  238. print("P1: "..p1p.."/"..lives)
  239. term.setCursorPos(45,1)
  240. print("P2: "..p2p.."/"..lives)
  241. print "PLayer 2 Wins!"
  242. run = false
  243. return
  244. elseif p2y == py then
  245.   if p1ba == "up" then
  246.   p1ba = down
  247.   term.setCursorPos(1,1)
  248. term.setBackgroundColor(colors.orange)
  249. print("P1: "..p1p.."/"..lives)
  250. term.setCursorPos(45,1)
  251. print("P2: "..p2p.."/"..lives)
  252.   else
  253. p2p = p2p + 1
  254. term.setCursorPos(1,1)
  255. term.setBackgroundColor(colors.orange)
  256. print("P1: "..p1p.."/"..lives)
  257. term.setCursorPos(45,1)
  258. print("P2: "..p2p.."/"..lives)
  259. end
  260. end
  261.  
  262. sleep(0.2)
  263. term.setBackgroundColor(colors.lightBlue)
  264. term.clear()
  265. term.setCursorPos(1,1)
  266. print("P1: "..p1p.."/"..lives)
  267. term.setCursorPos(45,1)
  268. print("P2: "..p2p.."/"..lives)
  269. term.setBackgroundColor(colors.lightBlue)
  270. paintutils.drawImage(field,2,2)
  271. term.setBackgroundColor(colors.orange)
  272. if p1ba == "up" then
  273. paintutils.drawImage(bar,px+1,py-1)
  274. end
  275.  
  276. if p2ba == "up" then
  277. paintutils.drawImage(bar,p2x-1,p2y-1)
  278. end
  279. paintutils.drawImage(char1,px,py)
  280. paintutils.drawImage(char2,p2x,p2y)
  281. end
  282.  
  283. if button == keys.l then
  284. if p2b == 0 then
  285.  
  286. else
  287. paintutils.drawImage(bar,p2x-1,p2y-1)
  288. p2b = p2b - 1
  289. p2ba = "up"
  290. end
  291. end
  292. end
  293. end
  294.  
  295.  
  296. term.setBackgroundColor(colors.lightBlue)
  297. term.clear()
  298. term.setBackgroundColor(colors.orange)
  299. term.setCursorPos(1,1)
  300. print("P1: "..p1p.."/"..lives)
  301. term.setCursorPos(45,1)
  302. print("P2: "..p2p.."/"..lives)
  303. term.setBackgroundColor(colors.lightBlue)
  304. paintutils.drawImage(field,2,2)
  305. term.setBackgroundColor(colors.orange)
  306. if p1ba == "up" then
  307. paintutils.drawImage(bar,px+1,py-1)
  308. end
  309.  
  310. if p2ba == "up" then
  311. paintutils.drawImage(bar,p2x-1,p2y-1)
  312. end
  313. paintutils.drawImage(char1,px,py)
  314. paintutils.drawImage(char2,p2x,p2y)
  315.  
  316.  
  317.  
  318. function para()
  319. while run do
  320. parallel.waitForAny(p1,p2)
  321. end
  322. end
  323. para()
Advertisement
Add Comment
Please, Sign In to add comment