Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local x,y = 5,5
- local oldx,oldy = 5,5
- scancode
- local left_key, right_key, up_key, down_key = 203, 205, 200, 208
- local quit_key = 45
- maxx, maxy = term.getSize()
- function drawGuy()
- term.setCursorPos(x,y)
- term.write("@")
- end
- function eraseGuy()
- term.setCursorPos(oldx,oldy)
- term.write(" ")
- end
- function moveGuy(code)
- if ( code == left_key ) then x = x - 1 end
- if ( code == right_key ) then x = x + 1 end
- if ( code == up_key ) then y = y - 1 end
- if ( code == down_key ) then y = y + 1 end
- x = max(1,x)
- x = min(maxx,x)
- y = max(1,y)
- y = min(maxy,y)
- end
- term.clear()
- drawGuy()
- while scancode ~= quit_key do
- event, scancode = os.pullEvent("key")
- if ( scancode == left_key or scancode == right_key or scancode == up_key or scancode == down_key ) then
- oldx = x
- oldy = y
- moveGuy(scancode)
- eraseOldGuy()
- drawGuy()
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement