lennilenn

pixelWar

Oct 1st, 2014
168
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.04 KB | None | 0 0
  1. term.setTextColor(colors.white)
  2. term.setBackgroundColor(colors.black)
  3. shell.run("clear")
  4.  
  5. function movement()
  6.  if p1x == nil then p1x = 5 end if p2x == nil then p2x = 5 end
  7.  if p1y == nil then p1y = 5 end if p2y == nil then p2y = 10 end
  8.  
  9.  maxx, maxy = term.getSize()
  10.  
  11.  event,key = cAPI.eventTimer(1,"key")
  12.  if key == 17 and p1y ~= 1 then p1y = p1y - 1 end
  13.  if key == 31 and p1y ~= maxy then p1y = p1y + 1 end
  14.  if key == 30 and p1x ~= 1 then p1x = p1x - 1 end
  15.  if key == 32 and p1x ~= maxx then p1x = p1x + 1 end
  16.  if key == 200 and p2y ~= 1 then p2y = p2y - 1 end
  17.  if key == 208 and p2y ~= maxy then p2y = p2y + 1 end
  18.  if key == 203 and p2x ~= 1 then p2x = p2x - 1 end
  19.  if key == 205 and p2x ~= maxx then p2x = p2x + 1 end
  20. end
  21. function drawPixels()
  22.  drawBackground(colors.green)
  23.  term.setCursorPos(p1x,p1y)
  24.  term.setBackgroundColor(colors.red)
  25.  term.write(" ")
  26.  term.setCursorPos(p2x,p2y)
  27.  term.setBackgroundColor(colors.blue)
  28.  term.write(" ")
  29.  term.setCursorPos(1,1)
  30.  term.setBackgroundColor(colors.black)
  31. end
  32. function drawBackground(...)
  33.  arg = {...}
  34.  term.setBackgroundColor(arg[1])
  35.  term.clear()
  36.  term.setCursorPos(1,1)
  37. end
  38. function gameMenu()
  39.  term.setBackgroundColor(colors.black)
  40.  term.setTextColor(colors.white)
  41.  term.clear()
  42.  term.setCursorPos(1,1)
  43.  cAPI.createButton(2,2,"Begin Game",colors.red,colors.black,colors.black,"intern")
  44.  cAPI.createButton(2,4,"Help",colors.red,colors.black,colors.black,"intern")
  45.  cAPI.createButton(2,6,"Exit",colors.red,colors.black,colors.black,"intern")
  46.  Pos = cAPI.runButtonIntern(2,2,2,4,2,6)
  47.  if Pos == 1 then
  48.   drawBackground(colors.green)
  49.   term.setCursorPos(5,5)
  50.   term.setBackgroundColor(colors.red)
  51.   write(" ")
  52.   term.setBackgroundColor(colors.blue)
  53.   term.setCursorPos(5,10)
  54.   write(" ")
  55.   game()
  56.  end
  57.  if Pos == 2 then
  58.   drawBackground(colors.black)
  59.   print("movement:")
  60.   print("player1: WASD player2: ArrowKeys")
  61.   print("attack: ")
  62.   print("player1: spacebar  player2: Ctrl Right")
  63.   print(" ")
  64.   print(" press enter to exit ")
  65.   os.pullEvent("key")
  66.   shell.run("clear")
  67.   gameMenu()
  68.  end
  69.  if Pos == 3 then shell.run("clear") error("game ended")
  70.  else
  71.  gameMenu()
  72.  end
  73. end
  74. function game()
  75.  while true do
  76.  term.setCursorPos(1,1)
  77.  term.setBackgroundColor(colors.black)
  78.  term.setTextColor(colors.white)
  79.  local time = os.time() local formattedTime = textutils.formatTime(time, false) print("The time is " .. formattedTime.." press enter to exit")
  80.  movement()
  81.  if key == 28 then break end
  82.  if key == 57 and p1x == p2x and p2y == p1y then term.setBackgroundColor(colors.black) term.setTextColor(colors.white) term.clear() term.setCursorPos(10,10) print("p1 won!!") sleep(2) os.pullEvent() break end
  83.  if key == 157 and p1x == p2x and p2y == p1y then term.setBackgroundColor(colors.black) term.setTextColor(colors.white) term.clear() term.setCursorPos(10,10) print("p2 won!!") sleep(2) os.pullEvent() break end
  84.  drawPixels()
  85.  end
  86.  term.setBackgroundColor(colors.black)
  87.  term.setTextColor(colors.white)
  88.  shell.run("clear")
  89. end
  90. p1x = 5
  91. p1y = 5
  92. p2x = 5
  93. p2y = 10
  94. gameMenu()
Advertisement
Add Comment
Please, Sign In to add comment