public void Update()
 {
     spawnTimer.UpdateTimer();
     if (lastSpawnedItem != null && lastSpawnedItem.Taken)
     {
         spawnTimer.ResetToZero();
         lastSpawnedItem = null;
     }
 }
Пример #2
0
        public virtual void GetHit(float damage)
        {
            if (hitTimer.Test() && explosionTimer == null)
            {
                isHit        = true;
                jetColor     = Color.OrangeRed;
                dimension.X += 5;
                dimension.Y += 5;
                hitTimer.ResetToZero();
            }

            health -= damage;

            if (health > 0)
            {
                hitEffect.Play();
            }

            if (health <= 0 && explosionTimer == null)
            {
                speed          = 0f;
                canShoot       = false;
                model          = Globals.content.Load <Texture2D>("explosion");
                explosionTimer = new CustomTimer(200);
            }
        }
Пример #3
0
        private void HandleLevel()
        {
            levelShowTextTimer.UpdateTimer();

            if (enemies.Count == 0 && spawners.Count == 0)
            {
                Random r = new Random();
                level++;
                spawners.Clear();
                switch (level)
                {
                case 2:
                    spawners.Add(new CorporalSpawner(new Vector2(r.Next(0, Globals.screenWidth),
                                                                 -r.Next(100, 300)), 10));
                    spawners.Add(new KamikazeSpawner(new Vector2(r.Next(-300, Globals.screenWidth + 300),
                                                                 -r.Next(100, 300)), 3));
                    break;

                case 3:
                    spawners.Add(new CorporalSpawner(new Vector2(r.Next(0, Globals.screenWidth),
                                                                 -r.Next(100, 300)), 5));
                    spawners.Add(new SergeantSpawner(new Vector2(r.Next(0, Globals.screenWidth),
                                                                 -r.Next(100, 300)), 10));
                    break;

                case 4:
                    spawners.Add(new MajorSpawner(new Vector2(r.Next(0, Globals.screenWidth),
                                                              -r.Next(100, 300)), 10));
                    spawners.Add(new SergeantSpawner(new Vector2(r.Next(0, Globals.screenWidth),
                                                                 -r.Next(100, 300)), 10));
                    break;

                case 5:
                    spawners.Add(new MajorSpawner(new Vector2(r.Next(0, Globals.screenWidth),
                                                              -r.Next(100, 300)), 5));
                    spawners.Add(new GeneralSpawner(new Vector2(r.Next(0, Globals.screenWidth),
                                                                -r.Next(100, 300)), 3));
                    break;

                case 6:
                    spawners.Add(new CorporalSpawner(new Vector2(r.Next(0, Globals.screenWidth),
                                                                 -r.Next(100, 300)), 10));
                    spawners.Add(new SergeantSpawner(new Vector2(r.Next(0, Globals.screenWidth),
                                                                 -r.Next(100, 300)), 5));
                    spawners.Add(new KamikazeSpawner(new Vector2(r.Next(-300, Globals.screenWidth + 300),
                                                                 -r.Next(100, 300)), 3));
                    spawners.Add(new MajorSpawner(new Vector2(r.Next(0, Globals.screenWidth),
                                                              -r.Next(100, 300)), 5));
                    spawners.Add(new GeneralSpawner(new Vector2(r.Next(0, Globals.screenWidth),
                                                                -r.Next(100, 300)), 5));
                    break;

                default:
                    Globals.currentState            = State.StartMenu;
                    GameGlobals.playerJet.destroyed = true;
                    break;
                }
                levelShowTextTimer.ResetToZero();
            }
        }
