player.ConnectUserId);.Reborn();.Send("Create", player.ConnectUserId, player.GetPosX(), player.GetPosY(), player.GetRotate());;"Move":.SetPosX(message.GetFloat(1));.SetPosY(message.GetFloat(2));.SetRotate(message.GetFloat(3));(Player pl in players)
{(pl.ConnectUserId != player.ConnectUserId)
{.Send("Move", player.ConnectUserId, player.GetPosX(), player.GetPosY(), player.GetRotate());
}
};"Chat":(Player pl in players)
{(pl.ConnectUserId != player.ConnectUserId)
{.Send("Chat", player.ConnectUserId, message.GetString(0));
}
};"Attack":(Player pl in players)
{(pl.ConnectUserId != player.ConnectUserId)
{.Send("Attack", player.ConnectUserId, message.GetFloat(1), message.GetFloat(2));
}
}
break;
}
}
} Приложение 2 Листинг программного кода скрипта взаимодействия с сервером public class Clientside : MonoBehaviour {string name = "Test";GameObject[] playerPrefab = new GameObject[10];GameObject[] bullet = new GameObject[10];GameObject weapon;Canvas menu;float rot = 0f;Texture2D[] numeral = new Texture2D[10];GameObject player;Client client;Connection connection;List msgList = new List();Dictionary options = new Dictionary ();int teamId = 0;int ammo = 30;bool isReload = false;Start () {.Add ("maxplayers", "16");userId = Settings.email;.PlayerIO.Authenticate(
"shooter-gpmw9uiee0uxk34a7hzp7w",
"public",Dictionary{{"userId", userId}},,(Client client) {.Log ("Authenticate");.client = client;.Multiplayer.DevelopmentServer = new ServerEndpoint("localhost",8184);.Multiplayer.CreateJoinRoom(.roomId,
"GameRoom",,,,(Connection connection) {.connection = connection;.connection.OnMessage += handlemessage;.Send("Create", client.ConnectUserId);
},(PlayerIOError error) {.Log("Error Joining Room: " + error.ToString());
}
);
}
);
}void SendAttack(){(ammo > 1)
{(!isReload)
{-;.Send("Attack", player.name, player.transform.position.x, player.transform.position.y);
}
}
{.Reload();
}
}void Reload()
{= !isReload;
}handlemessage(object sender, PlayerIOClient.Message m) {.Add(m);
}FixedUpdate() {(player != null) {.Send("Move", player.name, player.transform.position.x, player.transform.position.y, player.transform.rotation.z);
}(PlayerIOClient.Message m in msgList) {(m.Type) {"PlayerJoined":.Log("It's not me");otherPlayer = GameObject.Instantiate(playerPrefab[teamId]) as GameObject;.transform.position = new Vector3(m.GetFloat(1), m.GetFloat(2), 0);.name = m.GetString(0);.GetComponent().enabled = false;.Log(otherPlayer.name);;"Create":(player == null) { .Log("It's me");= (GameObject)Instantiate(playerPrefab[teamId]);.transform.position = new Vector3(m.GetFloat(1), m.GetFloat(2), 0);.name = m.GetString(0);= m.GetInt(3);.GetComponent().enabled = true;.GetComponent().player = player;.Log(player.name);
};"Move":upplayer = GameObject.Find (m.GetString (0));.transform.position = new Vector3(m.GetFloat(1), m.GetFloat(2), 0);.transform.eulerAngles = new Vector3(0,0,m.GetFloat(3));;"Attack":othplayer = GameObject.Find (m.GetString (0));posX = othplayer.transform.position.x + (Mathf.Cos((othplayer.transform.localEulerAngles.z - 90) * Mathf.Deg2Rad)) * -player.GetComponent().shooting_speed;posY = othplayer.transform.position.y + (Mathf.Sin((othplayer.transform.localEulerAngles.z - 90) * Mathf.Deg2Rad)) * -player.GetComponent().shooting_speed;game_bullet = Instantiate(bullet[teamId], othplayer.transform.position, othplayer.transform.rotation) as GameObject;_bullet.GetComponent().master = othplayer;_bullet.GetComponent().AddForce(new Vector2(posX, posY));;"PlayerLeft":playerd = GameObject.Find(m.GetString(0));(playerd);;
}
}.Clear();(isReload) {(ammo < 30)++;(ammo == 30) {.reload();
}
}
}void OnGUI()
{mouse = Input.mousePosition;(ammo > 9)
{x = ammo % 10;y = (int)ammo / 10;.DrawTexture(new Rect(mouse.x + 18, -mouse.y + Screen.height - 8, 16, 16), numeral[y]);.DrawTexture(new Rect(mouse.x + 35, -mouse.y + Screen.height - 8, 16, 16), numeral[x]);
}{.DrawTexture(new Rect(mouse.x + 18, -mouse.y + Screen.height - 8, 16, 16), numeral[0]);.DrawTexture(new Rect(mouse.x + 35,-mouse.y + Screen.height - 8,16,16), numeral[ammo]);
}
}
}
Похожие работы
Тема: Реализация многопользовательской системы в Windows NT |
Предмет/Тип: Информатика, ВТ, телекоммуникации (Реферат) |
Тема: Реализация игровой модели "Кости" |
Предмет/Тип: Информационное обеспечение, программирование (Диплом) |
Тема: Реализация модели выбора состава PC |
Предмет/Тип: Отсутствует (Курсовая работа (т)) |
Тема: Разработка и реализация математической модели двухключевой криптосистемы |
Предмет/Тип: Информационное обеспечение, программирование (Диплом) |
Тема: Построение модели DFD и реализация в СУБД Visual FoxPro |
Предмет/Тип: Другое (Учебное пособие) |
Интересная статья: Основы написания курсовой работы