Ejemplo n.º 1
0
 public void StopX(SpriteStripManager sprite)
 {
     if (sprite.Speed.Length() != 0)
     {
         //if (sprite.Speed.X > 0.2f)
         //{
         sprite.Speed.X *= 0.99f;
         //}
         //else sprite.Speed.X = 0;
         //if (sprite.Speed.Y > 0.2f)
         //{
         sprite.Speed.Y *= 0.99f;
         // }
         // else sprite.Speed.Y = 0;
         if (sprite.Speed.Length() < 0.1)
         {
             sprite.Speed.X = 0;
             sprite.Speed.Y = 0;
         }
         //sprite.Speed += Vector2.Transform(new Vector2(0, -1), Matrix.CreateRotationZ(sprite.rotation));
     }
     //if (sprite.XSpeed != 0.0f)
     //{
     //    if (sprite.XSpeed < 0.0f)
     //    {
     //        sprite.XSpeed += 0.05f;
     //    }
     //    if (sprite.XSpeed > 0.0f)
     //    {
     //        sprite.XSpeed -= 0.05f;
     //    }
     //}
     //if (sprite.XSpeed > -0.05f && sprite.XSpeed < 0.05f)
     //    sprite.XSpeed = 0.0f;
 }
        public void Think(SpriteStripManager Enemy, SpriteStripManager Player, ObjectController controller, ParticleManager particle, SoundEffectInstance sound)
        {
            //Pretty simple AI if player is too close the enemy will run into the player, if it's too far away to run into the enemy it fires and if it's really far away it does nothing.
            Vector2 enemyloc  = new Vector2(Enemy.XPos, Enemy.YPos);
            Vector2 playerloc = new Vector2(Player.XPos, Player.YPos);
            float   angle     = (float)((Math.Atan2(playerloc.Y - enemyloc.Y, playerloc.X - enemyloc.X) + MathHelper.Pi / 2));

            angle += MathHelper.ToRadians((new Random().Next(10 - Difficulty.difficulty) - (10 - Difficulty.difficulty))); //generates a random number between -(10 - difficulty) and 10 - difficulty and converts this to radians to stop the ai from being perfectly accurate but the ai will get more accurate as difficulty increases.
            if (Vector2.Distance(enemyloc, playerloc) < 600 && (Vector2.Distance(enemyloc, playerloc) > 100))
            {
                Enemy.Speed.Y = 0;
                if (Enemy.shotcooldown <= 0)
                {
                    //as difficulty increases the enemy will fire more often
                    Enemy.shotcooldown = 5 - Difficulty.difficulty / 2;
                    controller.Shoot(Enemy, particle, angle, sound);
                }
            }
            else if (Vector2.Distance(enemyloc, playerloc) < 100)
            {
                if (Enemy.Scale > 0.5)
                {
                    //a negative angle means that the alien will move away from the player.
                    controller.Move(Enemy, angle, 1);
                }
                else
                {
                    controller.Move(Enemy, -angle, 2);
                }
            }
        }
 public void NewItem(SpriteStripManager item, List <SpriteStripManager> itemlist, SpriteStrip texture, int itemid, Random ranGen)
 {
     item = new SpriteStripManager(1, false, ranGen, itemid);
     itemlist.Add(item);
     itemlist[itemlist.Count - 1].addAnimatedSpriteStrip(texture);
     itemlist[itemlist.Count - 1].Update();
 }
 void GenerateParticleEffects(SpriteStripManager item)
 {
     for (int i = 0; i < 3; i++)
     {
         ParticleEffects.EmitterLocation = new Vector2(item.XPos, item.YPos);
         ParticleEffects.Rangle          = (float)ranGen.NextDouble() * 6.2f;
         ParticleEffects.NewParticle(item.myID);
     }
 }
        public void Rotate(SpriteStripManager sprite, float angle)
        {
            float circle = MathHelper.Pi * 2;

            sprite.rotation += angle;
            sprite.rotation  = sprite.rotation % circle; //resets rotation to 0 after full spin
            if (sprite.rotation < 0)                     //prevents rotation becoming a negative number
            {
                sprite.rotation = circle + sprite.rotation;
            }
        }
 public void Move(SpriteStripManager sprite)
 {
     if (sprite.Speed.Length() < 3)
     {
         sprite.Speed += Vector2.Transform(new Vector2(0, -0.1f), Matrix.CreateRotationZ(sprite.rotation));
     }
     else
     {
         Stop(sprite);
     }
 }
 public void SpawnChildren(SpriteStripManager item, List <SpriteStripManager> itemlist, SpriteStrip texture, int current, int amount, Random ranGen)
 {
     //spawns smaller versions of a given item.
     for (int i = 0; i < amount; i++)
     {
         texture = new SpriteStrip(itemlist[current].getTexture(), 0.1f, true);
         texture.setName("Idle");
         item = new SpriteStripManager(1, false, ranGen, itemlist[current].XPos, itemlist[current].YPos, itemlist[current].Scale / 2, itemlist[current].myID);
         itemlist.Add(item);
         itemlist[itemlist.Count - 1].addAnimatedSpriteStrip(texture);
         itemlist[itemlist.Count - 1].Update();
     }
 }
        public void Stop(SpriteStripManager sprite)
        {
            if (sprite.Speed.Length() != 0)
            {
                sprite.Speed.X *= 0.99f;
                sprite.Speed.Y *= 0.99f;

                if (sprite.Speed.Length() < 0.1)
                {
                    sprite.Speed.X = 0;
                    sprite.Speed.Y = 0;
                }
            }
        }
Ejemplo n.º 9
0
 public void Move(SpriteStripManager sprite, int x)
 {
     if (x == 0)
     {
         if (sprite.Speed.Length() < 3)
         {
             sprite.Speed += Vector2.Transform(new Vector2(0, -0.1f), Matrix.CreateRotationZ(sprite.rotation));
         }
         else
         {
             StopX(sprite);
         }
     }
     if (x == 1)
     {
         float circle = MathHelper.Pi * 2;
         sprite.rotation += 0.1f;
         sprite.rotation  = sprite.rotation % circle; //resets rotation to 0 after full spin
         if (sprite.rotation < 0)                     //prevents rotation becoming a negative number
         {
             sprite.rotation = circle + sprite.rotation;
         }
         //if (sprite.XSpeed > -5)
         //{
         //    sprite.XSpeed -= 0.05f;
         //}
     }
     else if (x == 2)
     {
         if (sprite.XSpeed < 5)
         {
             sprite.XSpeed += 0.05f;
         }
     }
     else if (x == 3)
     {
         if (sprite.YSpeed > -5)
         {
             sprite.YSpeed -= 0.05f;
         }
     }
     else if (x == 4)
     {
         if (sprite.YSpeed < 5)
         {
             sprite.YSpeed += 0.05f;
         }
     }
 }
Ejemplo n.º 10
0
        public void Rotate(SpriteStripManager sprite, float angle)
        {
            float circle = MathHelper.Pi * 2;

            if (angle >= MathHelper.Pi)
            {
                if (sprite.rotation != angle)
                {
                    if (sprite.rotation > (angle + MathHelper.Pi) % circle && sprite.rotation < angle)
                    {
                        sprite.rotation += 0.03f;
                    }
                    else
                    {
                        sprite.rotation -= 0.03f;
                    }

                    if (sprite.rotation < angle + 0.03 && sprite.rotation > angle - 0.03)
                    {
                        sprite.rotation = angle;
                    }
                }
            }
            else
            {
                if (sprite.rotation != angle)
                {
                    if (sprite.rotation > (angle + MathHelper.Pi) % circle || sprite.rotation < angle)
                    {
                        sprite.rotation += 0.03f;
                    }
                    else
                    {
                        sprite.rotation -= 0.03f;
                    }

                    if (sprite.rotation < angle + 0.03 && sprite.rotation > angle - 0.03)
                    {
                        sprite.rotation = angle;
                    }
                }
            }

            sprite.rotation = sprite.rotation % circle; //resets rotation to 0 after full spin
            if (sprite.rotation < 0)                    //prevents rotation becoming a negative number
            {
                sprite.rotation = circle + sprite.rotation;
            }
        }
        public void Shoot(SpriteStripManager sprite, ParticleManager particle, SoundEffectInstance sound)
        {
            if (particle.particles.Count < 3)
            {
                if (sound.State == SoundState.Playing)
                {
                    sound.Pause();
                }
                sound.Play();

                particle.EmitterLocation = new Vector2(sprite.XPos, sprite.YPos);
                particle.Rangle          = sprite.rotation;
                particle.NewParticle();
            }
        }
        public void Shoot(SpriteStripManager sprite, ParticleManager particle, float angle, SoundEffectInstance sound)
        {
            //shoots at a specific angle this is used for when the AI fires
            if (particle.particles.Count < 3)
            {
                if (sound.State == SoundState.Playing)
                {
                    sound.Pause();
                }
                sound.Play();

                particle.EmitterLocation = new Vector2(sprite.XPos, sprite.YPos);
                particle.Rangle          = angle;
                particle.NewParticle();
            }
        }
