Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Just Does Games --
- if not term.isColor() then return print("Advanced Computer Required.") end
- local w,h = term.getSize()
- local running = true
- local px,py = math.ceil(w/2), math.ceil(h/2)
- local prevx,prevy = px,py
- local cx,cy = px,py
- local player, background = colors.cyan, colors.black
- function animate_player()
- local limit, loop, update = 1, 0, true
- while running do
- if prevx ~= px or prevy ~= py then
- if prevx ~= px then
- if px > prevx then prevx = prevx + 1 else prevx = prevx - 1 end
- update = true
- end
- if prevy ~= py then
- if py > prevy then prevy = prevy + 1 else prevy = prevy - 1 end
- update = true
- end
- if update then
- term.setCursorPos(prevx,prevy)
- term.setBackgroundColor(background)
- print(" ")
- term.setCursorPos(prevx,prevy)
- term.setBackgroundColor(player)
- print(" ")
- end
- if loop == limit then sleep(0.1) loop = 0 else loop = loop + 1 end
- else
- sleep(.07) -- ANY LOWER AND IT STOPS WORKING... WHY>?
- end
- end
- end
- function controller()
- while running do
- a,i,x,y = os.pullEvent()
- if a == "key" then
- if i == keys.q then
- running = false
- else
- end
- elseif a == "mouse_click" or a == "mouse_drag" then
- term.setBackgroundColor(background)
- term.setCursorPos(cx,cy) write(" ")
- cx,cy = x,y
- term.setCursorPos(cx,cy) write("x")
- px,py = x,y
- end
- sleep(.01)
- end
- end
- function game()
- parallel.waitForAny(controller, animate_player)
- end
- term.setBackgroundColor(background)
- term.clear()
- term.setCursorPos(prevx,prevy)
- term.setBackgroundColor(player)
- print(" ")
- term.setBackgroundColor(background)
- game()
- term.clear() term.setCursorPos(1,1) print("Exited.") sleep(.3)
Advertisement
Add Comment
Please, Sign In to add comment