using System; using System.Collections.Generic; using System.Linq; using System.Threading; using EEPhysics; using PlayerIOClient; namespace EEPhysicsDemo { // IF YOU DO NOT HAVE A C# 6 COMPILER USE: /* public class Player { public PhysicsPlayer Physics { get { return Program.PhysicsWorld.Players[Id]; } } public string Name { get; } public int Id { get; } public double X { get { return Physics.X; } } public double Y { get { return Physics.Y; } } public int x { get { return (int)Math.Round(X / 16); } } public int y { get { return (int)Math.Round(X / 16); } } public int Coins { get { return Physics.Coins; } } public bool GodMode { get { return Physics.InGodMode; } } public int BlueCoins { get { return Physics.BlueCoins; } } public Player(int id, string name) { Id = id; Name = name; } }*/ public class Player { public PhysicsPlayer Physics => Program.PhysicsWorld.Players[Id]; public string Name { get; } public int Id { get; } public double X => Physics.X; public double Y => Physics.Y; public int x => (int)Math.Round(X / 16); // Exact y value public int y => (int)Math.Round(X / 16); // Exact x value public int Coins => Physics.Coins; // Grab value of coins the player has public bool GodMode => Physics.InGodMode; // Tells if user is in GodMode public int BlueCoins => Physics.BlueCoins; public Player(int id, string name) { Id = id; Name = name; } } public class Program { public static Client Client; public static Connection Conn; public static PhysicsWorld PhysicsWorld = new PhysicsWorld(); public static Dictionary Players = new Dictionary(); public static int BotId; public static bool Finished; static void Main(string[] args) { Client = PlayerIO.QuickConnect.SimpleConnect("everybody-edits-su9rn58o40itdbnw69plyw", "guest", "guest", null); Conn = Client.Multiplayer.JoinRoom("Your World ID", null); //Make sure you give the guest edit! Conn.OnMessage += OnMessage; Conn.Send("init"); while (!Finished) Thread.Sleep(1); #region Example code // Will track random player's x and y with background blocks and detect when it hits to dots. Thread.Sleep(2500); // Wait a bit for add messages. int randomId; int[] ids = Players.Keys.ToArray(); // prefer other players than the bot itself if (ids.Length > 1) { int r = new Random().Next(Players.Keys.Count - 1); randomId = ids[r]; if (ids[r] == BotId) randomId = ids[r + 1]; } else randomId = ids[0]; if (randomId != BotId) Console.WriteLine("Tracking " + Players[randomId].Name); else Console.WriteLine("Tracking the bot itself"); Players[randomId].Physics.AddBlockEvent(4, delegate (PlayerEventArgs e) { Console.WriteLine("# " + e.Player.Name + " hit blockID 4 (gravity dot) at [" + e.BlockX + ", " + e.BlockY + "]!"); }); while (Players.ContainsKey(randomId)) { var player = Players[randomId]; Conn.Send("b", 1, player.x, player.y, 505); Thread.Sleep(14); } #endregion } public static void OnMessage(object o, Message m) { PhysicsWorld.HandleMessage(m); if (m.Type == "init") { var bot = new Player(m.GetInt(5), m.GetString(13)); Players.Add(bot.Id, bot); BotId = bot.Id; Conn.Send("init2"); Finished = true; } else if (m.Type == "add") { var p = new Player(m.GetInt(0), m.GetString(1)); Players.Add(p.Id, p); } else if (m.Type == "left") { if (Players.ContainsKey(m.GetInt(0))) { Players.Remove(m.GetInt(0)); } } } } }