bool CheckCollisions()
        {
            if (m_Player.Active())
            {
                if (CirclesIntersect(m_Player.m_Position, m_Player.m_Radius))
                {
                    SetScore();
                    m_Player.Hit();
                    return(true);
                }
            }

            for (int shot = 0; shot < 4; shot++)
            {
                if (m_Player.m_Shots[shot].Active())
                {
                    if (CirclesIntersect(m_Player.m_Shots[shot].m_Position, m_Player.m_Shots[shot].m_Radius))
                    {
                        m_Player.m_Shots[shot].Destroy();
                        SetScore();
                        return(true);
                    }
                }
            }

            if (m_UFO.m_Shot.Active())
            {
                if (CirclesIntersect(m_UFO.m_Shot.m_Position,
                                     m_UFO.m_Shot.m_Radius))
                {
                    m_UFO.m_Shot.Destroy();
                    return(true);
                }
            }

            if (m_UFO.Active())
            {
                if (CirclesIntersect(m_UFO.m_Position, m_UFO.m_Radius))
                {
                    m_UFO.Hit();
                    m_UFO.Explode();
                    return(true);
                }
            }

            return(false);
        }
Beispiel #2
0
        public override void Update()
        {
            m_NumberOfRocksLastFrame = m_NumberOfRocksThisFrame;
            int  rockCount   = 0;
            int  smrockCount = 0;
            int  mdrockCount = 0;
            int  lgrockCount = 0;
            bool playerClear = true;

            foreach (Rock rock in m_LargeRocks)
            {
                if (rock.m_Hit)
                {
                    rock.Destroy();
                    SpawnMedRocks(rock.m_Position);
                }

                if (rock.Active())
                {
                    rockCount++;
                    lgrockCount++;
                }
            }

            foreach (Rock rock in m_MedRocks)
            {
                if (rock.m_Hit)
                {
                    rock.Destroy();
                    SpawnSmallRocks(rock.m_Position);
                }

                if (rock.Active())
                {
                    rockCount++;
                    mdrockCount++;
                }
            }

            foreach (Rock rock in m_SmallRocks)
            {
                if (rock.m_Hit)
                {
                    rock.Destroy();
                }

                if (rock.Active())
                {
                    rockCount++;
                    smrockCount++;
                }
            }

            m_NumberOfRocksThisFrame = rockCount;

            if (m_NumberOfRocksLastFrame != m_NumberOfRocksThisFrame) //If([size]rockCount  < 4) {pitch = 1.2f + (0.05f × ( 4 - mdrockCount))}
            {
                float pitch = 1;

                if (lgrockCount == 0)
                {
                    if (mdrockCount > 3)
                    {
                        pitch = 1.2f;
                    }
                    else if (mdrockCount == 3)
                    {
                        pitch = 1.25f;
                    }
                    else if (mdrockCount == 2)
                    {
                        pitch = 1.3f;
                    }
                    else if (mdrockCount == 1)
                    {
                        pitch = 1.35f;
                    }

                    if (mdrockCount == 0)
                    {
                        if (smrockCount > 3)
                        {
                            pitch = 1.4f;
                        }
                        else if (smrockCount == 3)
                        {
                            pitch = 1.45f;
                        }
                        else if (smrockCount == 2)
                        {
                            pitch = 1.5f;
                        }
                        else if (smrockCount == 1)
                        {
                            pitch = 1.55f;
                        }
                    }
                }
                else if (lgrockCount > 3)
                {
                    pitch = 1;
                }
                else if (lgrockCount == 3)
                {
                    pitch = 1.05f;
                }
                else if (lgrockCount == 2)
                {
                    pitch = 1.1f;
                }
                else if (lgrockCount == 1)
                {
                    pitch = 1.15f;
                }

                m_Background.Pitch = pitch;
            }

            if (rockCount == 0)
            {
                m_LargeRockCount += 2;
                SpawnLargeRocks(m_LargeRockCount);
            }

            if (m_UFOTimer.TotalTime.TotalSeconds > m_UFOTimerSet && !m_UFO.Active())
            {
                m_UFOTimerSet = (float)m_Random.NextDouble() * m_UFOTimerAmount + ((m_UFOTimerAmount - m_Wave) * 0.5f);
                m_UFOTimer.Reset();
                m_UFO.Spawn(m_UFOCount, m_Wave);
                m_UFOCount++;
            }

            if (m_UFO.m_Done || m_UFO.m_Hit)
            {
                m_UFOTimer.Reset();
                m_UFO.Destroy();
            }

            if (m_Player.m_Hit)
            {
                foreach (Rock rock in m_LargeRocks)
                {
                    if (rock.Active())
                    {
                        if (m_Player.m_Hit)
                        {
                            if (!rock.CheckPlayerCLear())
                            {
                                playerClear = false;
                                break;
                            }
                        }
                    }
                }

                foreach (Rock rock in m_MedRocks)
                {
                    if (rock.Active())
                    {
                        if (m_Player.m_Hit)
                        {
                            if (!playerClear)
                            {
                                break;
                            }

                            if (!rock.CheckPlayerCLear())
                            {
                                playerClear = false;
                                break;
                            }
                        }
                    }
                }

                foreach (Rock rock in m_SmallRocks)
                {
                    if (rock.Active())
                    {
                        if (m_Player.m_Hit)
                        {
                            if (!playerClear)
                            {
                                break;
                            }

                            if (!rock.CheckPlayerCLear())
                            {
                                playerClear = false;
                                break;
                            }
                        }
                    }
                }

                if (playerClear)
                {
                    m_Player.m_Spawn = true;
                }

                if (m_UFO.Active())
                {
                    if (!m_UFO.CheckPlayerClear())
                    {
                        m_Player.m_Spawn = false;
                    }
                }

                if (m_UFO.m_Shot.Active())
                {
                    if (!m_UFO.m_Shot.CheckPlayerClear())
                    {
                        m_Player.m_Spawn = false;
                    }
                }
            }

            m_UFOTimer.Tick();

            if (m_Player.m_GameOver)
            {
                if (!m_Player.m_NewHighScore)
                {
                    if (Input.IsKeyPressed(Keys.N) || Input.IsKeyPressed(Keys.S) || Input.IsKeyPressed(Keys.Return))
                    {
                        NewGame();
                    }
                }

                if (!m_UFO.m_GameOver)
                {
                    m_Background.Stop();

                    foreach (Rock rock in m_LargeRocks)
                    {
                        rock.m_GameOver = true;
                    }

                    foreach (Rock rock in m_MedRocks)
                    {
                        rock.m_GameOver = true;
                    }

                    foreach (Rock rock in m_SmallRocks)
                    {
                        rock.m_GameOver = true;
                    }

                    m_UFO.m_GameOver = true;
                }
            }
            else
            {
                m_UFO.m_GameOver = false;

                if (m_Player.m_Pause)
                {
                    if (Input.IsKeyPressed(Keys.P))
                    {
                        m_Background.Play();

                        foreach (Rock rock in m_LargeRocks)
                        {
                            rock.Pause(false);
                        }

                        foreach (Rock rock in m_MedRocks)
                        {
                            rock.Pause(false);
                        }

                        foreach (Rock rock in m_SmallRocks)
                        {
                            rock.Pause(false);
                        }

                        m_UFO.Pause(false);
                        m_Player.Pause(false);

                        foreach (Shot shot in m_Player.m_Shots)
                        {
                            shot.Pause(false);
                        }
                    }
                }
                else
                {
                    m_Background.Play();

                    if (Input.IsKeyPressed(Keys.P))
                    {
                        m_Background.Stop();

                        foreach (Rock rock in m_LargeRocks)
                        {
                            rock.Pause(true);
                        }

                        foreach (Rock rock in m_MedRocks)
                        {
                            rock.Pause(true);
                        }

                        foreach (Rock rock in m_SmallRocks)
                        {
                            rock.Pause(true);
                        }

                        m_UFO.Pause(true);
                        m_Player.Pause(true);

                        foreach (Shot shot in m_Player.m_Shots)
                        {
                            shot.Pause(true);
                        }
                    }
                }
            }
        }