PlaceBack() public method

public PlaceBack ( byte ID, int x, int y, bool Self = false ) : bool
ID byte
x int
y int
Self bool
return bool
Exemplo n.º 1
0
        public static Map ReadSyncedMap(NetIncomingMessage I)
        {
            Map Map = new Map(I.ReadInt32(), I.ReadInt32());

            for (int x = 0; x < Map.Tiles.GetLength(0); x++)
            {
                for (int y = 0; y < Map.Tiles.GetLength(1); y++)
                {
                    byte Fore = I.ReadByte(), Back = I.ReadByte();
                    if (Fore > 0)
                    {
                        Map.PlaceFore(Fore, x, y, I.ReadByte());
                    }
                    if (Back > 0)
                    {
                        Map.PlaceBack(Back, x, y);
                    }
                }
            }
            return(Map);
        }
Exemplo n.º 2
0
        public static Map Load(string Path)
        {
            Map Map = null;
            int x = 0, y = 0;

            using (StreamReader Reader = new StreamReader(Path))
            {
                string Line = null;
                while (!string.IsNullOrEmpty(Line = Reader.ReadLine()))
                {
                    string[] Elements = (Line.Contains(":") ? Line.Split(':')[1].Split(',') : Line.Split(','));
                    if (Line.StartsWith("size"))
                    {
                        Map = new Map(Convert.ToInt32(Elements[0]), Convert.ToInt32(Elements[1]));
                    }
                    else
                    {
                        byte Fore = Convert.ToByte(Elements[0]), Back = Convert.ToByte(Elements[1]);
                        if (Fore > 0)
                        {
                            Map.PlaceFore(Fore, x, y, Convert.ToByte(Elements[2]));
                        }
                        if (Back > 0)
                        {
                            Map.PlaceBack(Back, x, y);
                        }
                        if (x == (Map.Tiles.GetLength(0) - 1))
                        {
                            x = 0; y++;
                        }
                        else
                        {
                            x++;
                        }
                    }
                }
                Reader.Close();
            }
            return(Map);
        }
