Benjamin i need your help
In Dark Basic Pro I used Tempest and I must say it is rather good
your very useful cube example is all well and good untill I came to add collision. It is quite hard to explain so here is a code snippet...
set window on
`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
`------------------------------------------
`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
make object cube x, 10
color object x, rgb(100+rnd(155), 100+rnd(155), 100+rnd(155))
position object x, 0, 5, 0
set object collision to boxes x
if not TPlayerExist(x) then hide object x
next x
`Make a matrix
make matrix 1, 1000, 1000, 10, 10
load image "sands.bmp", 1
prepare matrix texture 1, 1, 4, 4
do
if keystate(14)=0
msg$ = msg$ + entry$()
else
if entry$() <> "" then msg$ = left$(msg$,len(msg$)-1)
endif
text 0,300,"MyText: "+msg$
clear entry buffer
`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 YANGLE
if rightkey() then inc YANGLE
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()
`-------------------------------------------------------
rem this part is the collision bit
`-------------------------------------------------------
Rem Detect collision
If Object collision(ourid,0)>0 then position object ourid,X#,0,Z#
Rem get player object position and store in X# and Z#
X# = Object position x(ourid)
Z# = Object position z(ourid)
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
if rnd(10)<5 then TSendAll 1 else 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
the collision code should definitely work. I use it in every single Dark Basic Pro project of mine with no error. But when I use it with your Dll and when the player cube bumps into another object then the player cube just goes back to the start position? Please can you help me, the collision works in Multisync just fine but not in tempest using this example, what am i doing wrong???
Felony Rise 10% complete
Middle Earth ORPG 2%