예제 #1
0
        /// Handler
        static void CollisionHandler()
        {
            /*
             *      Enemy x Enemy = Push
             *      Enemy x Bullet = A, B Die
             *      Enemy x BlackHole = A Die
             *      Enemy x Player = B Die
             *      Enemy x Explosion = A Die/Push
             *      Enemy x Asteroid = A, B Die
             *      BlackHole x Bullet = A Die, B Push
             *      BlackHole x Player = B Die
             *      BlackHole x Asteroid = B Die
             *      Explosion x Player = B Die
             *      Explosion x Asteroid = B Push
             *      Asteroid x Bullet = A, B Die
             *      Asteroid x Player = A Die
             *      Asteroid x Asteroid = A, B Push
             */

            // Enemy x Enemy
            for (int i = 0; i < enemies.Count; i++)
            {
                for (int j = i + 1; j < enemies.Count; j++)
                {
                    if (inCollision(enemies[i], enemies[j]))
                    {
                        enemies[i].Push(enemies[j]);
                        enemies[j].Push(enemies[i]);
                    }
                }
            }

            foreach (Enemy e in enemies)
            {
                if (e.isWorking)
                {
                    // Enemy x Bullet
                    foreach (Bullet b in bullets)
                    {
                        if (inCollision(e, b))
                        {
                            e.onHit();
                            b.isDestroyed = true;
                        }
                    }

                    // Enemy x BlackHole
                    foreach (BlackHole b in blackholes)
                    {
                        if (inCollision(e, b))
                        {
                            e.onHit(true);
                            b.explode = true;
                        }
                    }

                    // Enemy x Player
                    if (!Player.Instance.isInvisible && inCollision(e, Player.Instance))
                    {
                        Player.Instance.Kill();
                        // Break because everything was destroyed
                        break;
                    }

                    // Enemy x Explosion (Closer = Kill, otherwise push)
                    foreach (Explosion x in explosions)
                    {
                        if (Maths.Pythagoras(x.position, e.position, 45))
                        {
                            if (Maths.Pythagoras(x.position, e.position, 25))
                            {
                                e.onHit(true);
                            }
                            else
                            {
                                e.Push(x);
                            }
                        }
                    }

                    // Enemy x Asteroid
                    foreach (Asteroid a in asteroids)
                    {
                        if (inCollision(e, a))
                        {
                            e.onHit(true);
                            a.inCollision(e);
                        }
                    }
                }
            }

            foreach (BlackHole b in blackholes)
            {
                // BlackHole x Bullet
                foreach (Bullet bu in bullets)
                {
                    if (inCollision(b, bu))
                    {
                        b.onHit();
                        bu.isDestroyed = true;
                    }
                }

                // BlackHole x Player
                if (!Player.Instance.isInvisible && inCollision(b, Player.Instance))
                {
                    Player.Instance.Kill();
                    // Break because everything was destroyed
                    break;
                }

                // BlackHole x Asteroid
                foreach (Asteroid a in asteroids)
                {
                    if (inCollision(b, a))
                    {
                        a.inCollision(a);
                    }
                }
            }

            foreach (Explosion e in explosions)
            {
                // Explosion x Player
                if (!Player.Instance.isInvisible && Maths.Pythagoras(e.position, Player.Instance.position, 45))
                {
                    if (SkillManager.skillData["explosion"].isActive)
                    {
                        Player.Instance.Push(e, 20);
                    }
                    else
                    {
                        Player.Instance.Kill();
                    }
                    break;
                }

                // Explosion x Bullet
                foreach (Bullet b in bullets)
                {
                    if (inCollision(e, b))
                    {
                        b.isDestroyed = true;
                    }
                }

                // Explosion x Asteroid
                foreach (Asteroid a in asteroids)
                {
                    if (Maths.Pythagoras(e.position, a.position, 60))
                    {
                        a.Push(e, 30);
                    }
                }
            }

            foreach (Asteroid a in asteroids)
            {
                // Asteroid x Bullet
                foreach (Bullet b in bullets)
                {
                    if (inCollision(a, b))
                    {
                        a.inCollision(b);
                        b.isDestroyed = true;
                    }
                }

                // Asteroid x Player
                if (!Player.Instance.isInvisible && inCollision(a, Player.Instance))
                {
                    a.inCollision(Player.Instance);
                    Player.Instance.Push(a);
                }
            }

            // Asteroid x Asteroid
            for (int i = 0; i < asteroids.Count; i++)
            {
                for (int j = i + 1; j < asteroids.Count; j++)
                {
                    if (inCollision(asteroids[i], asteroids[j]))
                    {
                        asteroids[i].Push(asteroids[j]);
                        asteroids[j].Push(asteroids[i]);
                    }
                }
            }
        }
예제 #2
0
 /// Get close entities
 public static IEnumerable <Entity> nearEntities(Vector2 pos, float r, float playerR)
 {
     return(entities.Where(e => Maths.Pythagoras(pos, e.position, (e is Player ? playerR : r))));
 }