Esempio n. 1
0
        /// <summary>
        /// Allows the game to run logic such as updating the world,
        /// checking for collisions, gathering input, and playing audio.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Update(GameTime gameTime)
        {
            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed ||
                Keyboard.GetState().IsKeyDown(Keys.Escape))
            {
                Exit();
            }

            MouseState mouse = Mouse.GetState();

            Ray     _castRay        = ((BasicCamera)Director.InstanceDirector.Camera).CalculateCursorRay(mouse.X, mouse.Y);
            Vector3 positionOnPlane = PlaneControll.IntersectPoint(_castRay.Direction, _castRay.Position, Vector3.Up, new Vector3(1, 0, 1));


            if (TEST == false)
            {
                if (mouse.LeftButton == ButtonState.Pressed && OldPushed == false)
                {
                    _map.MapLayers[1].LayerClick((((int)positionOnPlane.X / 32)) * 32, (((int)positionOnPlane.Z / 32)) * 32);
                    OldPushed = true;
                }

                if (Keyboard.GetState().IsKeyDown(Keys.F1))
                {
                    // _map.PutElementOnMap(StandardElements.SpawnPiont, new Vector2(positionOnPlane.X, positionOnPlane.Z));
                }

                if (Keyboard.GetState().IsKeyDown(Keys.F2))
                {
                    //_map.PutElementOnMap(StandardElements.FinishPoint, new Vector2(positionOnPlane.X, positionOnPlane.Z));
                }

                if (mouse.LeftButton == ButtonState.Released && OldPushed == true)
                {
                    OldPushed = false;
                }

                if (Keyboard.GetState().IsKeyDown(Keys.F12))
                {
                    TEST = true;
                    _map.SaveMe();
                    _map.InitTestGame(player);
                }
            }
            else
            {
                if (mouse.RightButton == ButtonState.Pressed && player.AliveBoiiii == false)
                {
                    player.AliveBoiiii = true;
                    _map.InitTestGame(player);
                }

                player.Update(gameTime, positionOnPlane);
            }


            Director.InstanceDirector.Camera.Update(gameTime);

            base.Update(gameTime);
        }
Esempio n. 2
0
    // Use this for initialization
    void Awake()
    {
        if (instance == null)
        {
            instance = this;
        }
        else if (instance != this)
        {
            Destroy(gameObject);
        }

        Time.timeScale = 1;
    }
        public void Update()
        {
            if (Keyboard.GetState().IsKeyDown(Keys.F1))
            {
                // Map.PutElementOnMap(StandardElements.SpawnPiont, );
                MouseState mouse = Mouse.GetState();
                if (CurrentMapElement != null)
                {
                    Ray     _castRay        = ((BasicCamera)Director.InstanceDirector.Camera).CalculateCursorRay(mouse.X, mouse.Y);
                    Vector3 positionOnPlane = PlaneControll.IntersectPoint(_castRay.Direction, _castRay.Position, Vector3.Up, new Vector3(1, 0, 1));

                    CurrentMapElement.Position = new Vector2(positionOnPlane.X, positionOnPlane.Z);
                }
            }
        }
