// THIS BIT FROM THE GAME
SetErrorMode(2)
// set window properties
SetWindowTitle( "PHONE CONTROLLER GAME CODE HERE" )
SetWindowSize( 1024, 768, 0 )
SetWindowAllowResize( 1 ) // allow the user to resize the window
// set display properties
SetVirtualResolution( 1024, 768 ) // doesn't have to match the window
SetOrientationAllowed( 1, 1, 1, 1 ) // allow both portrait and landscape on mobile devices
SetSyncRate( 30, 0 ) // 30fps instead of 60 to save battery
SetScissor( 0,0,0,0 ) // use the maximum available screen space, no black borders
SetGenerateMipmaps( 1 )
UseNewDefaultFonts( 1 ) // since version 2.0.22 we can use nicer default fonts
SetCameraRange(1,0.1,3000)
SetCameraRotation(1,0,0,0)
g=MakeColor(0,255,0)
r=MakeColor(255,0,255)
drawbox(1,1,1024,768,r,r,r,r,1)
DrawEllipse(1024/2,768/2,350,200,g,g,1)
DrawEllipse(1024/2,768/2,250,150,r,r,1)
DrawEllipse(1024/2,768/2,300,175,MakeColor(255,255,255),MakeColor(255,255,255),0)
getimage(1,1,1,1024,768)
global State = 0
global iType = 0
global NetworkID = 0
GLOBAL AccelY#
GLOBAL AccelX#
GLOBAL LR#
GLOBAL UD#
CreateObjectPlane(1,1000,600)
SetObjectImage(1,1,0)
RotateObjectLocalX(1,90)
////PUT YOUR GAME HERE
do
if GetRawKeyState(asc("A")) THEN RotateCameraLocalY(1,-6)
if GetRawKeyState(asc("D")) THEN RotateCameraLocalY(1,6)
//IF AccelX#<>0 then RotateCameraGlobalX(1,-AccelX#)
IF AccelY#<>0 THEN RotateCameraGlobalY(1,-AccelY#)
RotateCameraLOCALY(1,LR#)
//MoveCameraLocalZ(1,UD#)
MoveCameraLocalZ(1,3)
network()
Sync()
loop
function network() // TO RECIVE DATA FROM PHONE CONTROLLER PROGRAM
if State = 0
networkID = HostNetwork("AGK_NETWORK", "HOST", 45654)
iType = 0
State = 1
endif
if State = 1 and NetworkID = 0 then print ("Network connection failed")
if State = 1 and NetworkID > 0
inc activitycount
if activitycount>10 then activitycount=0
if IsNetworkActive ( NetworkID ) <> 0
id = GetNetworkFirstClient ( NetworkID )
while id <> 0
if iType = 0
cmessage = GetNetworkMessage ( NetworkID )
while cmessage <> 0
AccelX#=GetNetworkMessageFloat(cmessage)
AccelY#=GetNetworkMessageFloat(cmessage)
LR#=GetNetworkMessageFloat(cmessage)
UD#=GetNetworkMessageFloat(cmessage)
DeleteNetworkMessage ( cmessage )
cmessage = GetNetworkMessage ( NetworkID )
endwhile
cmessage = GetNetworkMessage ( NetworkID )
endif
id = GetNetworkNextClient ( NetworkID )
endwhilE
endif
endif
endfunction
/// this bit for the the game
SetErrorMode(2)
// set window properties
SetWindowTitle( "PHONE CONTROLLER GAME CODE HERE" )
SetWindowSize( 1024, 768, 0 )
SetWindowAllowResize( 1 ) // allow the user to resize the window
// set display properties
SetVirtualResolution( 1024, 768 ) // doesn't have to match the window
SetOrientationAllowed( 1, 1, 1, 1 ) // allow both portrait and landscape on mobile devices
SetSyncRate( 30, 0 ) // 30fps instead of 60 to save battery
SetScissor( 0,0,0,0 ) // use the maximum available screen space, no black borders
SetGenerateMipmaps( 1 )
UseNewDefaultFonts( 1 ) // since version 2.0.22 we can use nicer default fonts
SetCameraRange(1,0.1,3000)
SetCameraRotation(1,0,0,0)
g=MakeColor(0,255,0)
r=MakeColor(255,0,255)
drawbox(1,1,1024,768,r,r,r,r,1)
DrawEllipse(1024/2,768/2,350,200,g,g,1)
DrawEllipse(1024/2,768/2,250,150,r,r,1)
DrawEllipse(1024/2,768/2,300,175,MakeColor(255,255,255),MakeColor(255,255,255),0)
getimage(1,1,1,1024,768)
global State = 0
global iType = 0
global NetworkID = 0
GLOBAL AccelY#
GLOBAL AccelX#
GLOBAL LR#
GLOBAL UD#
CreateObjectPlane(1,1000,600)
SetObjectImage(1,1,0)
RotateObjectLocalX(1,90)
////PUT YOUR GAME HERE
do
if GetRawKeyState(asc("A")) THEN RotateCameraLocalY(1,-6)
if GetRawKeyState(asc("D")) THEN RotateCameraLocalY(1,6)
//IF AccelX#<>0 then RotateCameraGlobalX(1,-AccelX#)
IF AccelY#<>0 THEN RotateCameraGlobalY(1,-AccelY#)
RotateCameraLOCALY(1,LR#)
//MoveCameraLocalZ(1,UD#)
MoveCameraLocalZ(1,3)
network()
Sync()
loop
function network() // TO RECIVE DATA FROM PHONE CONTROLLER PROGRAM
if State = 0
networkID = HostNetwork("AGK_NETWORK", "HOST", 45654)
iType = 0
State = 1
endif
if State = 1 and NetworkID = 0 then print ("Network connection failed")
if State = 1 and NetworkID > 0
inc activitycount
if activitycount>10 then activitycount=0
if IsNetworkActive ( NetworkID ) <> 0
id = GetNetworkFirstClient ( NetworkID )
while id <> 0
if iType = 0
cmessage = GetNetworkMessage ( NetworkID )
while cmessage <> 0
AccelX#=GetNetworkMessageFloat(cmessage)
AccelY#=GetNetworkMessageFloat(cmessage)
LR#=GetNetworkMessageFloat(cmessage)
UD#=GetNetworkMessageFloat(cmessage)
DeleteNetworkMessage ( cmessage )
cmessage = GetNetworkMessage ( NetworkID )
endwhile
cmessage = GetNetworkMessage ( NetworkID )
endif
id = GetNetworkNextClient ( NetworkID )
endwhilE
endif
endif
endfunction
THIS BIT IS THE PHONE APP
SetErrorMode(2)
// set window properties
SetWindowTitle( "PHONE CODE FOR PHONE " )
SetWindowSize( 1024, 768, 0 )
SetWindowAllowResize( 1 ) // allow the user to resize the window
// set display properties
SetVirtualResolution( 1024, 768 ) // doesn't have to match the window
SetOrientationAllowed( 1, 1, 1, 1 ) // allow both portrait and landscape on mobile devices
SetSyncRate( 30, 0 ) // 30fps instead of 60 to save battery
SetScissor( 0,0,0,0 ) // use the maximum available screen space, no black borders
SetGenerateMipmaps( 1 )
UseNewDefaultFonts( 1 ) // since version 2.0.22 we can use nicer default fonts
SetCameraRange(1,0.1,3000)
SetCameraRotation(1,0,0,0)
global State = 0
global iType = 0
global NetworkID = 0
AddVirtualButton(1,200,600,100)
AddVirtualButton(2,100,500,100)
AddVirtualButton(3,300,500,100)
AddVirtualButton(4,200,400,100)
SetVirtualButtonVisible(1,0)
SetVirtualButtonVisible(2,0)
SetVirtualButtonVisible(3,0)
SetVirtualButtonVisible(4,0)
SetVirtualButtonActive(1,0)
SetVirtualButtonActive(2,0)
SetVirtualButtonActive(3,0)
SetVirtualButtonActive(4,0)
do
network()
Sync()
loop
function network()
if State = 0
StartGPSTracking()
CONTROLLER=1
SetVirtualButtonVisible(1,1)
SetVirtualButtonVisible(2,1)
SetVirtualButtonVisible(3,1)
SetVirtualButtonVisible(4,1)
SetVirtualButtonActive(1,1)
SetVirtualButtonActive(2,1)
SetVirtualButtonActive(3,1)
SetVirtualButtonActive(4,1)
NetworkID = JoinNetwork("AGK_NETWORK", "CLIENT")
iType = 1
State = 1
endif
if State = 1 and NetworkID = 0 then print ("Network connection failed")
if State = 1 and NetworkID > 0
inc activitycount
if activitycount>10 then activitycount=0
if IsNetworkActive ( NetworkID ) <> 0
id = GetNetworkFirstClient ( NetworkID )
while id <> 0
// join networkd
if iType = 1
cmessage = CreateNetworkMessage ( )
LR#=0
UD#=0
IF GetVirtualButtonState(2)=1 THEN LR#=-3
IF GetVirtualButtonState(3)=1 THEN LR#=3
IF GetVirtualButtonState(1)=1 THEN UD#=-1
IF GetVirtualButtonState(4)=1 THEN UD#=3
AddNetworkMessageFloat(cmessage, GetRawAccelX())
AddNetworkMessageFloat(cmessage, GetRawAccelY())
AddNetworkMessageFloat(cmessage, LR#)
AddNetworkMessageFloat(cmessage, UD#)
SendNetworkMessage ( NetworkID, 0, cmessage )
cmessage = GetNetworkMessage ( NetworkID )
endif
id = GetNetworkNextClient ( NetworkID )
endwhilE
endif
endif
endfunction