コード例 #1
0
 bool CheckParticleCollision(Collision sprite1, ParticleManager particles)
 {
     for (int particle = 0; particle < particles.particles.Count; particle++)
     {
         sprite2 = particles.GetCollider(particle);
         if (sprite1.visiblePixelCollision(sprite2))
         {
             particles.Kill(particle);
             particles.Update();
             particle--;
             return(true);
         }
     }
     return(false);
 }
コード例 #2
0
        void UpdateList(List <SpriteStripManager> list, SpriteStripManager item, GameTime gameTime)
        {
            for (int i = 0; i < list.Count; i++)
            {
                int hit = 0;
                if (list[i].myID == 2)
                {
                    // if the item in the list is an alien it reduces the shotcooldown and allows the ai to control it.
                    list[i].shotcooldown -= (float)gameTime.ElapsedGameTime.TotalSeconds;
                    if (myShip.Scale == 1)
                    {
                        ai.Think(list[i], myShip, controller, EnemyBulletParticles, soundlistinstance[0]);
                    }
                }

                controller.Update(list[i]);
                list[i].Update();

                sprite1 = list[i].GetCollider();
                if (list[i].isCollectable == false)
                {
                    //these checks are for when the player hits objects with it's bullets

                    for (int particle = 0; particle < PlayerBulletParticles.particles.Count; particle++)
                    {
                        sprite2 = PlayerBulletParticles.GetCollider(particle);
                        if (CheckParticleCollision(sprite1, PlayerBulletParticles))
                        {
                            //create 2 small asteroids when a large one is destroyed
                            if (list[i].Scale >= 0.5 && list[i].myID == 1)
                            {
                                spawner.SpawnChildren(item, list, asteroidIdle, i, (int)Difficulty.difficulty / 2, ranGen);
                                numAsteroid += (int)Difficulty.difficulty / 2;
                            }
                            if (list[i].Scale > 0.5 && list[i].myID == 2)
                            {
                                //spawns 0 aliens at difficulties 0-2, 1 alien from 3-5 and 2 aliens on the other difficulties when an alien is destroyed
                                spawner.SpawnChildren(item, list, alienIdle, i, (int)Difficulty.difficulty / 3, ranGen);
                                numAliens += (int)Difficulty.difficulty / 3;
                            }
                            //remove asteroid when hit by player shot
                            GenerateParticleEffects(list[i]);
                            if (list[i].myID == 1)
                            {
                                if (list[i].Scale == 1)
                                {
                                    soundlist[1].Play();
                                }
                                else if (list[i].Scale == 0.5)
                                {
                                    soundlist[2].Play();
                                }
                                else
                                {
                                    soundlist[3].Play();
                                }
                                hud.score        += 50;
                                extralifecounter += 50;
                                numAsteroid--;
                            }
                            else
                            {
                                numAliens--;
                                hud.score        += 100;
                                extralifecounter += 100;
                                soundlist[4].Play();
                            }
                            list.RemoveAt(i);
                            hit = 1;
                        }
                    }
                }
                //if the player has been hit before than the following is skipped
                if (hit == 0)
                {
                    //these checks are for when the player collides with other objects.
                    if (timesincelasthit > 2 || list[i].isCollectable)
                    {
                        sprite2 = myShip.GetCollider();
                        if (sprite1.visiblePixelCollision(sprite2))
                        {
                            if (list[i].Scale >= 0.5 && list[i].myID == 1)
                            {
                                spawner.SpawnChildren(item, list, asteroidIdle, i, (int)Difficulty.difficulty / 2, ranGen);
                                numAsteroid += (int)Difficulty.difficulty / 2;
                            }
                            if (list[i].Scale > 0.5 && list[i].myID == 2)
                            {
                                //spawns 0 aliens at difficulties 0-2, 1 alien from 3-5 and 2 aliens on the other difficulties when an alien is destroyed
                                spawner.SpawnChildren(item, list, alienIdle, i, (int)Difficulty.difficulty / 3, ranGen);
                                numAliens += (int)Difficulty.difficulty / 3;
                            }
                            //remove asteroid when hit by player shot
                            if (list[i].myID == 1)
                            {
                                numAsteroid--;
                                hud.score        += 25;
                                extralifecounter += 25;
                                if (list[i].Scale == 1)
                                {
                                    soundlist[1].Play();
                                }
                                else if (list[i].Scale == 0.5)
                                {
                                    soundlist[2].Play();
                                }
                                else
                                {
                                    soundlist[3].Play();
                                }
                            }
                            else if (list[i].myID == 2)
                            {
                                numAliens--;
                                hud.score        += 50;
                                extralifecounter += 50;
                                soundlist[4].Play();
                            }
                            else
                            {
                                numStars--;
                                hud.score        += 100;
                                extralifecounter += 50;
                                soundlist[5].Play();
                            }
                            if (!list[i].isCollectable)
                            {
                                //if the item collided with is not a collectable then the player is destroyed.
                                GenerateParticleEffects(list[i]);
                                GenerateParticleEffects(myShip);
                                hud.lives--;
                                myShip.Scale     = 0;
                                timesincelasthit = 0;
                                soundlist[1].Play();
                            }

                            list.RemoveAt(i);
                        }
                    }
                }
            }
        }