Ejemplo n.º 1
0
 private void RespawnCars()
 {
     foreach (iVehicleManager RVM in ReplayerVehicleManagers)
     {
         RVM.DestroyVehicle();
         RVM.CreateVehicle("Vehicle" + RVM.VId, CarManagerType.Replayer, RVM.Vehicle, RVM.Color);
         //RigidBody is frozen when created
     }
 }
Ejemplo n.º 2
0
        protected override void Update(GameTime gameTime)
        {
            if (textures == null)
            {
                InitTextures();
            }

            var kb    = Keyboard.GetState();
            var Delta = 20;

            if (kb.IsKeyDown(Keys.Up))
            {
                position += (new Vector2(0, -1f) * Delta);
            }
            if (kb.IsKeyDown(Keys.Down))
            {
                position += (new Vector2(0, 1f) * Delta);
            }
            if (kb.IsKeyDown(Keys.Left))
            {
                position += (new Vector2(-1f, 0) * Delta);
            }
            if (kb.IsKeyDown(Keys.Right))
            {
                position += (new Vector2(1f, 0) * Delta);
            }

            base.Update(gameTime);
            var msState = Mouse.GetState();

            if (msState.RightButton == ButtonState.Pressed || msState.LeftButton == ButtonState.Pressed && msState.Position.X > 0)
            {
                var ms = new
                {
                    LeftButton  = msState.LeftButton,
                    RightButton = msState.RightButton,
                    Position    = ToWorldCoords(msState.Position.ToVector2()).ToPoint()
                };

                var x = ms.Position.X / RVM.TileSize;
                var y = ms.Position.Y / RVM.TileSize;
                if (x >= 0 && x < RVM.Width && y >= 0 && y < RVM.Height)
                {
                    if (RVM.Mode == "Tile")
                    {
                        var tile = RVM.Tiles.FirstOrDefault(r => r.Position.X == x && r.Position.Y == y);
                        RVM.Select(tile);
                        if (ms.LeftButton == ButtonState.Pressed)
                        {
                            tile.TextureName = RVM.LeftClickTexture;
                        }
                        if (ms.RightButton == ButtonState.Pressed)
                        {
                            tile.TextureName = RVM.RightClickTexture;
                        }
                    }
                    else if (RVM.Mode == "SpawnGroup")
                    {
                        var tile = RVM.Tiles.FirstOrDefault(r => r.Position.X == x && r.Position.Y == y);
                        tile.SpawnGroup = RVM.SpawnGroup;
                    }
                    else if (RVM.Mode == "PlayerStart")
                    {
                        RVM.PlayerStartPosition = new Point(ms.Position.X, ms.Position.Y);
                    }
                    else if (RVM.Mode == "Inanimate")
                    {
                        var ix  = (ms.Position.X - (ms.Position.X % RVM.SnapTo)) + (RVM.SnapTo / 2);
                        var iy  = (ms.Position.Y - (ms.Position.Y % RVM.SnapTo)) + (RVM.SnapTo / 2);
                        var tar = RVM.Inanimates.FirstOrDefault(m => m.Position.X == ix && m.Position.Y == iy);
                        if (ms.LeftButton == ButtonState.Pressed && tar == null)
                        {
                            RVM.Inanimates.Add(new InanimateTypeViewModel
                            {
                                Type     = RVM.InanimateType,
                                Position = new Point(ix, iy),
                            });
                        }
                        if (ms.RightButton == ButtonState.Pressed && tar != null)
                        {
                            RVM.Inanimates.Remove(tar);
                        }
                    }
                    else if (RVM.Mode == "Enemy")
                    {
                        var ix  = (ms.Position.X - (ms.Position.X % RVM.SnapTo)) + (RVM.SnapTo / 2);
                        var iy  = (ms.Position.Y - (ms.Position.Y % RVM.SnapTo)) + (RVM.SnapTo / 2);
                        var tar = RVM.Enemies.FirstOrDefault(m => m.Position.X == ix && m.Position.Y == iy);
                        if (ms.LeftButton == ButtonState.Pressed && tar == null)
                        {
                            RVM.Enemies.Add(new EnemyViewModel
                            {
                                Type     = RVM.EnemyType,
                                Position = new Point(ix, iy),
                            });
                        }
                        if (ms.RightButton == ButtonState.Pressed && tar != null)
                        {
                            RVM.Enemies.Remove(tar);
                        }
                    }
                }
            }
        }