Discord
Login
Community
DARK THEME

Help with player.m

I'm making a simple multiplayer game and i'm having so many questions, how can i make the client draw the background and the player after the player's connected, and how can i make him walk.

Link of the game: https://microstudio.io/rianstar/cheesescape2d/

init = function()
  connection = new ServerConnection()

  player = object
    x = 0
    y = 0
    speed = 2
    alive = 1
  end
  players = object end
end

update = function()
  for message in connection.messages
    players[message.id] = message
  end
  if keyboard.RIGHT then
    player.x += player.speed
  end
  if keyboard.LEFT then 
    player.x -= player.speed
  end
  if keyboard.UP then
    player.y += player.speed
  end
  if keyboard.DOWN then
    player.y -= player.speed
  end
  
  for message in connection.messages
    if players[message.id] then
      players[message.id].x = player.x
      players[message.id].y = player.y
      players[message.id].alive = player.alive
    end
  end
end

draw = function()
  screen.clear("rgb(255,255,255)")
    
  if connection.status != "conected" then   
    screen.fillRect(0,0,500,500,"rgb(0,0,0)")
    screen.drawText(connection.status, 0, 0, 30, "rgb(0,0,0)")
    for id in players
      local player = players[id]
      print(player)
      if player.alive then
        screen.drawSprite("icon",player.x, player.y, 16, 16)
      end
    end
  end
end

@Loginus Sometimes the player don't walk and in others the player teleport, what's happening?

I don't know .

Add an event logging mechanism.

You will know at what point and which element fails.

Post a reply

Progress

Status

Preview
Cancel
Post
Validate your e-mail address to participate in the community