Esempio n. 4
0
        /// <summary>
        /// Allows the game to run logic such as updating the world,
        /// checking for collisions, gathering input, and playing audio.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Update(GameTime gameTime)
        {
            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed ||
                Keyboard.GetState().IsKeyDown(Keys.Escape))
            {
                Exit();
            }

            MouseState mouse = Mouse.GetState();


            /////////TEST
            akumulator += gameTime.ElapsedGameTime.TotalMilliseconds;


            foreach (PlayerClass otherPl in OtherPlayerList)
            {
                otherPl.Interpolate();
            }



            /*   if (akumulator > movePacketInterval && player.PlayerNetInfo != null && player.Forward != player.OldForward)
             * {
             *     var newMSG = Client.CreateMessage();
             *     newMSG.Write((short)6066);
             *     newMSG.Write(player.Forward.X);
             *     newMSG.Write(player.Forward.Y);
             *     Client.SendMessage(newMSG, NetDeliveryMethod.UnreliableSequenced);
             *     akumulator = 0;
             * }*/


            /*
             * if (akumulator > movePacketInterval && player.PlayerNetInfo!=null)
             * {
             *   var newMSG = Client.CreateMessage();
             *   newMSG.Write((short)6066);
             *   newMSG.Write(player.Position.X);
             *   newMSG.Write(player.Position.Y);
             *   Client.SendMessage(newMSG, NetDeliveryMethod.UnreliableSequenced);
             *   akumulator = 0;
             * }*/
            /////////TEST

            NetIncomingMessage message;

            while ((message = Client.ReadMessage()) != null)
            {
                switch (message.MessageType)
                {
                case NetIncomingMessageType.Data:
                {
                    // handle custom messages
                    if (message.LengthBytes >= 2)
                    {
                        short opcode;
                        opcode = message.ReadInt16();
                        if (opcode == 2000)
                        {
                            PlayerClass SpawnPlayerPacket = new PlayerClass();
                            SpawnPlayerPacket.ID = message.PeekInt32();
                            //message.ReadAllProperties((object) player);
                            player.PlayerNetInfo = SpawnPlayerPacket;

                            var newMSG = Client.CreateMessage();

                            JoinRoomPacket joinRoom = new JoinRoomPacket(roomName);
                            newMSG.Write(JoinRoomPacket.OpCode);
                            newMSG.Write(joinRoom.RoomName);
                            Client.SendMessage(newMSG, NetDeliveryMethod.ReliableSequenced);
                            akumulator = 0;
                        }
                        else if (opcode == 2620)
                        {
                            PlayerClass playerTemp = new PlayerClass();
                            message.ReadAllProperties(playerTemp);
                            // playerTemp.isAlive = true;
                            OtherPlayerList.Add(playerTemp);
                        }
                        else if (opcode == 6066)
                        {
                            MovePacket movePacket = new MovePacket();
                            message.ReadAllProperties(movePacket);
                            PlayerClass player2Move = OtherPlayerList.FirstOrDefault(x => x.ID == movePacket.ID);
                            if (player2Move != null)
                            {
                                player2Move.StartPosition = player2Move.EndPosition;
                                player2Move.EndPosition   = new Vector2(movePacket.X, movePacket.Y);
                                player2Move.interStep     = 0;
                            }
                        }
                        else if (opcode == ResurrectPointAddPacket.OpCode)
                        {
                            ResurrectPointAddPacket resurrectPlayerPoint = new ResurrectPointAddPacket();
                            message.ReadAllProperties(resurrectPlayerPoint);
                            PlayerClass player = OtherPlayerList.FirstOrDefault(x => x.ID == resurrectPlayerPoint.ID);
                            //   player.isAlive = false;
                            if (player != null)
                            {
                                ResurrectPoint ressurectPoint = new ResurrectPoint("ResurrectID" + player.ID);
                                ressurectPoint.Position = new Vector2(resurrectPlayerPoint.X, resurrectPlayerPoint.Y);
                                //Tu też będzie sie ustawiało kolor żeby gracz wiedział o kogo chodzi poza tym kto sie będzie respawnił po najechaniu na pole decydować bedzie serwer(oczywiście respawnić będzie legitnego człowieka)
                                Map.MapElements.Add(ressurectPoint);
                            }
                        }
                        else if (opcode == RevivedPlayerPacket.OpCode)
                        {
                            RevivedPlayerPacket revivedPlayer = new RevivedPlayerPacket();
                            message.ReadAllProperties(revivedPlayer);
                            PlayerClass player = OtherPlayerList.FirstOrDefault(x => x.ID == revivedPlayer.ID);
                            // player.isAlive = true;
                            ResurrectPoint revivePoint =
                                (ResurrectPoint)Map.GetMapElementByName <IMapElement>("ResurrectID" + player.ID);
                            if (revivePoint != null)
                            {
                                Map.MapElements.Remove(revivePoint);
                            }
                        }
                    }
                    break;
                }

                case NetIncomingMessageType.StatusChanged:
                    // handle connection status messages
                    switch (message.SenderConnection.Status)
                    {
                    case NetConnectionStatus.Connected:
                    {
                        var newMSG = Client.CreateMessage();
                        newMSG.Write((short)2000);
                        newMSG.Write("Client");
                        Client.SendMessage(newMSG, NetDeliveryMethod.UnreliableSequenced);
                        break;
                    }
                    }
                    break;

                case NetIncomingMessageType.DebugMessage:
                    // handle debug messages
                    // (only received when compiled in DEBUG mode)

                    break;

                /* .. */
                default:
                    break;
                }
            }


            foreach (IKeyStroke key in keys)
            {
                key.Update();
            }



            if (IsActive)
            {
                Ray _castRay = ((BasicCamera)Director.InstanceDirector.Camera).CalculateCursorRay(mouse.X, mouse.Y);
                positionOnPlane = PlaneControll.IntersectPoint(_castRay.Direction, _castRay.Position, Vector3.Up, new Vector3(1, 0, 1));
                StandFloorDebug = Map.UpdatePlayerMovmentType(player);
                collision       = Map.MapPath[0].FloorPolygon.IsCollide(player.CollisionObject);
            }
            //  player.Update(gameTime, positionOnPlane);

            if (mouse.RightButton == ButtonState.Pressed && player.AliveBoiiii == false && IsActive == true)
            {
                var newMSG = Client.CreateMessage();
                newMSG.Write((short)6066);
                newMSG.Write(positionOnPlane.X);
                newMSG.Write(positionOnPlane.Z);
                Client.SendMessage(newMSG, NetDeliveryMethod.UnreliableSequenced);
            }



            Director.InstanceDirector.Camera.Update(gameTime);
            Map.Update(gameTime);


            player.OldForward = player.Forward;
            base.Update(gameTime);
        }
