How to combine Sparky and Tempest Systems !
Please Sparky can u help me to insert your the collision in my code or any one else !
Thanks a lot!
`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 MSGAMOUNTS as integer
global MSGAMOUNTR as integer
global YANGLE as float
dim playerdata(MAXPLAYERS) as playerstates
`------------------------------------------
set window size 400,300
`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$ = "127.0.0.1"
`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
load object "soldier.x",x
scale object x,700,700,700
rotate object x,-180,0,0
next x
`Make a matrix
load object "map\tutorial.x",111
scale object 111,30,30,30
rem sc_setupComplexObject 1,1,2
`sc_setupObject 1,1,0
rem load image "1.jpg",1
rem texture object 1,1
load object "map\tutorial_lmap.x",444
scale object 444,30,30,30
ghost object on 444,111
set object ambient 444,0
do
`Output the framerate
text 0, 0, "Screen FPS: "+str$(screen fps())
load image "p1.bmp",111
paste image 111,300,10
`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()=1 then xrotate object OURID,0 : move object OURID,5 : xrotate object OURID,cx#
if downkey()=1 then xrotate object OURID,0 : move object OURID,-5 : xrotate object OURID,cx#
YANGLE=YANGLE+(mousemovex()/2.0)
yrotate object OURID, YANGLE
`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-YANGLE) * 50 + object position x(OURID)
zPos# = sin(270-YANGLE) * 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 YANGLE
TPutByte upkey()
TPutByte downkey()
TSetMessageID 2
TSendAll
LASTSENT = timer()
inc MSGAMOUNTS
endif
`Receive
repeat
newMsg = TGetMessage()
if newMsg
inc MSGAMOUNTR
from = TGetSender()
write string 1, "From: "+str$(from)+" ID: "+str$(TGetMessageID())
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