예제 #1
0
        public void enemyShoot(L2Sprite enemy)
        {
            Bullet newB = new Bullet((content.Load <Texture2D>("Textures\\eBullet")), enemy);

            newB.velocity  = new Vector2((float)Math.Sin(enemy.rotation), (float)Math.Cos(enemy.rotation)) * new Vector2(-5f, 4f);
            newB.screenPos = enemy.getPos() + newB.velocity * 3;
            newB.live      = true;

            if (evilBullets.Count < 5)
            {
                shoot.Play();
                evilBullets.Add(newB);
            }
        }
예제 #2
0
        public void updateEvilBullets(L2Sprite enemy)
        {
            foreach (Bullet b in evilBullets)
            {
                b.screenPos += b.velocity;
                if (Vector2.Distance(b.screenPos, enemy.getPos()) > 600)
                {
                    b.live = false;
                }
            }

            for (int i = 0; i < evilBullets.Count; i++)
            {
                if (!evilBullets[i].live)
                {
                    evilBullets.RemoveAt(i);
                    i--;
                }
            }
        }
예제 #3
0
        public override void Update(GameTime gameTime, bool otherScreenHasFocus, bool coveredByOtherScreen)
        {
            #region Update
            base.Update(gameTime, otherScreenHasFocus, false);
            background.Update(2);
            pSprite.Update(gameTime, viewportRect);
            #endregion
            #region Pause Gradient
            if (coveredByOtherScreen)
            {
                pauseGradient = Math.Min(pauseGradient + 1f / 32, 1);
            }
            else
            {
                pauseGradient = Math.Max(pauseGradient - 1f / 32, 0);
            }
            #endregion
            #region Spawn Enemy Timer
            if (active)
            {
                Random rand = new Random();
                elapsedTime  += gameTime.ElapsedGameTime.Milliseconds;
                elapsedTime2 += gameTime.ElapsedGameTime.Milliseconds;

                if (elapsedTime > spawnTime)
                {
                    elapsedTime -= spawnTime;
                    enemies.Add(CreateEnemy());
                    spawnTime = rand.Next(timeLeft * 5, timeLeft * 10);
                }
                #endregion
                #region Update Time Left (not visible)

                if (elapsedTime2 > secondTime)
                {
                    elapsedTime2 -= secondTime;
                    timeLeft--;
                    score++;
                }
                #endregion
                #region Shoot Enemies
                foreach (L2Enemy e in enemies)
                {
                    e.Update(gameTime, viewportRect);

                    enemyShoot(e);
                    #endregion
                    #region Rotate Enemies
                    if (e.getPos().X > pSprite.getPos().X)
                    {
                        if (e.getRotation() > 0.8)
                        {
                            e.rotation = (float)0.8;
                        }
                        else
                        {
                            e.rotation += 0.005f;
                        }
                    }

                    if (e.getPos().X < pSprite.getPos().X)
                    {
                        if (e.getRotation() < -0.8)
                        {
                            e.rotation = (float)-0.8;
                        }
                        else
                        {
                            e.rotation -= 0.005f;
                        }
                    }
                    #endregion
                    #region Check for Enemy crashing into Player
                    if (e.CollidesWith(pSprite))
                    {
                        if (!e.getLanded() && !e.getCollided())
                        {
                            pSprite.deHealth();
                            health--;
                            explode.Play();
                            e.setCollided();
                            hit.Add(e);
                        }
                    }
                    #endregion
                    #region Check for Good Bullets hitting Enemies
                    foreach (Bullet b in goodBullets)
                    {
                        if (b.live)
                        {
                            if (b.CollidesWith(e))
                            {
                                e.deHealth();
                                if (e.getLives() <= 0)
                                {
                                    e.setCollided();
                                    hit.Add(e);
                                    explode.Play();
                                    score += 25;
                                }
                                deadBullets.Add(b);
                            }
                        }
                    }
                    #endregion
                    #region Check for Evil Bullets hitting Enemies
                    foreach (Bullet b in evilBullets)
                    {
                        if (b.live)
                        {
                            if (b.CollidesWith(e))
                            {
                                deadEvilBullets.Add(b);
                            }
                            #endregion
                            #region Check for Evil Bullets hitting Player
                            if (b.CollidesWith(pSprite))
                            {
                                pSprite.deHealth();
                                health--;
                                b.live = false;
                                damage.Play();
                            }
                        }
                    }
                    health = (int)MathHelper.Clamp(health, 0, 100);
                    updateEvilBullets(e);
                }
                #endregion
                #region Update Healthbar Colour
                if (health < 100 && health > 75)
                {
                    healthColor = Color.Green;
                }
                else if (health < 76 && health > 50)
                {
                    healthColor = Color.Yellow;
                }
                else if (health < 51 && health > 25)
                {
                    healthColor = Color.Orange;
                }
                else if (health < 26 && health > 0)
                {
                    healthColor = Color.Red;
                }
                #endregion
                #region Check for Victory
                if (timeLeft == 0)
                {
                    SManager.AddScreen(new Victory2(score), null);
                }
                #endregion
                #region Check for Loss
                if (pSprite.getLives() <= 0)
                {
                    explode.Play();
                    SManager.AddScreen(new Loss2(), null);
                }
                #endregion
                #region Process Dead/Inactive Bullets + Enemies
                foreach (L2Enemy s in enemies)
                {
                    if (s.getDie())
                    {
                        inactive.Add(s);
                    }
                }

                foreach (L2Enemy s in hit)
                {
                    enemies.Remove(s);
                }

                foreach (L2Enemy s in inactive)
                {
                    enemies.Remove(s);
                }

                foreach (Bullet b in deadBullets)
                {
                    goodBullets.Remove(b);
                }
            }


            updateBullets();
            #endregion
        }