Exemplo n.º 1
0
        /// <summary>
        /// Is shield exploded by bomb position ?
        /// </summary>
        /// <returns></returns>
        public bool CheckExplosion(Bomb p_bomb)
        {
            bool isExploded = false;

            Point  posBomb       = p_bomb.GetPosition();
            double halfWidthBomb = p_bomb.Bounds.Width / 2;

            Point  posShield        = this.GetPosition();
            double halfWidthShield  = this.Bounds.Width / 2;
            double halfHeightShield = this.Bounds.Height / 2;

            if (this.Bounds.IntersectsWith(p_bomb.Bounds))
            {
                // Check column if shield reached
                int column = (int)((posBomb.X - (posShield.X - halfWidthShield)) / this.CellSize.Width) - 1;

                int damageCount = 0;
                for (int damageCol = 0; damageCol < 3; damageCol++)
                {
                    if (column + damageCol >= 0)
                    {
                        int damageRow = 0;

                        for (int row = 0; row < this.Patterns[Sequence[this.SequenceIndex]].Length; row++)
                        {
                            string spriteData = this.Patterns[Sequence[this.SequenceIndex]][row];

                            if (((column + damageCol) < spriteData.Length) && (spriteData[column + damageCol] == '1'))
                            {
                                isExploded = true;
                                damageRow++;
                                damageCount++;
                                this.Patterns[Sequence[this.SequenceIndex]][row] = spriteData.Substring(0, column + damageCol) + '0' + spriteData.Substring(column + damageCol + 1);

                                if (damageRow >= 2)
                                {
                                    break;
                                }

                                if (damageCount >= 5)
                                {
                                    break;
                                }
                            }
                        }
                    }

                    if (damageCount >= 6)
                    {
                        break;
                    }
                }

                if (damageCount > 0)
                {
                    this.Bitmaps[Sequence[this.SequenceIndex]] = GetBitmap(this.Patterns[Sequence[this.SequenceIndex]]);
                }
            }

            return(isExploded);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Do moving missile
        /// </summary>
        private void MoveMissile()
        {
            // Do movement of missile
            if (this.Missile != null)
            {
                Point posMissile = this.Missile.GetPosition();
                this.Missile.SetPosition(posMissile.X, posMissile.Y - m_missileVerticalStep);
                posMissile = this.Missile.GetPosition();

                // Check if missile exits of screen
                if (posMissile.Y <= 0)
                {
                    DestroyMissile();
                }
                else
                {
                    // Check if missile exploses bomb
                    Bomb explodedBomb = null;

                    foreach (Bomb bomb in m_sprites.Where(s => s is Bomb))
                    {
                        if (this.Missile.CheckExplosion(bomb))
                        {
                            explodedBomb = bomb;
                            break;
                        }
                    }

                    if (explodedBomb != null)
                    {
                        // Remove bomb from sprite list
                        m_sprites.Remove(explodedBomb);
                        DestroyMissile();
                    }
                    else
                    {
                        // Check if missile reaches enemy
                        IEnemy reachedEnemy = null;

                        foreach (IEnemy enemy in m_sprites.Where(s => s is IEnemy))
                        {
                            if ((enemy as Sprite).Bounds.IntersectsWith(this.Missile.Bounds))
                            {
                                DestroyEnemy(enemy);
                                DestroyMissile();
                                reachedEnemy = enemy;
                                break;
                            }
                        }

                        if (reachedEnemy == null)
                        {
                            // Check if missile reaches shield
                            foreach (Shield shield in m_sprites.Where(s => s is Shield))
                            {
                                if (shield.CheckBurning(this.Missile))
                                {
                                    DestroyMissile();
                                    break;
                                }
                            }
                        }
                    }
                }
            }
        }
Exemplo n.º 3
0
 /// <summary>
 /// Is player reached by bomb ?
 /// </summary>
 public bool CheckExplosion(Bomb p_bomb)
 {
     return(this.Bounds.IntersectsWith(p_bomb.Bounds));
 }