Наследование: FBLibrary.Core.BaseEntities.BaseMap
Пример #1
0
        protected override void Move(GameTime gameTime, Map map, int[,] hazardMap)
        {
            #region Moving input

            _motionVector = Vector2.Zero;

            // Up
            if ((Config.PlayersUsingController[Id] && InputHandler.ButtonDown(Buttons[0], PlayerIndex.One)) ||
                InputHandler.KeyDown(Keys[0]))
            {
                Sprite.CurrentAnimation = AnimationKey.Up;
                CurrentDirection = LookDirection.Up;
                _motionVector.Y = -1;
            }
            // Down
            else if ((Config.PlayersUsingController[Id] && InputHandler.ButtonDown(Buttons[1], PlayerIndex.One)) ||
                     InputHandler.KeyDown(Keys[1]))
            {
                Sprite.CurrentAnimation = AnimationKey.Down;
                CurrentDirection = LookDirection.Down;
                _motionVector.Y = 1;
            }
            // Left
            else if ((Config.PlayersUsingController[Id] && InputHandler.ButtonDown(Buttons[2], PlayerIndex.One)) ||
                     InputHandler.KeyDown(Keys[2]))
            {
                Sprite.CurrentAnimation = AnimationKey.Left;
                CurrentDirection = LookDirection.Left;
                _motionVector.X = -1;
            }
            // Right
            else if ((Config.PlayersUsingController[Id] && InputHandler.ButtonDown(Buttons[3], PlayerIndex.One)) ||
                     InputHandler.KeyDown(Keys[3]))
            {
                Sprite.CurrentAnimation = AnimationKey.Right;
                CurrentDirection = LookDirection.Right;
                _motionVector.X = 1;
            }
            else
            {
                CurrentDirection = LookDirection.Idle;
            }

            #endregion

            if (_motionVector != Vector2.Zero)
            {
                IsMoving = true;

                Position += _motionVector * GetMovementSpeed();
            }
            else
            {
                IsMoving = false;
            }

            Sprite.IsAnimating = IsMoving;

            base.Move(gameTime, map, hazardMap);
        }
Пример #2
0
        public void ChangeEntityPosition(DynamicEntity entity, Map map)
        {
            bool allTeleporterCellTaken = true;

            foreach (Teleporter t in map.TeleporterList)
            {
                Point position = t.CellPosition;
                if (position != CellPosition && map.Board[position.X, position.Y] is Teleporter)
                    allTeleporterCellTaken = false;
            }

            if (!allTeleporterCellTaken)
            {
                Point position = CellPosition;
                while (position == CellPosition)
                {
                    position = FinalBomber.Instance.GamePlayScreen.TeleporterList[
                        GamePlayScreen.Random.Next(FinalBomber.Instance.GamePlayScreen.TeleporterList.Count)].
                        CellPosition;
                }

                var bomb = entity as Bomb;
                if (bomb != null)
                {
                    bomb.ChangeSpeed(bomb.Speed + Config.BombSpeedIncrementeur);
                    bomb.ResetTimer();
                    bomb.ChangePosition(position);
                }
                else
                    entity.ChangePosition(position);
            }
        }
Пример #3
0
        protected override void Move(GameTime gameTime, Map map, int[,] hazardMap)
        {
            base.Move(gameTime, map, hazardMap);

            SendMovement();

            #region Movement interpolation
            // If a new position has been received from server
            if (_nextPosition != Vector2.Zero)
            {
                // If the position received from server is not reached yet
                if (Math.Abs(Position.X - _nextPosition.X) > 0.1f &&
                    Math.Abs(Position.Y - _nextPosition.Y) > 0.1f)
                {
                    // First time that we interpolate => save the initial position
                    if (!_isInterpolating)
                    {
                        _isInterpolating = true;
                        _initialPosition = Position;
                    }

                    _interpolationTimer += gameTime.ElapsedGameTime;

                    // We interpolate
                    float interpolationAmount = MathHelper.Clamp((float)_interpolationTimer.TotalMilliseconds / (float)_movementInterpolationTime.TotalMilliseconds, 0f, 1f);
                    PositionX = MathHelper.Lerp(_initialPosition.X, _nextPosition.X, interpolationAmount);
                    PositionY = MathHelper.Lerp(_initialPosition.Y, _nextPosition.Y, interpolationAmount);

                    if (_interpolationTimer >= _movementInterpolationTime)
                    {
                        _interpolationTimer = TimeSpan.Zero;
                        _nextPosition = Vector2.Zero;
                        _isInterpolating = false;
                    }
                }
            }
            #endregion

            #region Bomb

            if ((HasBadEffect && BadEffect == BadEffect.BombDrop) ||
                ((Config.PlayersUsingController[Id] && InputHandler.ButtonDown(Buttons[4], PlayerIndex.One)) || InputHandler.KeyPressed(Keys[4]) &&
                (!HasBadEffect || (HasBadEffect && BadEffect != BadEffect.NoBomb))))
            {
                if (this.CurrentBombAmount > 0)
                {
                    var bo = GameServer.Instance.GameManager.BombList.Find(b => b.CellPosition == this.CellPosition);
                    if (bo == null)
                    {
                        // Send to server that we want to plant a bomb
                        GameServer.Instance.SendBombPlacing();
                    }
                }
            }

            #endregion
        }
Пример #4
0
        protected GameManager()
        {
            Players = new PlayerCollection();

            WallList = new List<Wall>();
            PowerUpList = new List<PowerUp>();
            BombList = new List<Bomb>();

            _currentMap = new Map();
            BaseCurrentMap = _currentMap;

            _gameStopWatch = TimeSpan.Zero;

            _gameTime = new GameTime();
        }
Пример #5
0
        protected override void Move(GameTime gameTime, Map map, int[,] hazardMap)
        {
            #region Walk

            // If he hasn't reach his goal => we walk to this goal
            if (_aiNextPosition != new Vector2(-1, -1) &&
                !AIFunction.HasReachNextPosition(Position, Speed, _aiNextPosition))
            {
                IsMoving = true;
                Sprite.IsAnimating = true;

                CheckIsBlocked(map, hazardMap);

                Walk();

                ComputeWallCollision(map);
            }

            #endregion

            #region Search a goal
            // Otherwise => we find another goal
            else
            {
                // We place the player at the center of its cell
                Position = Engine.CellToVector(CellPosition);

                #region Bomb => AI

                // Try to put a bomb
                // Put a bomb
                if (!HasBadEffect || (HasBadEffect && BadEffect != BadEffect.NoBomb))
                {
                    if (AIFunction.TryToPutBomb(CellPosition, BombPower, map.Board, map.CollisionLayer, hazardMap,
                        Config.MapSize))
                    {
                        if (CurrentBombAmount > 0)
                        {
                            Bomb bo =
                                FinalBomber.Instance.GamePlayScreen.BombList.Find(
                                    b => b.CellPosition == CellPosition);
                            if (bo == null)
                            {
                                CurrentBombAmount--;
                                var bomb = new Bomb(Id, CellPosition, BombPower, BombTimer, Speed);

                                // We define a new way (to escape the bomb)
                                Path = AIFunction.MakeAWay(
                                    CellPosition,
                                    AIFunction.SetNewDefenseGoal(CellPosition, map.CollisionLayer, hazardMap,
                                        Config.MapSize),
                                    map.CollisionLayer, hazardMap, Config.MapSize);

                                FinalBomber.Instance.GamePlayScreen.AddBomb(bomb);
                            }
                        }
                    }
                }

                #endregion

                if (Path == null || Path.Count == 0)
                {
                    Sprite.IsAnimating = false;
                    IsMoving = false;
                    // We define a new goal
                    Path = AIFunction.MakeAWay(
                        CellPosition,
                        AIFunction.SetNewGoal(CellPosition, map.Board, map.CollisionLayer, hazardMap,
                            Config.MapSize),
                        map.CollisionLayer, hazardMap, Config.MapSize);

                    if (Path != null)
                    {
                        _aiNextPosition = Engine.CellToVector(Path[Path.Count - 1]);
                        Path.Remove(Path[Path.Count - 1]);

                        CheckIsBlocked(map, hazardMap);
                    }
                }
                else
                {
                    // We finish the current way
                    _aiNextPosition = Engine.CellToVector(Path[Path.Count - 1]);
                    Path.Remove(Path[Path.Count - 1]);
                    /*
                    // Update the way of the AI each time it changes of cell => usefull to battle against players (little bug here)
                    aiWay = AI.MakeAWay(
                        CellPosition,
                        AI.SetNewGoal(CellPosition, map.Board, map.CollisionLayer, hazardMap),
                        map.CollisionLayer, hazardMap);
                    */
                }
            }

            #endregion

            UpdatePlayerPosition(map);
        }
