Advertisement
Guest User

Untitled

a guest
Jun 23rd, 2017
45
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.11 KB | None | 0 0
  1.  
  2. local Client = NetTest:addState('Client')
  3. function Client:enterState()
  4.   clearLoveCallbacks()
  5.   cursors = {}
  6.   mouse = {}
  7.   mouse.x = 0
  8.   mouse.y = 0
  9.   mouse.xp = -1
  10.   mouse.yp = -1
  11.  
  12.   print("initializing client")
  13.   function onReceive(data)
  14.     print("recieved " .. data)
  15.     --cursors = lube.bin:unpack(data)
  16.   end
  17.   client = lube.client()
  18.   client:setHandshake("Hi!")
  19.   client:setCallback(onReceive)
  20.   client:connect("127.0.0.1", 18025)
  21.   print("initialized client")
  22.  
  23.   function love.update(dt)
  24.     client:update(dt)
  25.     mouse.x, mouse.y = love.mouse.getPosition()
  26.     if mouse.x ~= mouse.xp and mouse.y ~= mouse.yp then
  27.       client:send(lube.bin:pack(mouse))
  28.     end
  29.     mouse.xp = mouse.x
  30.     mouse.yp = mouse.y
  31.   end
  32.   function love.draw()
  33.     for _,i in ipairs(cursors) do
  34.       love.graphics.circle("fill", i.x,i.y, 10, 64)
  35.     end
  36.   end
  37.   function love.keypressed(k)
  38.     if k=='escape' then
  39.       netTest:gotoState('Menu')
  40.     end
  41.   end
  42.   function love.quit()
  43.     client:disconnect()
  44.   end
  45. end
  46. function Client:exitState()
  47.   client:disconnect()
  48.   print("Exiting client")
  49. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement