Exemplo n.º 1
0
 public Node(GameBlock gameBlock)
 {
     this._location   = gameBlock.Location;
     this._nodeEntity = gameBlock.PowerUp ?? gameBlock.Entity ?? gameBlock.Bomb;
     this._exploding  = gameBlock.Exploding;
     this._bombEntity = gameBlock.Bomb;
 }
        /// <summary>
        /// Marks the game block at the specified location as exploded.
        /// If the block contains a bomb that is not yet exploding, that bomb will then be detonated.
        /// </summary>
        /// <param name="x">X Location</param>
        /// <param name="y">Y Location</param>
        /// <param name="bomb">The bomb causing the explostion</param>
        /// <returns>True if the block was marked succesfully, false if the block contains a non destructable entity</returns>
        protected bool MarkGameBlockExploded(int x, int y, BombEntity bomb)
        {
            var gameBlock = _gameMap.GetBlockAtLocation(x, y);

            if (gameBlock.Entity == null)
            {
                gameBlock.ExplodingBombs.Add(bomb);
            }
            if (gameBlock.Bomb != null && !gameBlock.Bomb.IsExploding)
            {
                DetonateBomb(gameBlock.Bomb);
                _bombGraph.ConnectNodes(bomb, gameBlock.Bomb);
            }
            if (gameBlock.Entity != null)
            {
                var entity = gameBlock.Entity;
                if (entity.IsDestructable())
                {
                    gameBlock.ExplodingBombs.Add(bomb);
                }
                if (entity.StopsBombBlast())
                {
                    return(false);
                }
            }

            return(true);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Plants a new bomb on this game block
        /// </summary>
        /// <param name="timer">The timer for the bomb</param>
        /// <exception cref="InvalidOperationException">If here is no player present on the current block</exception>
        /// <exception cref="InvalidOperationException">If the block already contains a bomb</exception>
        /// <exception cref="InvalidOperationException">If the timer is less than 1</exception>
        public void PlantBomb(int timer)
        {
            if (Entity == null || Entity.GetType() != typeof(PlayerEntity))
            {
                throw new InvalidOperationException("Bomb required an owner");
            }

            if (Bomb != null)
            {
                throw new InvalidOperationException("Block already contains a bomb " + Entity.ToString());
            }

            if (timer < 2)
            {
                throw new InvalidOperationException("Bomb timer value should be larger than 1");
            }

            var owner = ((PlayerEntity)Entity);

            Bomb = new BombEntity {
                Owner      = owner,
                Location   = _location,
                BombRadius = owner.BombRadius,
                BombTimer  = timer
            };
        }
Exemplo n.º 4
0
        public DetonateBombTask(BombEntity bomb)
            : base(
                delayInMilliseconds: 2000,
                type: TaskType.GameWin)
        {
            Condition.Requires(bomb, nameof(bomb)).IsNotNull();

            this._bomb = bomb;
        }
Exemplo n.º 5
0
        private Brush GetWickBruch(BombEntity bomb)
        {
            Condition.Requires(bomb, nameof(bomb)).IsNotNull();

            switch (bomb.State)
            {
            case BombState.Normal:
                return(this._normalWickBrush);

            case BombState.Activated:
            default:
                return(this._activatedWickBrush);
            }
        }
Exemplo n.º 6
0
        private void DrawWickRectangle(
            BombEntity bomb,
            Graphics gc,
            PointDrawingHelper helper)
        {
            Condition.Requires(bomb, nameof(bomb)).IsNotNull();
            Condition.Requires(gc, nameof(gc)).IsNotNull();
            Condition.Requires(helper, nameof(helper)).IsNotNull();

            var wickRectangle = helper.GetPointRectangle(0.1);

            gc.FillEllipse(
                this.GetWickBruch(bomb),
                wickRectangle);
        }
 protected void AssignPoints(BombEntity ownerBomb, IEntity destroyedEntity)
 {
     if (destroyedEntity == null)
     {
         return;
     }
     if (destroyedEntity.GetType() == typeof(PlayerEntity))
     {
         ownerBomb.Points += +_playerKillPoints;
         return;
     }
     if (destroyedEntity.GetType() == typeof(DestructibleWallEntity))
     {
         ownerBomb.Points += Settings.Default.PointsWall;
         return;
     }
 }
        /// <summary>
        /// Detonates a specific bomb entity.
        /// This calculates the blast raduis for the bomb, and marks all of the game blocks affected by the explosion.
        /// </summary>
        /// <param name="bombEntity">The bomb to detonate</param>
        protected void DetonateBomb(BombEntity bombEntity)
        {
            _logger.LogInfo(String.Format("Detonating Bomb {0}", bombEntity));
            bombEntity.IsExploding = true;

            _bombGraph.AddNode(bombEntity);
            var bombX      = bombEntity.Location.X;
            var bombY      = bombEntity.Location.Y;
            var bombRaduis = bombEntity.BombRadius;

            for (var i = bombX; i <= bombX + bombRaduis; i++)
            {
                if (i > _gameMap.MapWidth)
                {
                    break;
                }

                if (!MarkGameBlockExploded(i, bombY, bombEntity))
                {
                    break;
                }
            }

            for (var i = bombX; i >= bombX - bombRaduis; i--)
            {
                if (i < 1)
                {
                    break;
                }

                if (!MarkGameBlockExploded(i, bombY, bombEntity))
                {
                    break;
                }
            }

            for (var i = bombY; i <= bombY + bombRaduis; i++)
            {
                if (i > _gameMap.MapHeight)
                {
                    break;
                }

                if (!MarkGameBlockExploded(bombX, i, bombEntity))
                {
                    break;
                }
            }

            for (var i = bombY; i >= bombY - bombRaduis; i--)
            {
                if (i < 1)
                {
                    break;
                }

                if (!MarkGameBlockExploded(bombX, i, bombEntity))
                {
                    break;
                }
            }
        }
Exemplo n.º 9
0
        public void HandleInput()
        {
            if (Animation == CelebrateAnimation) {
                Velocity = Vector2.Zero;
            } else {
                float speedMultiplier = 1F;

                // Ice multiplier
                if (_OnIce) {
                    speedMultiplier = 1.5F;
                }

                if (_Banana)
                    speedMultiplier = 0.5F;

                // Handle input
                if (GameHandler.InputHandler.OnKeyDown(Keys.Enter) && BombTimer <= 0) {
                    BombEntity bomb = new BombEntity();
                    BombTimer = 2;
                    bomb.Position = Position;
                    bomb.Velocity = Velocity;
                    bomb.Velocity.Y -= 500F;
                    if(IdleAnimation.FlipHorizontally) {
                        bomb.Velocity.X = Velocity.X - 1000F;
                    } else {
                        bomb.Velocity.X = Velocity.X + 1000F;
                    }
                    bomb.Layer = 10;
                    Parent.AddChild(bomb);
                }
                if (GameHandler.InputHandler.AnyKeyDown(LeftKey)) {
                    Velocity.X = LeftSpeed * speedMultiplier;
                } else if (GameHandler.InputHandler.AnyKeyDown(RightKey)) {
                    Velocity.X = RightSpeed * speedMultiplier;
                } else if (!_OnIce && _OnGround) {
                    Velocity.X = 0F;
                }
                if (GameHandler.InputHandler.AnyKeyDown(JumpKey) && _OnGround) {
                    Jump(JumpSpeed);
                }
            }
        }
Exemplo n.º 10
0
 public BombWorld(Engine renderEngine)
 {
     engine = renderEngine;
       skyBox = new SkyBox();
 }
Exemplo n.º 11
0
 public BombLogical(Game game, BombEntity owner)
     : base(game, owner)
 {
 }
Exemplo n.º 12
0
 public BombRenderer(Game game, BombEntity owner)
     : base(game, owner)
 {
 }