Пример #4
0
        private void ShootMissile()
        {
            Missile missile =
                new Missile(new Vector2(position.X, position.Y), this, new Vector2(Globals.mouse.newMousePos.X, Globals.mouse.newMousePos.Y), rotation, 12);

            GameGlobals.PassBullet(missile);
            missileEffect.Play();
            missileShootCooldown.ResetToZero();
        }
        public override void Update()
        {
            if (modelCounter < maxModelCount)
            {
                spawnTimer.UpdateTimer();

                if (spawnTimer.Test())
                {
                    modelCounter++;
                    SpawnModel();
                    spawnTimer.ResetToZero();
                }
            }
            else
            {
                finished = true;
            }
        }
        public override void Shoot()
        {
            if (shootTimer.Test())
            {
                int deflection = rand.Next(0, (int)Physics.GetDistance(position, GameGlobals.playerJet.position) / 4);

                if (rand.Next(0, 2) == 0)
                {
                    deflection = -deflection;
                }

                Bullet2D bullet =
                    new ImprovedBullet(new Vector2(position.X, position.Y),
                                       this, new Vector2(GameGlobals.playerJet.position.X + deflection,
                                                         GameGlobals.playerJet.position.Y), rotation, 8.0f);

                GameGlobals.PassBullet(bullet);
                shootEffect.Play();
                shootTimer.ResetToZero();
            }

            if (missileShootCooldown.Test())
            {
                int deflection = rand.Next(0, (int)Physics.GetDistance(position, GameGlobals.playerJet.position) / 4);

                if (rand.Next(0, 2) == 0)
                {
                    deflection = -deflection;
                }

                float degree = MathHelper.ToDegrees(rotation);

                float leftFirstX = 0, leftFirstY = 0;
                float rightFirstX = 0, rightFirstY = 0;

                float leftSecondX  = 0;
                float leftSecondY  = 0;
                float rightSecondX = 0;
                float rightSecondY = 0;

                float difference = 15;

                if (degree < 45 || (degree >= 150 && degree < 260) && degree > 0)
                {
                    leftFirstX   = position.X - dimension.X / 2;
                    rightFirstX  = position.X + dimension.X / 2;
                    leftFirstY   = rightFirstY = position.Y;
                    leftSecondX  = leftFirstX + difference;
                    leftSecondY  = leftFirstY;
                    rightSecondX = rightFirstX - difference;
                    rightSecondY = rightFirstY;
                }
                else if (degree == 45 || degree > -60 && degree < 0)
                {
                    leftFirstX   = position.X - dimension.X / 2 + 10;
                    rightFirstX  = position.X + dimension.X / 2 - 10;
                    leftFirstY   = rightFirstY = position.Y + 10;
                    leftSecondX  = leftFirstX + difference;
                    leftSecondY  = leftFirstY + difference;
                    rightSecondX = rightFirstX - difference;
                    rightSecondY = rightFirstY - difference;
                }
                else if (degree > 45 && degree < 150 || degree > 260 || (degree < 0 && degree < -60))
                {
                    leftFirstX   = rightFirstX = position.X;
                    leftFirstY   = position.Y + dimension.Y / 2;
                    rightFirstY  = position.Y - dimension.Y / 2;
                    leftSecondX  = leftFirstX + difference;
                    leftSecondY  = leftFirstY;
                    rightSecondX = rightFirstX - difference;
                    rightSecondY = rightFirstY;
                    leftSecondX  = leftFirstX;
                    leftSecondY  = leftFirstY + difference;
                    rightSecondX = rightFirstX;
                    rightSecondY = rightFirstY - difference;
                }

                Bullet2D leftMissileLeft =
                    new Missile(new Vector2(leftFirstX, leftFirstY),
                                this, new Vector2(GameGlobals.playerJet.position.X + deflection,
                                                  GameGlobals.playerJet.position.Y), rotation, 6.0f);

                Bullet2D rightMissileRight =
                    new Missile(new Vector2(rightFirstX, rightFirstY),
                                this, new Vector2(GameGlobals.playerJet.position.X + deflection,
                                                  GameGlobals.playerJet.position.Y), rotation, 6.0f);

                Bullet2D leftMissileSecond =
                    new Missile(new Vector2(leftSecondX, leftSecondY),
                                this, new Vector2(GameGlobals.playerJet.position.X + deflection,
                                                  GameGlobals.playerJet.position.Y), rotation, 6.0f);

                Bullet2D rightMissileSecond =
                    new Missile(new Vector2(rightSecondX, rightSecondY),
                                this, new Vector2(GameGlobals.playerJet.position.X + deflection,
                                                  GameGlobals.playerJet.position.Y), rotation, 6.0f);

                GameGlobals.PassBullet(leftMissileLeft);
                GameGlobals.PassBullet(rightMissileRight);
                GameGlobals.PassBullet(leftMissileSecond);
                GameGlobals.PassBullet(rightMissileSecond);
                missileEffect.Play();
                missileShootCooldown.ResetToZero();
            }
        }