本文整理汇总了C#中NetworkPlayer.SetTeam方法的典型用法代码示例。如果您正苦于以下问题:C# NetworkPlayer.SetTeam方法的具体用法?C# NetworkPlayer.SetTeam怎么用?C# NetworkPlayer.SetTeam使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类NetworkPlayer
的用法示例。
在下文中一共展示了NetworkPlayer.SetTeam方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Main
static void Main(string[] args)
{
int loopStartTime = 0;
int loopEndTime = 0;
float deltaSecond = 0;
//Frequency to return data
const float ReturnDataPerSecond = 20;
float lastSentData = 0;
//Team containers
ShapeTeamContainer greenTeam = new ShapeTeamContainer(ShapeTeam.GREEN);
ShapeTeamContainer redTeam = new ShapeTeamContainer(ShapeTeam.RED);
NetPeerConfiguration config = new NetPeerConfiguration("ShapeSpace");
config.Port = 55678;
config.MaximumConnections = maxPlayers;
config.ConnectionTimeout = 10;
config.EnableMessageType(NetIncomingMessageType.DiscoveryRequest);
config.EnableMessageType(NetIncomingMessageType.ConnectionApproval);
server = new NetServer(config);
//Console.WriteLine(server.Configuration.LocalAddress);
physicsWorld = new World(Vector2.Zero);
//50px = 1m
ConvertUnits.SetDisplayUnitToSimUnitRatio(50f);
try
{
server.Start();
}
catch(Exception e)
{
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine(e);
Console.ForegroundColor = ConsoleColor.White;
WaitForKeyPress();
}
Console.WriteLine("Server Started Sucessfully!");
//Main program loop
while(true)
{
deltaSecond = (loopEndTime - loopStartTime) / 1000f;
lastSentData += deltaSecond;
loopStartTime = Environment.TickCount;
//Handle incoming messages
NetIncomingMessage msg;
while ((msg = server.ReadMessage()) != null)
{
//Console.WriteLine(msg.MessageType);
switch (msg.MessageType)
{
case NetIncomingMessageType.Data:
//A swith handling ShapeSpace custom message types
switch((ShapeCustomNetMessageType)msg.ReadByte())
{
case ShapeCustomNetMessageType.InputUpdate:
int playerIndex = msg.ReadInt32();
float timeSinceLast = msg.ReadFloat();
Vector2 input = msg.ReadVector2();
connectedPlayers[playerIndex].inputs.Add(new InputWithTime(timeSinceLast,input));
//Console.WriteLine(timeSinceLast + ": " + input.ToString());
break;
case ShapeCustomNetMessageType.SetupRequest:
NetOutgoingMessage returnMessage = server.CreateMessage();
NetworkPlayer newPlayer = new NetworkPlayer(physicsWorld, msg.SenderConnection, new Vector2(0,0));
//ShapeTeam team = (ShapeTeam)msg.ReadByte();
string username = msg.ReadString();
try
{
//newPlayer.SetTeam(team);
newPlayer.SetUserName(username);
int spot = AddNewPlayer(newPlayer);
newPlayer.indexOnServer = spot;
//Assign the new player to the team with the least amount of players
ShapeTeamContainer newPlayerTeam = greenTeam.GetNumberOfMembers() < redTeam.GetNumberOfMembers() ? greenTeam : redTeam;
bool isBank = newPlayerTeam.AddPlayer(newPlayer.indexOnServer);
newPlayer.SetTeam(newPlayerTeam.GetTeam());
newPlayer.body.Position = ConvertUnits.ToSimUnits(newPlayerTeam.basePosition);
if (isBank)
newPlayer.SetClass(new ShapeClassBank());
else
newPlayer.SetClass(new ShapeClassKnocker());
newPlayer.OnCreateRemnant += CreateRemnant;
//.........这里部分代码省略.........