Exemplo n.º 1
0
        public MainMenu(RenderWindow window, ImageManager imageManager, Client client, Server server)
            : base(window, imageManager)
        {
            imageManager = new ImageManager();
            p = new Player(null, imageManager);
            mouse = new Sprite(imageManager.GetImage("mouse"));
            pImage = new RenderImage(window.Width, window.Height);
            pImage.DefaultView.Zoom(0.08F);
            pImage.DefaultView.Center = p.Center + new Vector2f(0, -30);
            pImage.SetView(pImage.DefaultView);

            this.window = window;
            this.client = client;
            this.server = server;
            items = new MenuItem[nbrItem];
            items[0] = new MenuItem("Local Game", new Vector2f(0, 100), StartLocal);
            items[1] = new MenuItem("Connect", new Vector2f(0, 130), Connect);
            items[2] = new MenuItem("Options", new Vector2f(0, 160), Option);
            items[3] = new MenuItem("Load map", new Vector2f(0, 190), LoadMap);
            items[4] = new MenuItem("Save map", new Vector2f(0, 220), SaveMap);
            items[5] = new MenuItem("Exit", new Vector2f(0, 280), Exit);

            foreach (MenuItem i in items)
                i.CenterX((int)window.Width);
        }
Exemplo n.º 2
0
        public void clientCorrection(Player p, UserMessage um)
        {
            while(um.Time > buffer[head].Time && head != tail){
                head = (head + 1) % capacity;
            }

            if(head != tail && um.Time.Equals(buffer[head].Time)){

                if(VectorUtils.Distance(buffer[head].Position, um.Position) > 1){

                    DateTime currentTime = um.Time;
                    Input currentInput = um.Input;
                    p.Position = um.Position;
                    p.FallSpeed = um.FallSpeed;

                    head = (head + 1) % capacity;
                    int index = head;

                    while(index != tail){
                        float deltaTime = (float) (buffer[index].Time - currentTime).TotalSeconds;

                        p.Update(deltaTime, currentInput);

                        currentTime = buffer[index].Time;
                        currentInput = buffer[index].Input;

                        buffer[index].Position = p.Position;
                        buffer[index].FallSpeed = p.FallSpeed;
                        index = (index + 1) % capacity;

                    }
                }
            }
        }
Exemplo n.º 3
0
        public void ReadIncomingMsg()
        {
            NetIncomingMessage msg;
            while ((msg = server.ReadMessage()) != null) {
                switch (msg.MessageType) {
                    case NetIncomingMessageType.VerboseDebugMessage:
                    case NetIncomingMessageType.DebugMessage:
                    case NetIncomingMessageType.WarningMessage:
                    case NetIncomingMessageType.ErrorMessage:
                        Console.WriteLine(msg.ReadString());
                        break;

                    case NetIncomingMessageType.StatusChanged:
                        NetConnectionStatus status = (NetConnectionStatus)msg.ReadByte();
                        if (status == NetConnectionStatus.Connected) {
                            int id = GetUniqueClientId();
                            NetworkClient newClient = new NetworkClient(id, msg.SenderConnection);
                            clientList.Add(msg.SenderConnection, newClient);
                            Console.WriteLine(newClient.Pseudo + " connected");

                            ClientInfo ci = new ClientInfo(id);
                            ci.Pseudo = newClient.Pseudo;
                            SendPkt(ci, msg.SenderConnection, true);

                            Player p = new Player(map, imageManager);
                            map.AddPlayer(p);
                            newClient.Player = p;
                            SendFullWorldUpdate(msg.SenderConnection);
                            SendFullClientInfo(msg.SenderConnection);

                        } else if (status == NetConnectionStatus.Disconnected) {
                            if (clientList.ContainsKey(msg.SenderConnection)) {
                                NetworkClient c = clientList[msg.SenderConnection];
                                clientList.Remove(c.Connection);
                                map.DeletePlayer(c.Player);
                                Console.WriteLine("Client " + c.Pseudo + " disconnected");

                                ClientDisconnect cd = new ClientDisconnect(c.ClientId);
                                SendPktToAll(cd, true);
                            }

                        }
                        break;

                    case NetIncomingMessageType.Data:
                        ReadPacket(msg);
                        break;

                    default:
                        Console.WriteLine("Unhandled type: " + msg.MessageType);
                        break;

                }
                server.Recycle(msg);
            }
        }
Exemplo n.º 4
0
 public ConnectMenu(RenderWindow window, ImageManager imageManager, Client client, Server server)
     : base(window, imageManager)
 {
     this.server = server;
     this.client = client;
     p = new Player(null, imageManager);
     randomiser = new Random();
     pImage = new RenderImage(window.Width, window.Height);
     pImage.DefaultView.Zoom(0.08F);
     pImage.DefaultView.Center = p.Center + new Vector2f(0, -40);
     pImage.DefaultView.Rotate(135);
     pImage.SetView(pImage.DefaultView);
     mouse = new Sprite(imageManager.GetImage("mouse"));
     title = new MenuItem("Enter an IP to connect to...", new Vector2f(0, 100), null);
     title.CenterX((int)window.Width);
     ip = new MenuItem("", new Vector2f(0, 150), null);
     ip.CenterX((int)window.Width);
     connecting = new MenuItem("Connecting...", new Vector2f(0, 180), null);
     connecting.CenterX((int)window.Width);
 }
Exemplo n.º 5
0
        private void Reset()
        {
            otherClients.Clear();
            clientId = -1;

            map = new World (imageManager);
            player = new Player (map, imageManager);
            map.AddPlayer (player);
            world.DefaultView.Center = new Vector2f (0, 0);
            world.SetView (world.DefaultView);
        }
Exemplo n.º 6
0
 public void AddPlayer(Player p)
 {
     playerList.Add(p);
 }
Exemplo n.º 7
0
 public void DeletePlayer(Player p)
 {
     playerList.Remove(p);
 }