Exemplo n.º 1
0
        protected override void CollisionWithLine(int asteroidIndex)
        {
            for (int index = lazerList.Count - 1; index > -1; index--)
            {
                // om skott krockar med astroid
                if (Raylib.CheckCollisionCircleRec(asteroidList[asteroidIndex].GetCirclePos, asteroidList[asteroidIndex].GetAsteroidHitboxSize, lazerList[index].GetRect))
                {
                    // - skott dmg && ta bort skott && + score för spaceship
                    asteroidList[asteroidIndex].Hp -= lazerList[index].GetDamage;
                    Spaceship.AddToScore(lazerList[index].GetID, lazerList[index].GetDamage);
                    Lazer.RemoceInstanceOfLine(index);

                    // om hp efter -dmg >=0 ta bort astroid också
                    if (asteroidList[asteroidIndex].Hp <= 0)
                    {
                        for (int i = 0; i < 3 * ButtonSeries.GetSelectedMultiplier(2); i++)
                        {
                            ScatterAsteroidSubMissile scatterAsteroidSubMissile = new ScatterAsteroidSubMissile(asteroidList[asteroidIndex].GetCirclePos, Color.PINK, 100);
                        }

                        asteroidList.Remove(asteroidList[asteroidIndex]);
                    }
                }
            }
        }
Exemplo n.º 2
0
        // hämtar in lista med skott
        // syftet med metoden är att checka om ett skott(Line) kolliderar med en asteroid
        protected virtual void CollisionWithLine(int asteroidIndex)
        {
            // för varje instans av Lazer tittar om kollision med astroid;
            for (int index = lazerList.Count - 1; index > -1; index--)
            {
                // om skott krockar med astroid
                if (Raylib.CheckCollisionCircleRec(asteroidList[asteroidIndex].GetCirclePos, asteroidList[asteroidIndex].GetAsteroidHitboxSize, lazerList[index].GetRect))
                {
                    // - skott dmg && ta bort skott && + score för spaceship
                    asteroidList[asteroidIndex].Hp -= lazerList[index].GetDamage;

                    // om hp efter -dmg >=0 ta bort astroid också
                    if (asteroidList[asteroidIndex].Hp <= 0)
                    {
                        // lägger till poäng för asteroid
                        Spaceship.AddToScore(lazerList[index].GetID, asteroidList[asteroidIndex].worth);
                        // tar bort instans av astroid
                        asteroidList.Remove(asteroidList[asteroidIndex]);
                    }
                    // tar bort skott(index)
                    Lazer.RemoceInstanceOfLine(index);
                }
            }
        }