Multiplayer game with lua-enet and love

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
cuppajoeman
Prole
Posts: 3
Joined: Thu Apr 08, 2021 12:40 am

Multiplayer game with lua-enet and love

Post by cuppajoeman »

Hi there,

I am attempting to make a multiplayer game and would like some feedback on my ideas & answers to some questions.

My goal is to make the following game have multiplayer functionality (here is a video: https://streamable.com/e/m9wxy6). All the files you need to run the game are attached.

So far the game runs only on one computer, I instantiated a world and create physics bodies where a player can control themselves in it, they also have an aiming direction.

----------------------------------------------------------------------------------------------------------------------

I started by reading the lua-enet examples: https://love2d.org/wiki/lua-enet and realized that the method which sends the data (https://love2d.org/wiki/enet.peer:send) only allows sending strings.

So in my code you will find the method for a player called inputStateAsText which converts the players input into a string with the following format

|xDir|yDir|rotationAngle|

xDir = 1 implies positive x movement, xDir = -1 implies negative x movement, 0 is nothing, same concept for yDir

rotationAngle is the angle of the aiming line.

----------------------------------------------------------------------------------------------------------------------

My idea is to send this information to the server when the update function is called, let the server do the physics calculation based on their current inputs and then return where there new position should be. (Eventually also say if someone has gotten hit/died/etc... - but that's down the line)

Note: I am aware that eventually some type of interpolation should be added to smooth out the positions that are returned from the server so that it's not all jumpy, but for now, I just want something basic to work.

----------------------------------------------------------------------------------------------------------------------

I want to understand how to design the server now. So if I have N concurrent players all sending their data to the server, I will need a way determine who sent what info, so I can update their position only and not some other players accidentally, how would you recommend I do this? (1)

----------------------------------------------------------------------------------------------------------------------

Based on the server example code:

Code: Select all

-- server.lua
local enet = require "enet"
local host = enet.host_create("localhost:6789")
while true do
  local event = host:service(100)
  while event do
    if event.type == "receive" then
      print("Got message: ", event.data, event.peer)
      event.peer:send( "pong" )
    elseif event.type == "connect" then
      print(event.peer, "connected.")
    elseif event.type == "disconnect" then
      print(event.peer, "disconnected.")
    end
    event = host:service()
  end
end
It looks like the server just sits and waits until it gets messages and then simply reacts accordingly inside the first if block, is this where I would put my logic? If not, could someone give me some ideas for the structure of the server in this kind of setup/game (2)

----------------------------------------------------------------------------------------------------------------------

In my mind when you boot up the server, the following things should happen:
  • Instantiate the physics world
  • Start an infinite while loop
    • If a new player joins, then make them their own player object
  • Each players client will be calling the

    Code: Select all

    love.update(dt)
    at different moments in time, which sends a packet of their input information to the server
    • The moment the packet is received by the server - I need to apply physics based on their movement and then send back their new position
      • I am also realizing that I need to somehow timestamp when these inputs are received, as if I process them in some update function on the server, then it would be processing them as if they had all occured at the same time - which would make dodging and other movement unfair if you reacted first. How would you deal with this? (3) (maybe this doesn't matter because the delta time is small enough?)
I guess without complicating things any further or going down too many rabbit holes, I'd really like to see some sort of minimal working example of this basic physics simulation - or ideas on how to implement it. (2)

----------------------------------------------------------------------------------------------------------------------

So far I have read this discussion: https://love2d.org/forums/viewtopic.php?t=84776

@zorg mentions:
although you need to modify the infinite loops since löve already has love.update you should use.
So I know that love.update is involved on the server in some way or another, but other than that I am a little lost.

Thanks in advance.
Attachments
classic.lua
(1009 Bytes) Downloaded 25 times
player.lua
(1.61 KiB) Downloaded 25 times
main.lua
(4.02 KiB) Downloaded 25 times
tutor_34
Prole
Posts: 8
Joined: Thu Apr 01, 2021 2:54 am

Re: Multiplayer game with lua-enet and love

Post by tutor_34 »

where do i find the License this is really good.
tutor_34
Prole
Posts: 8
Joined: Thu Apr 01, 2021 2:54 am

Re: Multiplayer game with lua-enet and love

Post by tutor_34 »

i can pay you good money if you can exsplain in detail your code and how its effects is shown in game. 50$ 70$?
Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 27 guests