hey benjamin. I think theres something screwy with my computer.. or my router...
When i try to run your example program (i open it twice on the same computer, using 127.0.0.1 for both) it does the same thing that my other programs do. They run fine, and you can see the peoples nicknames up in the corner, and you can see the other persons cube sitting there, but you cant see it move.... it always stays in one spot.
any ideas?
I dont know if you need it, but heres the code.
`Constants --------------------------------
#constant MAXPLAYERS 10
#constant SENDGAP 100
`------------------------------------------
`Types ------------------------------------
type playerstates
keyup as boolean
keydown as boolean
endtype
`------------------------------------------
`Data -------------------------------------
global OURID as integer
global LASTSENT as integer
global PLAYER_ANGLE_Y as float
dim playerdata(MAXPLAYERS) as playerstates
`------------------------------------------
`Ask for choice of mode
print "1. Host"
print "2. Join"
Input "Choice: ", choice
`If no choice then quit
if choice=0 then end
`If choice is 1 then host a multiplayer game
if choice=1
`Ask for username and IP to host on
input "Nickname: ", nick$
input "IP: ", ip$
`If either variable is empty, set a default
if nick$="" then nick$ = "Host"
if ip$="" then ip$ = "0.0.0.0"
`Host the multiplayer game
result = THost(ip$, MAXPLAYERS, nick$)
`If hosting failed then report to user and quit
if not result
print "Failed to host game"
wait key
end
endif
endif
`If choice is 1 then join
if choice=2
`Ask for username and IP to host on
input "Nickname: ", nick$
input "IP: ", ip$
`If either variable is empty, set a default
if nick$="" then nick$ = "Client"
if ip$="" then ip$ = "127.0.0.1"
`Join the multiplayer game
result = TJoin(ip$, nick$)
`If hosting failed then report to user and quit
if not result
print "Failed to join game"
wait key
end
endif
endif
`Retrieve our ID in the game and store it
OURID = TGetThisID()
`Set up sync
sync on
sync rate 60
`Make the player objects and hide ones not in use
for x=1 to MAXPLAYERS
make object cube x, 10
color object x, rgb(100+rnd(155), 100+rnd(155), 100+rnd(155))
position object x, 0, 5, 0
if not TPlayerExist(x) then hide object x
next x
`Make a matrix
make matrix 1, 1000, 1000, 10, 10
load image "..\media\sands.bmp", 1
prepare matrix texture 1, 1, 4, 4
do
`Output the framerate
text 0, 0, "Screen FPS: "+str$(screen fps())
`Show who is online
for x=1 to MAXPLAYERS
if TPlayerExist(x)
text 0, x*13, TGetPlayername(x)+"("+str$(x)+") is connected."
endif
next x
`Update everything
HandleControls()
HandleCamera()
if TConnected() then HandleNetwork()
HandleMovement()
`Let Tempest update itself
TSync
`Refresh the screen
Sync
loop
function HandleMovement()
for x=1 to MAXPLAYERS
if OURID<>x and object exist(x)
if playerdata(x).keyup then move object x, 1
if playerdata(x).keydown then move object x, -1
endif
next x
endfunction
function HandleControls()
if upkey() then move object OURID, 1
if downkey() then move object OURID, -1
if leftkey() then dec PLAYER_ANGLE_Y
if rightkey() then inc PLAYER_ANGLE_Y
yrotate object OURID, PLAYER_ANGLE_Y
`This shows how the host can boot a player
if spacekey()
TKillPlayer 2
repeat : until not spacekey()
endif
`This shows how to disconnect
if shiftkey()
TDisconnect
repeat : until not shiftkey()
endif
endfunction
function HandleCamera()
xPos# = cos(270-PLAYER_ANGLE_Y) * 50 + object position x(OURID)
zPos# = sin(270-PLAYER_ANGLE_Y) * 50 + object position z(OURID)
position camera xPos#, 30, zPos#
point camera object position x(OURID), 5, object position z(OURID)
endfunction
function HandleNetwork()
`Player states
newPlayer = TNewPlayer()
if newPlayer>0 then show object newPlayer
`Send
if LASTSENT+SENDGAP<timer()
TPutFloat object position x(OURID)
TPutFloat object position z(OURID)
TPutFloat PLAYER_ANGLE_Y
TPutByte upkey()
TPutByte downkey()
TSendAll
LASTSENT = timer()
endif
`Receive
repeat
newMsg = TGetMessage()
if newMsg
from = TGetSender()
x# = TGetFloat()
z# = TGetFloat()
yA# = TGetFloat()
playerdata(from).keyup = TGetByte()
playerdata(from).keydown = TGetByte()
XVAL = x#
ZVAL = z#
if object exist(from)
position object from, x#, 5, z#
yrotate object from, yA#
endif
endif
until not newMsg
endfunction