Everything works, the collisions are buggy.
After I get the collisions running smoothly, I will make a invisible tile for the map.
I can't figure out while the players stick together sometimes.
Please help, thnaks.
SetVirtualResolution ( 640, 480 )
global virtualWidth
global virtualHeight
global playerID = 2
global netid
global joined = 0
initDisplay (90)
SetUpButtons()
JoinTheNetwork()
CreateSprites()
do
SetOwnSpriteDetails()
MoveAllSprites()
sync()
loop
function initDisplay ( height# )
device_width# = GetDeviceWidth ( )
device_height# = GetDeviceHeight ( )
virtual_width_multiplier# = device_width# / device_height#
if ( device_width# < device_height# )
virtual_width_multiplier# = device_height# / device_width#
endif
SetVirtualResolution ( height# * virtual_width_multiplier#, height# )
virtualWidth = height# * virtual_width_multiplier#
virtualHeight = height#
endfunction
function SetUpButtons()
AddVirtualJoystick ( 1, 10, 80, 10 )
SetJoystickScreenPosition ( 10, 70, 20 )
addvirtualbutton (1,10,20,10)
setvirtualbuttontext(1,"Host")
addvirtualbutton(2,30,20,10)
setvirtualbuttontext(2,"Join")
endfunction
function JoinTheNetwork()
rem *** Wait for button press ***
repeat
HandleButtons()
sync()
until joined = 1
DeleteVirtualButton(1)
DeleteVirtualButton(2)
deletesprite (85)
Endfunction
function HandleButtons()
if getvirtualbuttonpressed(1) = 1 and joined = 0
netid = Hostnetwork("MyNetwork", "Hostmachine",1206)
global playerID =2
joined = 1
endif
if getvirtualbuttonpressed(2) = 1 and joined = 0
clientname$ = str(getseconds())
netid = joinnetwork ("MyNetwork", clientname$)
joined = 1
global playerID =3
endif
endfunction
function CreateSprites()
LoadImage ( 10, "map.png" )
CreateSprite ( 10, 10 )
SetSpriteSize ( 10, 1000,-1)
SetClearColor(0,0,0)
Loadimage (2,"Player1.png")
createsprite(2,2)
SetSpriteAnimation ( 2, 32, 32, 11 )
SetSpriteSize ( 2, 5, -1 )
SetSpritePosition ( 2, 10, 10 )
PlaySprite ( 2, 10, 1, 1, 3 )
Loadimage (3,"Player2.png")
createsprite(3,3)
SetSpriteAnimation ( 3, 32, 32, 11 )
SetSpriteSize ( 3, 5, -1 )
PlaySprite ( 3, 10, 1, 1, 3)
boxcollision = 3
SetSpriteShape ( 2, boxcollision )
SetSpriteShape ( 3, boxcollision )
SetSpritePhysicsOn ( 2, 1 )
SetSpritePhysicsOn ( 3, 1 )
endfunction
function SetOwnSpriteDetails()
oldx# = GetSpriteX ( playerID )
oldy# = GetSpriteY ( playerID )
joyx# = getspritex(playerID)
joyy# = getspritey(playerID)
playerx# = joyx# + GetVirtualJoystickX ( 1 )
playery# = joyy# + GetVirtualJoystickY ( 1 )
x# = GetSpriteX ( playerID )
y# = GetSpriteY ( playerID )
SetSpritePosition ( playerID, GetSpriteX (playerID ) + ( joyx# / 5.0 ), GetSpriteY ( playerID) + ( joyy# / 5.0 ) )
SetViewOffset ( x# - 50, y# - 50 )
setnetworklocalfloat(netid,"x",playerx#)
setnetworklocalfloat(netid,"y",playery#)
endfunction
function MoveAllSprites()
clientid = getnetworkfirstclient(netid)
while clientid<> 0
if GetSpriteCollision(2,3) <>1
playerx# = getnetworkclientfloat(netid,clientid,"x")
playery# = getnetworkclientfloat(netid,clientid,"y")
SetSpritePosition ( clientid+1,playerx#,playery#)
endif
clientid = getnetworknextclient(netid)
endwhile
endfunction