I'm kind of working on something like this (kind of.. I'm a better procrastinator than coder at times lol). There is a code snippet in AGK's example folder - (..\Multiplayer\GettingStarted). It should do just that
I'm not sure about the host migration thing though. I'm only trying to make a two-player game atm. I imagine you'd have to re-negotiate for a new host or something when a host leaves, making the game halt a bit.
As for LAN, I was super pleasantly surprised at how easy it was to make a wireless LAN type connection! All you have to do is to make a WiFi hotspot on one of the mobile devices (android), and just connect to that with the other device. No internet required! My tablet unfortunately couldn't make a hotspot afaik, but my mobile phones can (I have an old, ooold one with Android 2.3.5, as well as a newer one (Android 6.0), both works). Except for the WiFi hotspot thing it should the same for desktops (I've only tried between my desktop and a tablet, but I'm pretty sure it is, as long as the computers can reach each other via a network).
I changed the GettingStarted example slightly for a slightly better demonstration (imho). I uploaded it to the "code base entries" a while ago,
here. It seems those pages are in a bit of a mess atm but the code does show. Just in case I'm also posting it below (media files exists in the GettingStarted\media folder, just copy this folder if you want to try this).
// Modified (slightly) from AGK2 example "Multiplayer - GettingStarted"
// set a display aspect
SetDisplayAspect ( 4.0 / 3.0 )
// load two images
LoadImage ( 1, "green.png" )
LoadImage ( 2, "red.png" )
LoadImage ( 3, "background5.jpg" )
// backdrop
CreateSprite ( 3, 3 )
// create sprite 11 (the host)
CreateSprite ( 11, 1 )
SetSpritePosition ( 11, 10, 20 )
SetSpriteSize ( 11, 25, -1 )
// create sprite 12 (the joiner)
CreateSprite ( 12, 2 )
SetSpritePosition ( 12, 50, 20 )
SetSpriteSize ( 12, 25, -1 )
// set some variables
State = 0
iType = 0
NetworkID = 0
// main loop
do
// initial state of game - host or join game
if State = 0
// display instructions
Print ( "Select green square to host a game" )
Print ( "Select red square to join a game" )
// check input
if GetPointerPressed ( ) = 1
// find out which sprite was hit
hit = GetSpriteHit ( GetPointerX ( ), GetPointerY ( ) )
// green sprite - host game
if ( hit = 11 )
NetworkID = HostNetwork ( "AGK Test Game", "Player 1", 1025 )
iType = 0
State = 1
localSprite = 11
remoteSprite = 12
endif
// red sprite - join game
if ( hit = 12 )
randomplayername$="player"+str(random(1,10000))
NetworkID = JoinNetwork ( "AGK Test Game", randomplayername$ )
iType = 1
State = 1
localSprite = 12
remoteSprite = 11
endif
endif
endif
// in game
if State = 1 and NetworkID = 0 then print ("Network connection failed")
if State = 1 and NetworkID > 0
rem network status
printc ("Network active:")
printc (IsNetworkActive ( NetworkID ))
for activity=1 to activitycount
printc(".")
next activity
print("")
inc activitycount
if activitycount>10 then activitycount=0
rem if active
if IsNetworkActive ( NetworkID ) <> 0
// get ID of first player
id = GetNetworkFirstClient ( NetworkID )
// cycle through all players and display their names on screen
while id <> 0
// show current player
Print ( GetNetworkClientName ( NetworkID, id ) )
// find next player
id = GetNetworkNextClient ( NetworkID )
endwhile
// update position of local player
x# = GetPointerX ( )
y# = GetPointerY ( )
SetSpritePosition ( localSprite, x#, y# )
// create a message containing the position to be sent out to the other player
cmessage = CreateNetworkMessage ( )
AddNetworkMessageFloat ( cmessage, x# )
AddNetworkMessageFloat ( cmessage, y# )
SendNetworkMessage ( NetworkID, 0, cmessage )
// Get remote position message
dmessage = GetNetworkMessage ( NetworkID )
while dmessage <> 0
// get position
x2# = GetNetworkMessageFloat ( dmessage )
y2# = GetNetworkMessageFloat ( dmessage )
// update remote players position
SetSpritePosition ( remoteSprite, x2#, y2# )
// delete the current message
DeleteNetworkMessage ( dmessage )
// find the next message
dmessage = GetNetworkMessage ( NetworkID )
endwhile
endif
endif
// update the screen
Sync ( )
loop
EDIT: Well from reading Dybing's answer above I se the same example is mentioned. Still, hope this is of some use to someone.
Apologies for any typos and strange grammar.