Exemplo n.º 3
0
        protected override void Update(GameTime Time)
        {
            Mouse.Update();
            Keyboard.Update(Time);
            XboxPad.Update(Time);
            Timers.Update(Time);
            Performance.Update(Time);

            Globe.Active = IsActive;
            if (XboxPad.Pressed(XboxPad.Buttons.Back) || Keyboard.Pressed(Keyboard.Keys.Escape))
            {
                Exit();
            }

            Profiler.Start("Game Update");
            switch (State)
            {
                #region MainMenu

            case States.MainMenu:
                if (Globe.Active)
                {
                    if (Keyboard.Pressed(Keyboard.Keys.F1))
                    {
                        CreateLobby("Server");
                        State = States.Game;
                    }
                    else if (Keyboard.Pressed(Keyboard.Keys.F2))
                    {
                        if (Keyboard.Holding(Keyboard.Keys.LeftShift) || Keyboard.Holding(Keyboard.Keys.RightShift))
                        {
                            MultiPlayer.Connect("Game", "127.0.0.1", 6121, Globe.Version, MpName);
                        }
                        else
                        {
                            MultiPlayer.Connect("Game", "71.3.34.68", 6121, Globe.Version, MpName);
                        }
                    }
                    else if (Keyboard.Pressed(Keyboard.Keys.F3))
                    {
                        CreateLobby("Server");
                        Camera.Position = new Vector2((Map.Width / 2f), (Map.Height / 2f));
                        State           = States.MapEditor;
                    }
                }
                break;

                #endregion

            case States.RequestMap: if (MultiPlayer.Type() == MultiPlayer.Types.Client)
                {
                    MultiPlayer.Send(MultiPlayer.Construct(Packets.RequestMap)); State = States.SyncingMap;
                }
                break;

                #region MapEditor
            case States.MapEditor:
                Map.Update(Time);
                Point MousePoint = new Point((int)(Mouse.CameraPosition.X / Tile.Width), (int)(Mouse.CameraPosition.Y / Tile.Height));
                if (Globe.Active)
                {
                    #region Camera Movement
                    if (Keyboard.Holding(Keyboard.Keys.W))
                    {
                        Camera.Position.Y -= (float)(Map.Speed.Y * Time.ElapsedGameTime.TotalSeconds);
                    }
                    if (Keyboard.Holding(Keyboard.Keys.S))
                    {
                        Camera.Position.Y += (float)(Map.Speed.Y * Time.ElapsedGameTime.TotalSeconds);
                    }
                    if (Keyboard.Holding(Keyboard.Keys.A))
                    {
                        Camera.Position.X -= (float)(Map.Speed.X * Time.ElapsedGameTime.TotalSeconds);
                    }
                    if (Keyboard.Holding(Keyboard.Keys.D))
                    {
                        Camera.Position.X += (float)(Map.Speed.X * Time.ElapsedGameTime.TotalSeconds);
                    }
                    #endregion
                    bool BackPlace = (Keyboard.Holding(Keyboard.Keys.LeftShift) || Keyboard.Holding(Keyboard.Keys.RightShift));
                    if (Mouse.ScrolledUp())
                    {
                        if (!BackPlace)
                        {
                            if (EditorForeTile > 1)
                            {
                                EditorForeTile--;
                            }
                        }
                        else
                        {
                            if (EditorBackTile > 1)
                            {
                                EditorBackTile--;
                            }
                        }
                    }
                    if (Mouse.ScrolledDown())
                    {
                        if (!BackPlace)
                        {
                            if (EditorForeTile < Mod.Fore.Values.Count)
                            {
                                EditorForeTile++;
                            }
                        }
                        else
                        {
                            if (EditorBackTile < Mod.Back.Values.Count)
                            {
                                EditorBackTile++;
                            }
                        }
                    }
                    if (Mouse.Holding(Mouse.Buttons.Left))
                    {
                        if (!BackPlace)
                        {
                            Map.PlaceFore(EditorForeTile, MousePoint.X, MousePoint.Y, null, true);
                        }
                        else
                        {
                            Map.PlaceBack(EditorBackTile, MousePoint.X, MousePoint.Y, true);
                        }
                    }
                    if (Mouse.Holding(Mouse.Buttons.Right))
                    {
                        if (!BackPlace)
                        {
                            Map.ClearFore(MousePoint.X, MousePoint.Y, true);
                        }
                        else
                        {
                            Map.ClearBack(MousePoint.X, MousePoint.Y, true);
                        }
                    }
                }
                break;
                #endregion

                #region Game

            case States.Game:
                Map.Update(Time);
                for (byte i = 0; i < Players.Length; i++)
                {
                    if (Players[i] != null)
                    {
                        Players[i].Update(Time);
                    }
                }
                if (MultiPlayer.Type("Game") == MultiPlayer.Types.Server)
                {
                    if (Timers.Tick("Positions"))
                    {
                        foreach (var Player1 in Players)
                        {
                            if (Player1 != null && (Player1.Connection != null))
                            {
                                var O = MultiPlayer.Construct("Game", Packets.Position);
                                foreach (var Player2 in Players)
                                {
                                    if ((Player2 != Player1) && (Player2 != null) && !Player2.Dead)
                                    {
                                        O.Write(Player2.Slot);
                                        O.Write(Player2.Position);
                                        O.Write(Player2.Angle);
                                    }
                                }
                                MultiPlayer.SendTo("Game", O, Player1.Connection, NetDeliveryMethod.UnreliableSequenced, 1);
                            }
                        }
                    }
                    if (GameType == GameTypes.TeamStandard)
                    {
                        if (!RoundEnded)
                        {
                            if (RoundEndWait > 0)
                            {
                                RoundEndWait -= Time.ElapsedGameTime.TotalSeconds;
                            }
                            else if ((TeamCount(1) > 0) && (TeamCount(2) > 0))
                            {
                                if ((DeadCount(1) == TeamCount(1)) && (DeadCount(2) == TeamCount(2)))
                                {
                                    EndRound(VictoryStates.Draw, 0, 0);
                                }
                                else if (DeadCount(1) == TeamCount(1))
                                {
                                    EndRound(VictoryStates.Team, 2, 0);
                                }
                                else if (DeadCount(2) == TeamCount(2))
                                {
                                    EndRound(VictoryStates.Team, 1, 0);
                                }
                            }
                        }
                        else
                        {
                            if (RoundTimer > 0)
                            {
                                RoundTimer -= Time.ElapsedGameTime.TotalSeconds;
                            }
                            else
                            {
                                NewRound();
                            }
                        }
                    }
                }
                break;

                #endregion
            }
            Profiler.Stop("Game Update");

            #region Networking

            MultiPlayer.Flush("Game");
            NetIncomingMessage I;
            while ((I = MultiPlayer.Read("Game")) != null)
            {
                var Break = false;
                switch (I.MessageType)
                {
                case NetIncomingMessageType.ConnectionApproval:
                    Read(Packets.Connection, I);
                    break;

                case NetIncomingMessageType.Data:
                    Read((Packets)I.ReadByte(), I);
                    break;

                case NetIncomingMessageType.StatusChanged:
                    var Status = ((MultiPlayer.Type("Game") == MultiPlayer.Types.Client)
                            ? (NetConnectionStatus)I.ReadByte()
                            : ((MultiPlayer.Type("Game") == MultiPlayer.Types.Server)
                                ? I.SenderConnection.Status
                                : NetConnectionStatus.None));
                    switch (Status)
                    {
                    case NetConnectionStatus.Connected:
                        if (MultiPlayer.Type("Game") == MultiPlayer.Types.Client)
                        {
                            var Hail = I.SenderConnection.RemoteHailMessage;
                            Read((Packets)Hail.ReadByte(), Hail);
                        }
                        break;

                    case NetConnectionStatus.Disconnected:
                        if ((MultiPlayer.Type("Game") == MultiPlayer.Types.Client) &&
                            (I.SenderConnection.Status == NetConnectionStatus.Disconnected))
                        {
                            QuitLobby();
                            Break = true;
                        }
                        else
                        {
                            Read(Packets.Disconnection, I);
                        }
                        break;
                    }
                    break;
                }
                if (Break)
                {
                    break;
                }
            }

            #endregion

            base.Update(Time);
        }