Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- term.setTextColor(colors.white)
- term.setBackgroundColor(colors.black)
- shell.run("clear")
- function movement()
- if p1x == nil then p1x = 5 end if p2x == nil then p2x = 5 end
- if p1y == nil then p1y = 5 end if p2y == nil then p2y = 10 end
- maxx, maxy = term.getSize()
- event,key = cAPI.eventTimer(1,"key")
- if key == 17 and p1y ~= 1 then p1y = p1y - 1 end
- if key == 31 and p1y ~= maxy then p1y = p1y + 1 end
- if key == 30 and p1x ~= 1 then p1x = p1x - 1 end
- if key == 32 and p1x ~= maxx then p1x = p1x + 1 end
- if key == 200 and p2y ~= 1 then p2y = p2y - 1 end
- if key == 208 and p2y ~= maxy then p2y = p2y + 1 end
- if key == 203 and p2x ~= 1 then p2x = p2x - 1 end
- if key == 205 and p2x ~= maxx then p2x = p2x + 1 end
- end
- function drawPixels()
- drawBackground(colors.green)
- term.setCursorPos(p1x,p1y)
- term.setBackgroundColor(colors.red)
- term.write(" ")
- term.setCursorPos(p2x,p2y)
- term.setBackgroundColor(colors.blue)
- term.write(" ")
- term.setCursorPos(1,1)
- term.setBackgroundColor(colors.black)
- end
- function drawBackground(...)
- arg = {...}
- term.setBackgroundColor(arg[1])
- term.clear()
- term.setCursorPos(1,1)
- end
- function gameMenu()
- term.setBackgroundColor(colors.black)
- term.setTextColor(colors.white)
- term.clear()
- term.setCursorPos(1,1)
- cAPI.createButton(2,2,"Begin Game",colors.red,colors.black,colors.black,"intern")
- cAPI.createButton(2,4,"Help",colors.red,colors.black,colors.black,"intern")
- cAPI.createButton(2,6,"Exit",colors.red,colors.black,colors.black,"intern")
- Pos = cAPI.runButtonIntern(2,2,2,4,2,6)
- if Pos == 1 then
- drawBackground(colors.green)
- term.setCursorPos(5,5)
- term.setBackgroundColor(colors.red)
- write(" ")
- term.setBackgroundColor(colors.blue)
- term.setCursorPos(5,10)
- write(" ")
- game()
- end
- if Pos == 2 then
- drawBackground(colors.black)
- print("movement:")
- print("player1: WASD player2: ArrowKeys")
- print("attack: ")
- print("player1: spacebar player2: Ctrl Right")
- print(" ")
- print(" press enter to exit ")
- os.pullEvent("key")
- shell.run("clear")
- gameMenu()
- end
- if Pos == 3 then shell.run("clear") error("game ended")
- else
- gameMenu()
- end
- end
- function game()
- while true do
- term.setCursorPos(1,1)
- term.setBackgroundColor(colors.black)
- term.setTextColor(colors.white)
- local time = os.time() local formattedTime = textutils.formatTime(time, false) print("The time is " .. formattedTime.." press enter to exit")
- movement()
- if key == 28 then break end
- 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
- 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
- drawPixels()
- end
- term.setBackgroundColor(colors.black)
- term.setTextColor(colors.white)
- shell.run("clear")
- end
- p1x = 5
- p1y = 5
- p2x = 5
- p2y = 10
- gameMenu()
Advertisement
Add Comment
Please, Sign In to add comment