So, i have my entire code, which i don't mind sharing, it's pretty much a 1:1 copy of the Example cube world demo that comes with multisync, but i modified it to work with my game, however, Players are not able to see each other... i've tried everything i can think of, i even compared the demo with my source side by side...
Any help is greatly appreciated.
My Code
Global name$ as string
global a$ as string
global dim message$(0) as string
global clearPrompt as integer
global promptFlag as integer
global rk
global gk as integer
global RCamRange as integer
global playerNum as integer
#constant SENDGAP 0.1
#constant MAXIMUM_PLAYERS 3200
#constant MESSAGE_ID_NAME 0
#constant MESSAGE_ID_CLANTAG 9
#constant MESSAGE_ID_GENERAL 1 : ` Contains just player data
#constant MESSAGE_ID_GENERALFULL 2 : ` Contains player numbers and player data
#constant MESSAGE_ID_PLAYERJOINED 3
#constant MESSAGE_ID_PLAYERQUIT 4
#constant FLAG_UP 1
#constant FLAG_DOWN 2
#constant FLAG_LEFT 4
#constant FLAG_RIGHT 8
#Constant FLAG_ROLL_LEFT 16
#Constant FLAG_ROLL_RIGHT 32
#Constant FLAG_PITCH_UP 64
#Constant FLAG_PITCH_DOWN 128
#constant MESSAGE_CHAT_ID 5
` Constants -----------------------------------
#constant MAXIMUM_TEXTLINE_AMOUNT 30
#constant MESSAGE_ID_FAIL 0
#constant MESSAGE_ID_SUCCESS 1
#constant MESSAGE_ID_REGISTER 0
#constant MESSAGE_ID_LOGIN 1
#constant MESSAGE_ID_CHAT 2
#constant MESSAGE_ID_NEWCLIENT 4
#constant MESSAGE_ID_CLIENTLEFT 5
` Variables -----------------------------------
dim TextLines(MAXIMUM_TEXTLINE_AMOUNT) as string
global CURRENT_TEXTLINE_AMOUNT as integer
global CURRENT_TEXT_ENTRY as string
global KEYDOWN_RETURN as boolean
global EnterKey as Byte
global ChatInUse as Byte
global LastChatMsg as String
global ChatKey as String
global ChatInputTimer as Integer
global ChatInputStr as String
` Types ------------------------------------------
type player_data
playerNum as integer
exist as boolean
name as string
CLANTAG as string
x as float
Y as float
z as float
realx as float
realz as float
angle as float
key_up as boolean
key_down as boolean
key_left as boolean
key_right as boolean
endtype
Type GameType
PvE as string
PvP as string
Normal as string
RP as string
ClanBattle as string
EndType
type Planet
object as integer
filename as string
name as string
population as integer
size as integer
race as string
endtype
` Variables --------------------------------------
global LASTSENT as integer
global NAME as string
Global CLANTAG as string
global dim player(MAXIMUM_PLAYERS) as player_data
global lastFlags as byte
global toSend
Global MaxPlanet = 64
dim Planet(MaxPlanet) as Planet
` ------------------------------------------------
sync off
autocam off
net put byte MESSAGE_ID_NAME
net put byte MESSAGE_ID_CLANTAG
net put string NAME
net put string CLANTAG
net send
`ip$="24.113.151.115"
ip$="127.0.0.1"
`ip$="192.168.1.102"
result = net connect(ip$)
net set port 22101
if not result
print "Could not connect: "+chr$(34)+net get error()+chr$(34)+"."
print "Press any key to exit."
wait key
end
endif
dWidth$ as integer
dHeight$ as integer
input "Desktop Width: ",dWidth$
input "Desktop Height: ",dHeight$
width = dWidth$
height = dHeight$
set display mode dWidth$, dHeight$,32
if dWidth$=>1920
maximize window
endif
textPosY = 600
load image "Media/login2.png",90111
paste image 90111,0,0
AstAmount as integer
PlanetAmount as integer
SET CURSOR 1240,690
input " ", NAME
SET CURSOR 1235,720
input " ", CLANTAG
RCamRange=2500
`input "Clan/Fleet Tag: ",CLANTAG
`input "Amount of Asteroids: ",AstAmount
`input "Amount of Planets: ",PlanetAmount
AstAmount=0
playerNum=10
cls
CenterBox(screen width()/2, screen height()/2, 135, 30, "LOADING...")
net put byte MESSAGE_ID_NAME
net put byte MESSAGE_ID_CLANTAG
net put string NAME
net put string CLANTAG
net send
LoadTextures()
playerNum = 1500
color ambient light rgb(64,64,64)
SET IMAGE COLORKEY 0,0,0
color backdrop 0,0
set normalization on
load object "Media/Nova.x",playerNum,5
NVLM = find free image (5000,5500)
NVCM = find free image (5001,5500)
load image "Media/federation_nova_LM.png",NVLM
load image "Media/federation_nova.tga",NVCM
texture object playerNum,0,NVCM
texture object playerNum,1,NVLM
set blend mapping on playerNum,1,NVLM,3,7
Load Effect "FX/relief_mapping.fx",125,0
Load Effect "FX/PixelLighting.fx",126,0
SP_Cube=find free object(1500,15000)
make object cube SP_Cube,10
Position Object SP_Cube,0,0,-1500
hide object SP_Cube
set object collision off SP_Cube
set object specular playerNum,rgb(255,192,128)
set object specular power playerNum,6
SET REFLECTION SHADING ON playerNum
position object playerNum,object position x(SP_Cube),object position y(SP_Cube),object position z(SP_Cube)
set object cull playerNum,1
SET SHADOW SHADING ON playerNum
set object collision on playerNum
set object collision to polygons playerNum
set ambient light 10
hide light 0
make light 100
color ambient light rgb(255,245,110)
position light 100,5000,0,15000
set light range 100,20000
set point light 100,5000,0,15000
make object sphere 100,5000
position object 100,5000,0,15000
set object light 100,0
sunimg = find free image (50500,50550)
load image "Media/51.png",sunimg
texture object 100,sunimg
set object specular 100,rgb(255,245,110)
backdrop on
color backdrop 0
set camera fov 45
set camera range 1,5280000
set global collision on
remstart
playerNum=10
load object "Media/Nova.x",10,5
NVLM = find free image (5000,5500)
NVCM = find free image (5001,5500)
load image "Media/federation_nova_LM.png",NVLM
load image "Media/federation_nova.tga",NVCM
texture object 10,0,NVCM
texture object 10,1,NVLM
set blend mapping on 10,1,NVLM,3,7
Load Effect "FX/relief_mapping.fx",125,0
Load Effect "FX/PixelLighting.fx",126,0
remend
make camera 6
set camera range 6,1,15000
set camera fov 6,60
backdrop on 6
color backdrop 6,rgb(128,128,128)
AIObj = 12500
load object "Media/Sabre.x",AIObj
scale object AIObj,35,35,35
position object AIObj, 0,0,1500
`CreatePlanets(950,0,0,5000)
`gosub draw_asteroids:
Health=100
health_time =timer()
healthRecovery_delay =5000
objnum = 1
Lvl=1
PlayerExp=0
XPMod#=1.00
VIPXPMod#=1.34
Xp=0
Txp=0
TotalXp=0
dim ChatArray(0) as String
global TotalChatSpaces as Integer
TotalChatSpaces = 20
gosub SetUp_Bloom:
sync on
sync rate 60
do
update_time=timer()
If net get message()=1
getMessage$=net get string()
messageFlag = 1
inc maxCount
array insert at bottom message$(0)
if messageFlag = 1 then message$(maxCount)= getMessage$
if messageFlag = 2 then message$(maxCount)="<<"+NAME+">>"+a$
inc tCount
if tCount > 17 then textPosY = textPosY -15
messageFlag = 0
endif
if keystate(27)=1 and clearPrompt = 0
clearPrompt = 1
promptFlag = 1
else
if keystate(27)=0
clearPrompt= 0
endif
endif
if promptFlag = 0
clearText = 1
a$ = ""
clear entry buffer
endif
if promptFlag = 1
if commandKeyFlag = 0
if a$= "]"
clear entry buffer
commandKeyFlag = 1
endif
endif
if returnkey()=1 and rk = 0
rk = 1
clientMessage$="["+CLANTAG+"]"+NAME+": "+a$
net put string clientMessage$
net send
messageFlag = 2
clear entry buffer
commandKeyFlag = 0
promptFlag = 0
else
if returnkey()=0
rk = 0
endif
endif
endif
if maxCount > 0
for i =1 to maxCount
text 10,textPosY+15*i,message$(i)
next i
endif
`set text opaque
if promptFlag = 1
a$=entry$(1)
text 10,screen height()-30,"Enter Message: "+a$
endif
text 320,screen height()-60, str$(screen fps())
box 30 * xMulti,27 * yMulti,31+Health * xMulti,35 * yMulti,rgb(175,0,0),rgb(175,0,0),rgb(200,0,0),rgb(200,0,0)
Health$="Hull: "+str$(Health)+"%" : text 5,5,Health$
if keystate(2)=1
wait 250
Create_Klingon_Neghvar()
Endif
If keystate(3)=1
wait 250
Create_Cardassian_Galor()
Endif
if keystate(4)=1
wait 250
Create_Borg_Cube()
Endif
if keystate(5)=1
wait 250
Create_Federation_Galaxy()
Endif
point object 100,camera position x(),camera position y(),camera position z()
if health=<0
CenterBox(screen width()/2, screen height()/2, 350, 26, "Your ship has been destroyed...")
endif
`if keystate(90)=1
` inc PlayerExp,1
` inc TotalXp,1
`Endif
remstart
Lv$="Level: "+str$(Lvl) : text 5,50,Lv$
GainedXp$="Xp: "+str$(PlayerExp) : text 5,75,GainedXp$
NeededXp$="Xp needed: "+str$(Xp) : text 5,100,NeededXp$
TotalXp$="Total XP: "+str$(TotalXp) : text 5,125,TotalXp$
if PlayerExp=Xp
Lvl=Lvl+1
dec PlayerExp,PlayerExp
Xp=Xp*XPMod#
Txp=PlayerExp
endif
remend
` HandleControls()
position camera object position x(playerNum),object position y(playerNum),object position z(playerNum)
if mouseclick()=0
xrotate camera camera angle x()+mousemovey()*0.25
yrotate camera camera angle y()+mousemovex()*0.25
if camera angle x()>90 then xrotate camera 90
if camera angle x()<-90 then xrotate camera -90
endif
if mouseclick()>0 then CamDis#=CamDis#-mousemovey()*0.25
CamDis#=CamDis#+mousemovez()*0.1
if CamDis#>-2 then CamDis#=-2
if CamDis#<-5000 then CamDis#=-5000
move camera CamDis#
`if camera position y()<-90 then position camera camera position x(),-90,camera position z()
mousemovex()=0
mousemovey()=0
`text 0,200,"Distance: "+str$(dist2object(1,98360))
text 0,250,"Polygons Onscreen: "+str$(statistic(1))
gosub UpDate_Bloom
set camera to image 6,6995,150,150
paste image 6995,screen width()-150, screen height()-150
position camera 6,object position x(playerNum),object position y(playerNum)+RCamRange,object position z(playerNum)
point camera 6,object position x(playerNum),object position y(playerNum),object position z(playerNum)
if keystate(88)=1
screenshot = 0
repeat
INC screenshot
until FILE EXIST("Screenshots/Screenshot-" + STR$(screenshot) + ".png") <> 1
img=find free image (100000,190000)
GET IMAGE img, 0, 0, SCREEN WIDTH(), SCREEN HEIGHT(), 3
SAVE IMAGE "Screenshots/Screenshot-" + STR$(screenshot) + ".png", img
DELETE IMAGE img
endif
HandleControls()
if net connected()
HandleNetwork()
else
CenterBox(screen width()/2, screen height()/2, 200, 26, "Connection to server lost.")
endif
HandleMovement()
//AIGoto()
//Phy Update
sync
loop
UpDate_Bloom:
position camera bloom_cam,camera position x(),camera position y(),camera position z()
rotate camera bloom_cam,camera angle x(),camera angle y(),camera angle z()
dis#=(sh#/2.0)/tan(fov/2.0)
position object bloom_obj+2,camera position x(),camera position y(),camera position z()
rotate object bloom_obj+2,camera angle x(),camera angle y(),camera angle z()
move object bloom_obj+2,dis#/400
move object up bloom_obj+2,0.01
move object left bloom_obj+2,0.01
scale object bloom_obj+2,101,101,0
return
SetUp_Bloom:
fov=60
sw#=screen width()
sh#=screen height()
dis#=(sh#/2)/tan(fov/2)
brightness#=0.25
blurWidth#=0.012
bloom_cam=3
bloom_img=50
bloom_obj=50
make camera bloom_cam
set camera to image bloom_cam,bloom_img,256,256
set camera range bloom_cam,3,5280000
set camera fov bloom_cam,fov
color backdrop bloom_cam,0
make object plain bloom_obj,sw#/100,sh#/100
load effect "FX/Bloom.fx",bloom_obj,0
texture object bloom_obj,0,bloom_img
set object effect bloom_obj,bloom_obj
position object bloom_obj,0,-10000,dis#/100
make camera bloom_cam+1
set camera to image bloom_cam+1,bloom_img+1,256,256
set camera range bloom_cam+1,0.1,5280000
set camera fov bloom_cam+1,fov
position camera bloom_cam+1,0,-10000,0
make object plain bloom_obj+1,sw#/100,sh#/100
load effect "FX/Bloom.fx",bloom_obj+1,0
texture object bloom_obj+1,bloom_img+1
set object effect bloom_obj+1,bloom_obj+1
position object bloom_obj+1,500,-10000,dis#/100
make camera bloom_cam+2
set camera to image bloom_cam+2,bloom_img+2,256,256
set camera range bloom_cam+2,0.1,5280000
set camera fov bloom_cam+2,fov
position camera bloom_cam+2,500,-10000,0
make object plain bloom_obj+2,-sw#/(400),sh#/(400)
load effect "FX/Bloom.fx",bloom_obj+2,0
texture object bloom_obj+2,0,bloom_img+2
set object effect bloom_obj+2,bloom_obj+2
ghost object on bloom_obj+2
set effect technique bloom_obj,"Tone"
set effect technique bloom_obj+1,"blurpassX"
set effect technique bloom_obj+2,"blurpassY"
set effect constant float bloom_obj+1,"Brightness",brightness#
set effect constant float bloom_obj+1,"blurWidth",blurWidth#
set effect constant float bloom_obj+2,"Brightness",brightness#
set effect constant float bloom_obj+2,"blurWidth",blurWidth#
return
function CameraFollowObject(Camera,Object,FollowX#,FollowY#,FollowZ#,XAng#,Yang#,ZAng#)
xpos#=object position x(Object)+(FollowZ#*cos(object angle x(Object))+FollowY#*sin(object angle x(Object)))*sin(object angle y(Object))+FollowX#*cos(object angle y(Object))
ypos#=object position y(Object)-FollowZ#*sin(object angle x(Object))+FollowY#*cos(object angle x(Object))
zpos#=object position z(Object)+(FollowZ#*cos(object angle x(Object))+FollowY#*sin(object angle x(Object)))*cos(object angle y(Object))-FollowX#*sin(object angle y(Object))
position camera Camera,xpos#,ypos#,zpos#
set camera to object orientation Camera,Object
pitch camera down Camera,XAng#
turn camera right Camera,YAng#
roll camera left Camera,ZAng#
endfunction
function third_person_camera(obj#,cam#,dist#,height#)
rem this sets camera's x angle back to 0
pitch camera up height#
rem positions camera in object position
position camera cam#,object position x(obj#),object position y(obj#),object position z(obj#)
rem rotate camera to object angles
set camera to object orientation cam#,obj#
rem tilt camera
pitch camera down height#
rem move camera at a distance away
move camera -dist#
endfunction
function xMultiplier(x,basex)
xMulti = x / basex
endfunction xMulti
function yMultiplier(y,basey)
yMulti = y / basey
endfunction yMulti
remstart
draw_starfield:
base=600000
spread=1000
stars=1000
dist=-50
cx#=camera position x()
cy#=camera position y()
cz#=camera position z()
pick screen screen width()/2,screen height()/2,dist
sx#=get pick vector x()
sy#=get pick vector y()
sz#=get pick vector z()
if object exist(600000)=0
make object plane 600000,1,1
for i=600001 to 600000+stars
clone object i,600000
set object light i,0
set object collision off i
position object i,rnd(spread*2)-spread,rnd(spread*2)-spread,camera position z()+rnd(dist)
next i
endif
for i=600000 to 600000+stars
if object in screen(i)=0
position object i,cx#+sx#+(rnd(spread)-(spread/2)),cy#+sy#+(rnd(spread)-(spread/2)),cz#+sz#+(rnd(spread*2)-(spread/2))
endif
dist#=distance(cx#,cy#,cz#,i)
scale object i,.1*(dist#*2),.1*(dist#*2),2000*speed#
set object to object orientation i,1
move object i,speed#*-1.2
next i
return
remend
function distance(x1#,y1#,z1#,obj)
x2#=object position x(obj)
y2#=object position y(obj)
z2#=object position z(obj)
dist#=sqrt((x1#-x2#)*(x1#-x2#)+(y1#-y2#)*(y1#-y2#)+(z1#-z2#)*(z1#-z2#))
endfunction dist#
function dist2object(obj1,obj2)
x2#=object position x(obj2)
y2#=object position y(obj2)
z2#=object position z(obj2)
x1#=object position x(obj1)
y1#=object position y(obj1)
z1#=object position z(obj1)
dist2object#=sqrt((x1#-x2#)*(x1#-x2#)+(y1#-y2#)*(y1#-y2#)+(z1#-z2#)*(z1#-z2#))
endfunction dist2object#
function camera_follow(cam as integer,object as integer,maxdist# as float,smoothing as integer)
camx#=camera position x(cam)
camy#=camera position y(cam)
camz#=camera position z(cam)
objx#=object position x(object)
objy#=object position y(object)
objz#=object position z(object)
dist#=abs(sqrt(((camx#-objx#)^2)+((camy#-objy#)^2)+((camz#-objz#)^2)))
goalx#=(objx#+(sin(atanfull((camx#-objx#),(camz#-objz#)))*maxdist#))
goalz#=(objz#+(cos(atanfull((camx#-objx#),(camz#-objz#)))*maxdist#))
if dist#>maxdist#
camx#=curvevalue(goalx#,camx#,smoothing)
camz#=curvevalue(goalz#,camz#,smoothing)
endif
camy#=curvevalue(objy#+((object size y(object)/5)*6),camy#,smoothing)
point camera cam,objx#,objy#,objz#
position camera cam,camx#,camy#,camz#
endfunction
remstart
function HandleInput()
newData$ = entry$()
if newData$ <> ""
CURRENT_TEXT_ENTRY = CURRENT_TEXT_ENTRY + newData$
clear entry buffer
lenHigh = len(CURRENT_TEXT_ENTRY)
lenLow = lenHigh - len(newData$)
for x = lenHigh to lenLow step -1
char = asc(mid$(CURRENT_TEXT_ENTRY, x))
if char = 8
CURRENT_TEXT_ENTRY = left$(CURRENT_TEXT_ENTRY, x-2) + right$(CURRENT_TEXT_ENTRY, len(CURRENT_TEXT_ENTRY)-x)
else
if char < 32
CURRENT_TEXT_ENTRY = left$(CURRENT_TEXT_ENTRY, x-1) + right$(CURRENT_TEXT_ENTRY, len(CURRENT_TEXT_ENTRY)-x)
endif
endif
next x
DrawEntry()
endif
if returnkey()
if not KEYDOWN_RETURN
if CURRENT_TEXT_ENTRY <> ""
net put byte MESSAGE_ID_CHAT
net put string CURRENT_TEXT_ENTRY
net send
CURRENT_TEXT_ENTRY = ""
DrawEntry()
endif
KEYDOWN_RETURN = 1
endif
else
if KEYDOWN_RETURN
KEYDOWN_RETURN = 0
endif
endif
endfunction
remend
function XCenterPoint(x1#,x2#)
X3# =((X1# + X2#)/2)
endfunction X3#
function yCenterPoint(y1#,y2#)
Y3# =((Y1# + Y2#)/2)
endfunction Y3#
function zCenterPoint(Z1#,Z2#)
Z3# =((Z1# + Z2#)/2)
endfunction Z3#
//All your chat functions.
function Chat()
ChatKeys()
endfunction
Function ChatGUI()
ChatWindowGUI(10,screen height()-200,400,150)
Endfunction
function ChatWindowGUI(PosX as Integer,PosY as Integer,SizeX as Integer,SizeY as Integer)
text PosX,PosY-15,"General Chat"
//if Chat is opened
if ChatInUse =2
box PosX,PosY,PosX+SizeX,PosY+SizeY,rgb(0,0,0),rgb(50,50,50),rgb(0,0,0),rgb(50,50,50)
box PosX,PosY+SizeY,PosX+SizeX,PosY+SizeY+20,rgb(50,50,50),rgb(50,50,50),rgb(50,50,50),rgb(50,50,50)
line PosX,PosY+SizeY,PosX,PosY+SizeY+20
line PosX+SizeX,PosY+SizeY,PosX+SizeX,PosY+SizeY+20
line PosX,PosY+SizeY+20,PosX+SizeX,PosY+SizeY+20
ChatInput(PosX+4,PosY+SizeY)
endif
if ChatInUse = 3
ChatSubmitMsg(LastChatMsg)
Net Put Byte 5
Net Put String player(x).name+LastChatMsg
LastChatMsg = player(x).name+": "
net send
endif
line PosX,PosY,PosX+SizeX,PosY
line PosX,PosY,PosX,PosY+SizeY
line PosX+SizeX,PosY,PosX+SizeX,PosY+SizeY
Line PosX,PosY+SizeY,PosX+SizeX,PosY+SizeY
ChatDisplayHistoryText(PosX+3,PosY+SizeY)
endfunction
function ChatKeys()
if EnterKey = 3 then EnterKey = 0
if EnterKey = 2 and returnkey()=0 then EnterKey = 3
if EnterKey = 1 then EnterKey = 2
if EnterKey = 0 and returnkey()=1 then EnterKey = 1
if ChatInuse = 1 and EnterKey > 1 then ChatInuse = 2
if EnterKey = 1 and ChatInUse = 0 then ChatInuse = 1
if ChatInUse = 3 then ChatInuse = 0
if EnterKey = 1 and ChatInuse = 2 then ChatInuse = 3
endfunction
function ChatInput(PosX as Integer,PosY as Integer)
ChatKey = entry$(0)
if ChatInputTimer < timer()
ChatInputTimer = timer()+100
if len(ChatInputStr)>0 then ChatInputStr = "" else ChatInputStr = "|"
endif
if returnkey()=0 and len(ChatKey) >0 and keystate(14)=0
LastChatMsg = LastChatMsg + ChatKey
clear entry buffer
endif
//Backspacing..
if len(ChatKey)>0 and keystate(14)=1
lastChatMsg = left$(LastChatMsg,len(LastChatMsg)-1)
clear entry buffer
endif
text PosX,PosY,player(x).name+": "+LastChatMsg+ChatInputStr
endfunction
function ChatSubmitMsg(Txt as String)
//Move all chat array 1 index forward..
a as integer
dim ChatArray(array count(ChatArray(0))+1) as String
for a = Array count(ChatArray(0))-1 to 1 step -1
ChatArray(a) = ChatArray(a-1)
next a
ChatArray(0) = txt
endfunction
function ChatDisplayHistoryText(PosX as Integer,PosY as Integer)
for a=0 to 10
if a <= Array count(ChatArray(0))-1 then text PosX,PosY-(15*a)-15,ChatArray(a)
next a
endfunction
Function Update0030Loop()
set effect technique 1,"Black"
sync mask 2^1
sync
set effect technique 1,"Cubemap"
sync mask 2^0
`sync
endfunction
Function Update0030BeforeLoop()
load effect "FX/EnvironmentBump.fx",1,0
load image "Media/Floor.dds",1
load image "Media/Floor_n.dds",2
load image "Media/Cube0.dds",3,2
make camera 1
set camera to image 1,5,512,512
set camera fov 1,45
backdrop on 1
color backdrop 1,rgb(0,0,0)
load effect "FX/Light Scattering.fx",3,0
make object plain 5,2,2,1
texture object 5,5
set object effect 5,3
set object mask 5,2^0
endfunction
remstart
draw_asteroids:
Ast_base=880000
asteroids=AstAmount
Ast_spread=2
Ast_dist=1500
cx#=camera position x()
cy#=camera position y()
cz#=camera position z()
pick screen screen width()/2,screen height()/2,Ast_dist
sx#=get pick vector x()
sy#=get pick vector y()
sz#=get pick vector z()
CPX = Camera Position X()
CPY = Camera Position Y()
CPZ = Camera Position Z()
if object exist(880000)=0
load object "Media/AST_03.X",880000
`load image "Media/AST5.BMP",880000
`texture object 880000,880000
set object light 880000,0
if FILE EXIST("Asteroid-Collider.bc2")=0
phy make rigid body dynamic mesh 880000,"Asteroid-Collider.bc2"
print "Creating Asteroid Physics File..."
endif
hide object 880000
for i=880001 to 880000+asteroids
clone object i,880000,1
position object i,Ast_spread+rnd(Ast_spread*1000),Ast_spread+rnd(Ast_spread*1000),Ast_spread+rnd(Ast_spread*1000)
ROTATE OBJECT i, object angle x(i)+rnd(asteroids*2), object angle y(i)+rnd(asteroids*2),object angle z(i)+rnd(asteroids*2)
phy load rigid body dynamic mesh i,"Asteroid-Collider.bc2"
set object collision on i
set object cull i,1
set object light i,1
set object effect i,125
`texture object i,880000
scale object i,rnd(object scale x(880000)),rnd(object scale y(880000)),rnd(object scale z(880000))
next i
for i=880000 to 880000+asteroids
if object in screen(i)=0
position object i,cx#+sx#+(rnd(Ast_spread)-(Ast_spread/2)),cy#+sy#+(rnd(Ast_spread)-(Ast_spread/2)),cz#+sz#+(rnd(Ast_spread*2)-(Ast_spread/2))
endif
next i
Return
endif
remend
//Function AIGoto()
//move object 125000,.5
//point object 125000,object position x(playerNum),object position y(playerNum),object position z(playerNum)
//Endfunction
`draw_planets:
Function CreatePlanet(PL_Scale,XPPos#,YPPos#,ZPPos#)
PL_base=find free object(32500,80000)
PL_Scale=140+rnd(3200)
Planets=PlanetAmount
make object sphere PL_Base,PL_Scale,40,40
//phy make rigid body static sphere PL_Base
position object PL_Base,XPPos#,YPPos#,ZPPos#
if object size(PL_Base)>3100 `Suns
texture object PL_Base,32502 `sun
endif
if object size(PL_Base)>2900 `Large Gas Giants
texture object PL_Base,32505 `gas
endif
if object size(PL_Base)>2500 `Medium Gas Giants
texture object PL_Base,32505 `gas
endif
if object size(PL_Base)>1900 `Small Gas Giants
texture object PL_Base,32505 `gas
endif
if object size(PL_Base)>1500 `Large Planets
texture object PL_Base,32500 `hab
endif
if object size(PL_Base)>1000 `Large Habitable
texture object PL_Base,32500 `hab
endif
if object size(PL_Base)>600 `Habitable
texture object PL_Base,32501 `hab
endif
if object size(PL_Base)>390 `Dwarf, Smaller Planet
texture object PL_Base,32501 `hab
Endif
if object size(PL_Base)>140 `Moon
texture object PL_Base,32501 `hab
Endif
EndFunction
Function Create_Klingon_Neghvar()
KShipNum=find free object (99999,130000)
load object "Media/Klingon_Neghvar.x",KShipNum,5
scale object KShipNum,25,25,25
`SET SHADOW SHADING ON KShipNum
Position Object KShipNum, camera position x(),camera position y(),camera position z()
set object cull KShipNum,1
texture object KShipNum,0,5051
texture object KShipNum,1,5050
set blend mapping on KShipNum,1,5050,3,7
Endfunction
Function Create_Cardassian_Galor()
CShipNum=find free object (89999,130000)
load object "Media/Cardassian_Galor.x",CShipNum,5
scale object CShipNum,30,30,30
`SET SHADOW SHADING ON CShipNum
Position Object CShipNum, camera position x(),camera position y(),camera position z()
set object cull CShipNum,1
texture object CShipNum,0,5020
texture object CShipNum,1,5021
set blend mapping on CShipNum,1,5021,3,7
Endfunction
Function Create_Borg_Cube()
BShipNum=find free object (79999,130000)
load object "Media/CapitalCarrier_BorgFCCube.dbo",BShipNum,5
scale object BShipNum,20,20,20
`SET SHADOW SHADING ON CShipNum
Position Object BShipNum, camera position x(),camera position y(),camera position z()
set object cull BShipNum,1
texture object BShipNum,0,6070
texture object BShipNum,1,6060
set blend mapping on BShipNum,1,6060,3,7
Endfunction
Function Create_Federation_Galaxy()
FShipNum=find free object (79999,130000)
load object "Media/Fed_Galaxy.dbo",FShipNum,5
yrotate object FShipNum,180
xrotate object FShipNum,90
fix object pivot FShipNum
scale object FShipNum,20,20,20
`SET SHADOW SHADING ON CShipNum
Position Object FShipNum, camera position x(),camera position y(),camera position z()
set object cull FShipNum,1
texture object FShipNum,0,7070
texture object FShipNum,1,7060
set blend mapping on FShipNum,1,7060,3,7
Endfunction
Function LoadTextures()
KNLM = find free image (5050,5550)
KNCM = find free image (5051,5550)
CNLM = find free image (5020,5520)
CNCM = find free image (5021,5520)
load image "Media/21.png",32500 `hab
load image "Media/26.png",32501 `hab
load image "Media/51.png",32502 `sun
load image "Media/52(2).png",32503 `sun
load image "Media/44.png",32504 `sun
load image "Media/gas1.png",32505 `gas
load image "Media/KN_Glow.png",5050 `Klingon Glow
load image "Media/Klingon_NeghVar-cl.dds",5051 ` Klingon Texture
Load Image "Media/Borg_LM.png",6060
Load Image "Media/Borg-cl.dds",6070
Load Image "Media/Fed_GalaxyLM1.png",7060
Load Image "Media/Fed_Galaxy-cl.dds",7070
load image "Media/CG_LM.png",5021
load image "Media/Cardassian_Galor-cl.dds",5020
load image "Media/stars2.png",519
load image "Media/radarimg.png",6995
Endfunction
function HandleMovement()
for x = 1 to MAXIMUM_PLAYERS
if player(x).exist
rem real values are the actual current values
if player(x).key_up
player(x).realx = player(x).realx + sin(player(x).angle)
player(x).realz = player(x).realz + cos(player(x).angle)
endif
if player(x).key_down
player(x).realx = player(x).realx - sin(player(x).angle)
player(x).realz = player(x).realz - cos(player(x).angle)
endif
if player(x).key_left then player(x).angle = wrapvalue(player(x).angle-1)
if player(x).key_right then player(x).angle = wrapvalue(player(x).angle+1)
distx# = abs(player(x).realx-player(x).x)
speedx# = distx# / 10.0
distz# = abs(player(x).realz-player(x).z)
speedz# = distz# / 10.0
angle# = atanfull(player(x).realx-player(x).x, player(x).realz-player(x).z)
player(x).x = player(x).x + (sin(angle#)*speedx#)
player(x).z = player(x).z + (cos(angle#)*speedz#)
yrotate object x+10, player(x).angle
position object x+10, player(x).x, 0, player(x).z
center text object screen x(x+10), object screen y(x+10)-13, player(x).CLANTAG+player(x).name
endif
next x
endfunction
function HandleNetwork()
while net get message()
inc MSGSRECVD
select net get byte()
case MESSAGE_ID_GENERAL
playerNum = net get byte()
player(playerNum).realx = net get float()
player(playerNum).realz = net get float()
player(playerNum).angle = net get byte() * 1.411
ApplyFlags(playerNum, net get byte())
endcase
case MESSAGE_ID_GENERALFULL
while net get message remainder() > 0
playerNum = net get byte()
player(playerNum).exist = 1
player(playerNum).name = net get string()
player(playernum).CLANTAG = net get string()
player(playerNum).realx = net get float()
player(playerNum).realz = net get float()
player(playerNum).angle = net get byte() * 1.411
ApplyFlags(playerNum, net get byte())
load object "Media/Nova.x",playerNum+10
ApplyPosition(playerNum)
endwhile
endcase
case MESSAGE_ID_PLAYERJOINED
playerNum = net get byte()
player(playerNum).exist = 1
player(playerNum).name = net get string()
player(playernum).CLANTAG = net get string()
load object "Media/Nova.x",playerNum+10
endcase
case MESSAGE_ID_PLAYERQUIT:
ResetPlayer(net get byte())
endcase
endselect
endwhile
if toSend and LASTSENT+SENDGAP<timer()
net put byte MESSAGE_ID_GENERAL
net put float object position x(playerNum)
net put float object position z(playerNum)
net put byte (object angle y(playerNum) / 1.411)
flags = (upkey() || downkey() << 1 || leftkey() << 2 || rightkey() << 3)
net put byte flags
net send
toSend = 0
endif
endfunction
remstart
function HandleControls()
flags = 0
PhyMode = 4
if upkey() then phy add rigid body local force 10,0,0,.015,PhyMode : flags = flags || FLAG_UP
if downkey() then phy add rigid body local force 10,0,0,-.015,PhyMode : flags = flags || FLAG_DOWN
if leftkey() or keystate (30)=1 then phy add rigid body local torque 10, 0, -.0005, 0, PhyMode : flags = flags || FLAG_LEFT
if rightkey() or keystate (32)=1 then phy add rigid body local torque 10, 0, .0005, 0, PhyMode : flags = flags || FLAG_RIGHT
if keystate (16)=1 then phy add rigid body local torque 10, 0, 0, .0005, PhyMode : flags = flags || FLAG_ROLL_LEFT
if keystate (18)=1 then phy add rigid body local torque 10, 0, 0, -.0005, PhyMode : flags = flags || FLAG_ROLL_RIGHT
if keystate (17)=1 then phy add rigid body local torque 10, .0005, 0, 0, PhyMode : flags = flags || FLAG_PITCH_UP
if keystate (31)=1 then phy add rigid body local torque 10, -.0005, 0, 0, PhyMode : flags = flags || FLAG_PITCH_DOWN
phy set rigid body angular damping 10,.10
PhySpeed = phy get rigid body linear velocity z (10)
phy set rigid body max angular velocity 10,10
if spacekey()=1
phy set rigid body linear velocity 10,0,0,0
Endif
Text 5,175, "Speed: "+str$(PhySpeed)
if flags <> lastFlags
toSend = 1
lastFlags = flags
LASTSENT = timer()
endif
endfunction
remend
function HandleControls()
flags = 0
if upkey() then move object playerNum, 1 : flags = flags || FLAG_UP
if downkey() then move object playerNum, -1 : flags = flags || FLAG_DOWN
if leftkey() then yrotate object playerNum, wrapvalue(object angle y(playerNum)-1) : flags = flags || FLAG_LEFT
if rightkey() then yrotate object playerNum, wrapvalue(object angle y(playerNum)+1) : flags = flags || FLAG_RIGHT
if flags <> lastFlags
toSend = 1
lastFlags = flags
LASTSENT = timer()
endif
endfunction
function HandleCamera()
xPos# = object position x(playerNum) + cos(270-object angle y(playerNum)) * 50
zPos# = object position z(playerNum) + sin(270-object angle y(playerNum)) * 500
`position camera xPos#, 90, zPos#
`point camera object position x(1), 40, object position z(1)
set camera to follow object position x(playerNum), object position y(playerNum), object position z(playerNum), 25, object scale z(playerNum), 10, 1, 1
endfunction
function ResetPlayer(playerNum as integer)
if object exist(playerNum+10) then delete object playerNum+10
player(playerNum).exist = 0
player(playerNum).name = ": "
player(playernum).CLANTAG = ": "
player(playerNum).x = 0
player(playerNum).z = 0
player(playerNum).angle = 0
player(playerNum).key_up = 0
player(playerNum).key_down = 0
player(playerNum).key_left = 0
player(playerNum).key_right = 0
endfunction
function ApplyFlags(playerNum as integer, flags as integer)
if flags && FLAG_UP
player(playerNum).key_up = 1
else
player(playerNum).key_up = 0
endif
if flags && FLAG_DOWN
player(playerNum).key_down = 1
else
player(playerNum).key_down = 0
endif
if flags && FLAG_LEFT
player(playerNum).key_left = 1
else
player(playerNum).key_left = 0
endif
if flags && FLAG_RIGHT
player(playerNum).key_right = 1
else
player(playerNum).key_right = 0
endif
endfunction
function ApplyPosition(playerNum as integer)
position object playerNum+10, player(playerNum).x, 0, player(playerNum).z
yrotate object playerNum+10, player(playerNum).angle
endfunction
function CenterBox(x as integer, y as integer, xSize as integer, ySize as integer, textString as string)
xPos = x-(xSize/2)
yPos = y-(ySize/2)
ink rgb(32,32,200),0
box xPos, yPos, xPos+xSize, yPos+ySize
ink rgb(255,255,255),0
center text x, y-(text height("A")/2), textString
endfunction
Demo Code
` Constants -------------------------------------
#constant SENDGAP 0
#constant MAXIMUM_PLAYERS 10
#constant MESSAGE_ID_NAME 0
#constant MESSAGE_ID_GENERAL 1 : ` Contains just player data
#constant MESSAGE_ID_GENERALFULL 2 : ` Contains player numbers and player data
#constant MESSAGE_ID_PLAYERJOINED 3
#constant MESSAGE_ID_PLAYERQUIT 4
#constant FLAG_UP 1
#constant FLAG_DOWN 2
#constant FLAG_LEFT 4
#constant FLAG_RIGHT 8
` -----------------------------------------------
` Types ------------------------------------------
type player_data
exist as boolean
name as string
x as float
z as float
realx as float
realz as float
angle as float
key_up as boolean
key_down as boolean
key_left as boolean
key_right as boolean
endtype
` ------------------------------------------------
` Variables --------------------------------------
global LASTSENT as integer
global NAME as string
global dim player(MAXIMUM_PLAYERS) as player_data
global lastFlags as byte
global toSend
` ------------------------------------------------
sync off
autocam off
input "IP: ", ip$
result = net connect(ip$)
if not result
print "Could not connect: "+chr$(34)+net get error()+chr$(34)+"."
print "Press any key to exit."
wait key
end
endif
input "Name: ", NAME
net put byte MESSAGE_ID_NAME
net put string NAME
net send
make matrix 1, 1000, 1000, 10, 10
make object cube 1, 10
make object cube 40, 10
ghost object on 40
hide object 40
sync on
sync rate 60
do
text 0, 0, str$(screen fps())
HandleControls()
HandleCamera()
if net connected()
HandleNetwork()
else
CenterBox(screen width()/2, screen height()/2, 200, 26, "WE'VE LOST THE SERVER!")
endif
HandleMovement()
sync
loop
function HandleMovement()
for x = 1 to MAXIMUM_PLAYERS
if player(x).exist
rem real values are the actual current values
if player(x).key_up
player(x).realx = player(x).realx + sin(player(x).angle)
player(x).realz = player(x).realz + cos(player(x).angle)
endif
if player(x).key_down
player(x).realx = player(x).realx - sin(player(x).angle)
player(x).realz = player(x).realz - cos(player(x).angle)
endif
if player(x).key_left then player(x).angle = wrapvalue(player(x).angle-1)
if player(x).key_right then player(x).angle = wrapvalue(player(x).angle+1)
distx# = abs(player(x).realx-player(x).x)
speedx# = distx# / 10.0
distz# = abs(player(x).realz-player(x).z)
speedz# = distz# / 10.0
angle# = atanfull(player(x).realx-player(x).x, player(x).realz-player(x).z)
player(x).x = player(x).x + (sin(angle#)*speedx#)
player(x).z = player(x).z + (cos(angle#)*speedz#)
yrotate object x+10, player(x).angle
position object x+10, player(x).x, 0, player(x).z
center text object screen x(x+10), object screen y(x+10)-13, player(x).name
endif
next x
endfunction
function HandleNetwork()
while net get message()
inc MSGSRECVD
select net get byte()
case MESSAGE_ID_GENERAL
playerNum = net get byte()
player(playerNum).realx = net get float()
player(playerNum).realz = net get float()
player(playerNum).angle = net get byte() * 1.411
ApplyFlags(playerNum, net get byte())
endcase
case MESSAGE_ID_GENERALFULL
while net get message remainder() > 0
playerNum = net get byte()
player(playerNum).exist = 1
player(playerNum).name = net get string()
player(playerNum).realx = net get float()
player(playerNum).realz = net get float()
player(playerNum).angle = net get byte() * 1.411
ApplyFlags(playerNum, net get byte())
make object cube playerNum+10, 10
ApplyPosition(playerNum)
endwhile
endcase
case MESSAGE_ID_PLAYERJOINED
playerNum = net get byte()
player(playerNum).exist = 1
player(playerNum).name = net get string()
make object cube playerNum+10, 10
endcase
case MESSAGE_ID_PLAYERQUIT:
ResetPlayer(net get byte())
endcase
endselect
endwhile
if toSend and LASTSENT+SENDGAP<timer()
net put byte MESSAGE_ID_GENERAL
net put float object position x(1)
net put float object position z(1)
net put byte (object angle y(1) / 1.411)
flags = (upkey() || downkey() << 1 || leftkey() << 2 || rightkey() << 3)
net put byte flags
net send
toSend = 0
endif
endfunction
function HandleControls()
flags = 0
if upkey() then move object 1, 1 : flags = flags || FLAG_UP
if downkey() then move object 1, -1 : flags = flags || FLAG_DOWN
if leftkey() then yrotate object 1, wrapvalue(object angle y(1)-1) : flags = flags || FLAG_LEFT
if rightkey() then yrotate object 1, wrapvalue(object angle y(1)+1) : flags = flags || FLAG_RIGHT
if flags <> lastFlags
toSend = 1
lastFlags = flags
LASTSENT = timer()
endif
endfunction
function HandleCamera()
xPos# = object position x(1) + cos(270-object angle y(1)) * 50
zPos# = object position z(1) + sin(270-object angle y(1)) * 50
position camera xPos#, 40, zPos#
point camera object position x(1), 20, object position z(1)
endfunction
function ResetPlayer(playerNum as integer)
if object exist(playerNum+10) then delete object playerNum+10
player(playerNum).exist = 0
player(playerNum).name = ""
player(playerNum).x = 0
player(playerNum).z = 0
player(playerNum).angle = 0
player(playerNum).key_up = 0
player(playerNum).key_down = 0
player(playerNum).key_left = 0
player(playerNum).key_right = 0
endfunction
function ApplyFlags(playerNum as integer, flags as integer)
if flags && FLAG_UP
player(playerNum).key_up = 1
else
player(playerNum).key_up = 0
endif
if flags && FLAG_DOWN
player(playerNum).key_down = 1
else
player(playerNum).key_down = 0
endif
if flags && FLAG_LEFT
player(playerNum).key_left = 1
else
player(playerNum).key_left = 0
endif
if flags && FLAG_RIGHT
player(playerNum).key_right = 1
else
player(playerNum).key_right = 0
endif
endfunction
function ApplyPosition(playerNum as integer)
position object playerNum+10, player(playerNum).x, 0, player(playerNum).z
yrotate object playerNum+10, player(playerNum).angle
endfunction
function CenterBox(x as integer, y as integer, xSize as integer, ySize as integer, textString as string)
xPos = x-(xSize/2)
yPos = y-(ySize/2)
ink rgb(200, 200, 200), 0
box xPos, yPos, xPos+xSize, yPos+ySize
ink rgb(255, 255, 255), 0
center text x, y-(text height("A")/2), textString
endfunction