Ejemplo n.º 13
0
 public void StopY(SpriteStripManager sprite)
 {
     if (sprite.YSpeed != 0.0f)
     {
         if (sprite.YSpeed < 0.0f)
         {
             sprite.YSpeed += 0.05f;
         }
         if (sprite.YSpeed > 0.0f)
         {
             sprite.YSpeed -= 0.05f;
         }
     }
     if (sprite.YSpeed > -0.05f && sprite.YSpeed < 0.05f)
     {
         sprite.YSpeed = 0.0f;
     }
 }
        public void RotateTo(SpriteStripManager sprite, float angle)
        {
            //rotates ship to a specific angle for when a controller is used as the player input
            float circle = MathHelper.Pi * 2;

            if (angle < 0) //prevents rotation becoming a negative number
            {
                angle = circle + angle;
            }

            if (sprite.rotation > angle + 0.3f || sprite.rotation < angle - 0.3f)
            {
                if (sprite.rotation + MathHelper.Pi <= circle)
                {
                    if (angle < sprite.rotation + MathHelper.Pi && sprite.rotation < angle)
                    {
                        sprite.rotation += 0.3f;
                    }
                    else
                    {
                        sprite.rotation -= 0.3f;
                    }
                }
                else if (sprite.rotation - MathHelper.Pi < angle && sprite.rotation > angle)
                {
                    sprite.rotation -= 0.3f;
                }
                else
                {
                    sprite.rotation += 0.3f;
                }
            }
            else
            {
                sprite.rotation = angle;
            }
            sprite.rotation = sprite.rotation % circle; //resets rotation to 0 after full spin
            if (sprite.rotation < 0)                    //prevents rotation becoming a negative number
            {
                sprite.rotation = circle + sprite.rotation;
            }
        }
 public void Move(SpriteStripManager sprite, float angle, int dir)
 {
     sprite.Speed = Vector2.Transform(new Vector2(0, -2f * dir), Matrix.CreateRotationZ(angle));
 }
 public void Update(SpriteStripManager sprite)
 {
     Rotate(sprite, sprite.Rotate);
     sprite.XPos += sprite.Speed.X;
     sprite.YPos += sprite.Speed.Y;
 }
 void MoveTo(SpriteStripManager sprite, float Xpos, float Ypos)
 {
     sprite.XPos = Xpos;
     sprite.YPos = Ypos;
 }
        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);
                        }
                    }
                }
            }
        }
Ejemplo n.º 19
0
 public void Update(SpriteStripManager sprite)
 {
     sprite.XPos += sprite.Speed.X;
     sprite.YPos += sprite.Speed.Y;
 }
Ejemplo n.º 20
0
 public void Shoot(SpriteStripManager sprite, ParticleManager particle)
 {
     particle.EmitterLocation = new Vector2(sprite.XPos, sprite.YPos);
     particle.Rangle          = sprite.rotation;
     particle.NewParticle();
 }