Esempio n. 5
0
        /// <summary>
        /// Allows the game to run logic such as updating the world,
        /// checking for collisions, gathering input, and playing audio.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Update(GameTime gameTime)
        {
            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed ||
                Keyboard.GetState().IsKeyDown(Keys.Escape))
            {
                Exit();
            }

            MouseState mouse = Mouse.GetState();

            Ray _castRay = ((BasicCamera)Director.InstanceDirector.Camera).CalculateCursorRay(mouse.X, mouse.Y);

            positionOnPlane = PlaneControll.IntersectPoint(_castRay.Direction, _castRay.Position, Vector3.Up, new Vector3(1, 0, 1));


            foreach (IKeyStroke key in keys)
            {
                key.Update();
            }

            //  TEST = true;
            if (TEST == false)
            {
                if (mouse.LeftButton == ButtonState.Pressed && OldPushed == false && !objectInspector.Desktop.IsMouseOverGUI)
                {
                    Map.MapLayers[1].LayerClick((((int)positionOnPlane.X / 32)) * 32, (((int)positionOnPlane.Z / 32)) * 32);
                    OldPushed = true;
                }

                if (mouse.RightButton == ButtonState.Pressed && !objectInspector.Desktop.IsMouseOverGUI)
                {
                    /* IMapElement el = Map.GetMapElementByName<IMapElement>(objectInspector.selectedID);
                     * if (el != null && el.GetType() != typeof(SpawnPoint) )
                     *   (el as Gun).SetLookingDirection(positionOnPlane);*/

                    Circle circle = new Circle(new Vector2(positionOnPlane.X, positionOnPlane.Z), 15);

                    collision = Map.MapPath[0].FloorPolygon.IsCollide(player.CollisionObject);
                }


                if (Keyboard.GetState().IsKeyDown(Keys.F1))
                {
                    StreamReader MapWriter = new StreamReader("C:\\pasta\\Maps\\Client\\Map0.json");
                    object       objectMap = JsonConvert.DeserializeObject <Map>(MapWriter.ReadToEnd(),
                                                                                 new JsonSerializerSettings()
                    {
                        TypeNameHandling = TypeNameHandling.Objects
                    });
                    MapWriter.Close();
                    Map = (Map)objectMap;
                    Map.InitTestGame(player);
                    TEST = true;
                }

                if (Keyboard.GetState().IsKeyDown(Keys.F2))
                {
                    // Map.PutElementOnMap(StandardElements.FinishPoint, new Vector2(positionOnPlane.X, positionOnPlane.Z));

                    if (!File.Exists("C:\\pasta\\Maps\\Client\\Map0.json"))
                    {
                        StreamWriter MapWriter     = new StreamWriter("C:\\pasta\\Maps\\Client\\Map0.json", false);
                        string       jsonSerialize = JsonConvert.SerializeObject(
                            Map,
                            new JsonSerializerSettings()
                        {
                            TypeNameHandling = TypeNameHandling.Objects
                        });
                        MapWriter.Write(jsonSerialize);
                        MapWriter.Flush();
                        MapWriter.Close();

                        MapWriter     = new StreamWriter("C:\\pasta\\Maps\\Server\\CollisionStructure0.json", false);
                        jsonSerialize = JsonConvert.SerializeObject(
                            Map.MapPath,
                            new JsonSerializerSettings()
                        {
                            TypeNameHandling = TypeNameHandling.Objects
                        });
                        MapWriter.Write(jsonSerialize);
                        MapWriter.Flush();
                        MapWriter.Close();
                    }
                }

                if (mouse.LeftButton == ButtonState.Released && OldPushed == true)
                {
                    OldPushed = false;
                }
            }
            else
            {
                if (mouse.RightButton == ButtonState.Pressed && player.AliveBoiiii == false)
                {
                    player.AliveBoiiii = true;
                }

                StandFloorDebug = Map.UpdatePlayerMovmentType(player);
                //collision = Map.MapPath[0].FloorPolygon.IsCollide(player.CollisionObject);

                if (mouse.LeftButton == ButtonState.Pressed && !objectInspector.Desktop.IsMouseOverGUI)
                {
                    /* IMapElement el = Map.GetMapElementByName<IMapElement>(objectInspector.selectedID);
                     * if (el != null && el.GetType() != typeof(SpawnPoint) )
                     *   (el as Gun).SetLookingDirection(positionOnPlane);*/

                    Circle circle = new Circle(new Vector2(positionOnPlane.X, positionOnPlane.Z), 30);

                    collision = Map.MapPath[0].FloorPolygon.IsCollide(player.CollisionObject);
                }
                player.Update(gameTime, positionOnPlane);
            }


            Director.InstanceDirector.Camera.Update(gameTime);
            Map.Update(gameTime);
            base.Update(gameTime);
        }