Пример #6
0
 private void CheckIsBlocked(Map map, int[,] hazardMap)
 {
     // If the AI is blocked
     if (map.CollisionLayer[Engine.VectorToCell(_aiNextPosition).X, Engine.VectorToCell(_aiNextPosition).Y] ||
         hazardMap[Engine.VectorToCell(_aiNextPosition).X, Engine.VectorToCell(_aiNextPosition).Y] >= 2)
     {
         Sprite.IsAnimating = false;
         IsMoving = false;
         // We define a new goal
         Path = AIFunction.MakeAWay(
             CellPosition,
             AIFunction.SetNewGoal(CellPosition, map.Board, map.CollisionLayer, hazardMap, map.Size),
             map.CollisionLayer, hazardMap, map.Size);
     }
 }
Пример #7
0
        protected override void Move(GameTime gameTime, Map map, int[,] hazardMap)
        {
            Vector2 motionVector = Vector2.Zero;

            switch (CurrentDirection)
            {
                case LookDirection.Down:
                    Sprite.CurrentAnimation = AnimationKey.Down;
                    motionVector.Y = 1;
                    break;
                case LookDirection.Left:
                    Sprite.CurrentAnimation = AnimationKey.Left;
                    motionVector.X = -1;
                    break;
                case LookDirection.Right:
                    Sprite.CurrentAnimation = AnimationKey.Right;
                    motionVector.X = 1;
                    break;
                case LookDirection.Up:
                    Sprite.CurrentAnimation = AnimationKey.Up;
                    motionVector.Y = -1;
                    break;
            }

            if (motionVector != Vector2.Zero)
            {
                IsMoving = true;
                Sprite.IsAnimating = true;
                Position += motionVector * GetMovementSpeed();
            }
            else
            {
                Sprite.IsAnimating = false;
            }

            //UpdatePlayerPosition();

            #region Bomb

            /*
            if ((HasBadItemEffect && BadItemEffect == BadItemEffect.BombDrop) ||
                ((Config.PlayersUsingController[Id] && InputHandler.ButtonDown(Buttons[4], PlayerIndex.One)) || InputHandler.KeyPressed(Keys[4]) &&
                (!HasBadItemEffect || (HasBadItemEffect && BadItemEffect != BadItemEffect.NoBomb))))
            {
                if (this.CurrentBombAmount > 0)
                {
                    var bo = FinalBomber.Instance.GamePlayScreen.BombList.Find(b => b.CellPosition == this.CellPosition);
                    if (bo == null)
                    {
                        this.CurrentBombAmount--;
                        var bomb = new Bomb(this.Id, CellPosition, this.Power, this.BombTimer, this.Speed);

                        FinalBomber.Instance.GamePlayScreen.AddBomb(bomb);
                    }
                }
            }
            */

            #endregion

            base.Move(gameTime, map, hazardMap);
        }
Пример #8
0
 public override void Update(GameTime gameTime, Map map, int[,] hazardMap)
 {
     base.Update(gameTime, map, hazardMap);
 }