Advertisement
cap9

EEPhysics

May 25th, 2014
165
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 4.05 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using PlayerIOClient;
  6. using System.Threading;
  7. using EEPhysics;
  8.  
  9. namespace !NAMESPACE_NAME!
  10. {
  11.     public class Player
  12.     {
  13.         public int ID { get; private set; }
  14.         public string Name { get; private set; }
  15.         public PhysicsPlayer Physics { get { return Program.physicsWorld.Players[ID]; } }
  16.  
  17.         public double X { get { return Physics.X; } }
  18.         public double Y { get { return Physics.Y; } }
  19.         public bool GodMode { get { return Physics.InGodMode; } }
  20.         public int Coins { get { return Physics.Coins; } }
  21.         public int BlueCoins { get { return Physics.BlueCoins; } }
  22.  
  23.         public Player(int id, string name)
  24.         {
  25.             ID = id;
  26.             Name = name;
  27.         }
  28.     }
  29.  
  30.     public class Program
  31.     {
  32.         public static Client client;
  33.         public static Connection conn;
  34.         public static PhysicsWorld physicsWorld = new PhysicsWorld();
  35.         public static Dictionary<int, Player> players = new Dictionary<int, Player>();
  36.  
  37.         public static int botID;
  38.         public static bool finished = false;
  39.  
  40.         static void Main(string[] args)
  41.         {
  42.             client = PlayerIO.QuickConnect.SimpleConnect("everybody-edits-su9rn58o40itdbnw69plyw", "email", "password");
  43.             conn = client.Multiplayer.JoinRoom("World ID", null);
  44.  
  45.             conn.OnMessage += onMessage;
  46.             conn.OnDisconnect += delegate(object o, string reason) { };
  47.  
  48.             conn.Send("init");
  49.  
  50.             while (!finished)
  51.                 Thread.Sleep(1);
  52.  
  53.             #region Example code
  54.             // Will track random player's x and y with background blocks and detect when it hits to dots.
  55.             Thread.Sleep(2500); // Wait a bit for add messages.
  56.  
  57.             int randomId;
  58.             int[] ids = players.Keys.ToArray();
  59.             // prefer other players than the bot itself
  60.             if (ids.Length > 1)
  61.             {
  62.                 int r = new Random().Next(players.Keys.Count - 1);
  63.                 randomId = ids[r];
  64.                 if (ids[r] == botID)
  65.                     randomId = ids[r + 1];
  66.             }
  67.             else
  68.                 randomId = ids[0];
  69.  
  70.             if (randomId != botID)
  71.                 Console.WriteLine("Tracking " + players[randomId].Name);
  72.             else
  73.                 Console.WriteLine("Tracking the bot itself");
  74.            
  75.  
  76.             players[randomId].Physics.AddBlockEvent(4, delegate(PlayerEventArgs e)
  77.             {
  78.                 Console.WriteLine("# " + e.Player.Name + " hit blockID 4 (gravity dot) at [" + e.BlockX + ", " + e.BlockY + "]!");
  79.             });
  80.  
  81.             while (players.ContainsKey(randomId))
  82.             {
  83.                 Player player = players[randomId];
  84.                 conn.Send(physicsWorld.WorldKey, 1, (int)Math.Round(player.X / 16), (int)Math.Round(player.Y / 16), 505);
  85.                 Thread.Sleep(35);
  86.             }
  87.             #endregion
  88.         }
  89.  
  90.         public static void onMessage(object o, Message m)
  91.         {
  92.             physicsWorld.HandleMessage(m);
  93.             switch (m.Type)
  94.             {
  95.                 case "init":
  96.                     {
  97.                         Player bot = new Player(m.GetInt(6), m.GetString(12));
  98.                         players.Add(bot.ID, bot);
  99.                         botID = bot.ID;
  100.                         conn.Send("init2");
  101.                         finished = true;
  102.                     }
  103.                     break;
  104.                 case "add":
  105.                     {
  106.                         Player p = new Player(m.GetInt(0), m.GetString(1));
  107.                         players.Add(p.ID, p);
  108.                     }
  109.                     break;
  110.                 case "left":
  111.                     {
  112.                         if (players.ContainsKey(m.GetInt(0)))
  113.                         {
  114.                             players.Remove(m.GetInt(0));
  115.                         }
  116.                     }
  117.                     break;
  118.             }
  119.         }
  120.     }
  121. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement