Example #1
0
        public void Recalculate(DateTime now)
        {
            m_ship.Recalculate(now);
            //Баллистика собственных снарядов
            foreach (Bullet b in m_ship.GetAmmunition)
            {
                if (!b.IsCharged)
                {
                    b.Fly();
                }
                if (b.Ypoint < 0 || b.Xpoint < 0 || b.Xpoint > m_width)
                {
                    b.IsCharged = true;
                }
            }

            //Баллистика снарядов врагов
            for (int i = 0; i < m_enemyBullets.Count; i++)
            {
                m_enemyBullets[i].Fly();
                if (m_enemyBullets[i].Ypoint > GetHeight)
                {
                    m_enemyBullets.RemoveAt(i);
                }
            }

            //Враги и бонусы
            for (int i = 0; i < m_aliens.Count; i++)
            {
                if (m_aliens[i].GetHealth == 0)
                {
#warning !!!!!!!!!!!

                    if (now.Subtract(m_aliens[i].TimeOfExplosion).Milliseconds > 500)
                    {
                        m_ship.AddCash(m_aliens[i].GetCash);
                        m_aliens.RemoveAt(i);
                        m_counterBonus++;
                        //pl.URL = "Sound\\explosion.wav";
                    }
                }
                else
                {
                    if (m_aliens[i].Ypoint > m_height)
                    {
                        m_aliens.RemoveAt(i);
                    }
                    else
                    {
                        m_aliens[i].Shoot(now, m_enemyBullets);
                        m_aliens[i].Move(m_width, m_height);
                    }
                }
            }

            //Проверка на попадание в алиенов и возвращение пули в магазин
            for (int i = 0; i < m_aliens.Count; i++)
            {
                foreach (Bullet b in m_ship.GetAmmunition)
                {
                    if (!b.IsCharged && m_aliens[i].GetHealth > 0)
                    {
                        if (Collision(b, m_aliens[i]))
                        {
                            m_aliens[i].Damaged(b, now);
                            b.IsCharged = true;
                        }
                    }
                }
            }

            //Повреждение корабля снарядами
            for (int i = 0; i < m_enemyBullets.Count; i++)
            {
                if (Collision(m_ship, m_enemyBullets[i]))
                {
                    m_ship.Damaged(m_enemyBullets[i]);
                    if (m_ship.GetArmor == 0)
                    {
                        m_ship.Collapse(m_width / 2, m_height - m_ship.GetHeight / 2,
                                        now);
                    }
                    m_enemyBullets.RemoveAt(i);
                }
            }

            //Столкновения корабля и противников
            foreach (Alien a in m_aliens)
            {
                if (Collision(m_ship, a))
                {
                    m_ship.Collapse(m_width / 2, m_height - m_ship.GetHeight / 2,
                                    now);
                    break;
                }
            }

            //Расчет падения бонусов
            if (m_bonus != null)
            {
                m_bonus.Fall();
                if (m_bonus.Ypoint > m_height)
                {
                    m_bonus = null;
                }
                else
                {
                    if (Collision(m_ship, m_bonus))
                    {
                        m_bonus.Improve(m_ship);
                        m_bonus = null;
                    }
                }
            }
            else
            {
                if (m_counterBonus >= m_needForDrop)
                {
                    m_counterBonus = 0;
                    m_bonus        = m_bonuses[m_rnd.Next(m_bonuses.Count)];
                    m_bonus.Drop(m_rnd.Next(20, m_width - 20), 0);
                }
            }
        }