示例#1
0
 private void HandleEnemies()
 {
     //create some random enemies
     if (lastSatelliteSpawn + satelliteCreateDelay <= (float)time)
     {
         Enemy enemy = new Enemy(this, satelliteModel, satelliteTexture);
         enemyList.Add(enemy);
         lastSatelliteSpawn = (float)time;
         if (satelliteCreateDelay > 0.4f)
         {
             satelliteCreateDelay -= 0.1f;
         }
     }
     if (lastUfoSpawn + ufoCreateDelay <= (float)time)
     {
         Ufo ufo = new Ufo(this, ufoModel, ufoTexture);
         ufoList.Add(ufo);
         lastUfoSpawn = (float)time;
         if (ufoCreateDelay > 0.4f)
         {
             ufoCreateDelay -= 0.1f;
         }
     }
     //checksatellite updates
     for (int e = 0; e < enemyList.Count; e++)
     {
         enemyList[e].Update();
         enemyList[e].UpdateCollision(enemyList, e);
         //check for death
         if (enemyList[e].shouldDie)
         {
             particleEngine = new ParticleEngine(particleTextures, enemyList[e].position, this);
             emitters.Add(particleEngine);
             enemyList.RemoveAt(e);
             e--;
             enemiesKilled++;
         }
     }
     //check for ufo updates
     for (int u = 0; u < ufoList.Count; u++)
     {
         ufoList[u].Update();
         ufoList[u].UpdateCollision(ufoList, u);
         //check for death
         if (ufoList[u].shouldDie)
         {
             particleEngine = new ParticleEngine(particleTextures, ufoList[u].position, this);
             emitters.Add(particleEngine);
             ufoList.RemoveAt(u);
             u--;
             enemiesKilled++;
         }
     }
 }
示例#2
0
 public void Update()
 {
     if (spawnTime + 3 <= game.time)
     {
         shouldDie = true;
         ParticleEngine particleEngine = new ParticleEngine(game.particleTextures, position, game);
         game.emitters.Add(particleEngine);
     }
     position.Z  = 0;
     position   -= flyDir * 2;
     physicsBody = new BoundingBox(position - new Vector3(1, 1, 1), position + new Vector3(1, 1, 1));
 }
 public void Update()
 {
     //if close enough to player, then he probaply touches, so pickup
     if ((game.player.position - position).Length() <= 5)
     {
         shouldDie           = true;
         game.player.health += 5;
         //particle engine takes list of textures. need to do that even with one texture doh -.-
         List <Texture2D> hearts = new List <Texture2D>();
         hearts.Add(game.heartParticle);
         ParticleEngine heartParticles = new ParticleEngine(hearts, position, game);
         game.emitters.Add(heartParticles);
     }
     if (spawnTime + 10 < game.time)
     {
         shouldDie = true;
         //particle engine takes list of textures. need to do that even with one texture doh -.-
         List <Texture2D> hearts = new List <Texture2D>();
         hearts.Add(game.heartParticle);
         ParticleEngine heartParticles = new ParticleEngine(hearts, position, game);
         game.emitters.Add(heartParticles);
     }
 }
示例#4
0
        //---------------------main game loop----------------------//
        protected override void Update(GameTime gameTime)
        {
            //check if escape is pressed, then exit the game
            if (Keyboard.GetState().IsKeyDown(Keys.Escape))
            {
                Exit();
            }
            //Game1.time is counting elapsed time...
            time += gameTime.ElapsedGameTime.TotalSeconds;
            //err... handle touch input?
            HandleInput();
            //randomize background color
            RandomBackground();
            //if we are in menu
            if (gameStage == 0)
            {
                score = 0;
                combo = 0;
                if (player.isPressed || mouseClicking)
                {
                    gameStage = 1;
                }
            }
            #region in-game
            //this one is for in-game
            else if (gameStage == 1)
            {
                //handle combo actions
                if (lastHitCombo + 2 < time)
                {
                    combo = 0;
                }
                //get screen width and height
                SCREEN_HEIGHT = _viewport.Height;
                SCREEN_WIDTH  = _viewport.Width;
                //update player
                player.position.X -= joystick_right.dir.X * player.speed;
                player.position.Y += joystick_right.dir.Y * player.speed;
                //check for borders
                Vector3 var1 = _viewport.Unproject(new Vector3(0, 0, 0), projection, view, world);                        //these two first are finding what cordinates in world space are current (0,0)
                Vector3 var2 = _viewport.Unproject(new Vector3(0, 0, 100), projection, view, world);                      //meaning the left up corner
                Vector3 var3 = _viewport.Unproject(new Vector3(SCREEN_WIDTH, SCREEN_HEIGHT, 0), projection, view, world); //and these two are doing the same for right down corner
                Vector3 var4 = _viewport.Unproject(new Vector3(SCREEN_WIDTH, SCREEN_HEIGHT, 100), projection, view, world);
                upLeft    = 1000 * (var1 - var2);                                                                         //create Vector3 for up_left corner
                downRight = 1000 * (var3 - var4);                                                                         //create Vector3 for down_right corner

                //clamp player position within borders
                player.position.X = MathHelper.Clamp(player.position.X, upLeft.X, downRight.X);
                player.position.Y = MathHelper.Clamp(player.position.Y, downRight.Y, upLeft.Y);
                HandleEnemies();
                player.Update();//position is not done, update it...

                if (emitters.Count > 0)
                {
                    for (int emitter = 0; emitter < emitters.Count; emitter++)
                    {
                        emitters[emitter].Update();
                        if (emitters[emitter].shouldDie)
                        {
                            emitters.RemoveAt(emitter);
                            emitter--;
                        }
                    }
                }
                updateBullets();
                if (heartList.Count > 0)
                {
                    for (int heart = 0; heart < heartList.Count; heart++)
                    {
                        heartList[heart].Update();
                        if (heartList[heart].shouldDie)
                        {
                            heartList.RemoveAt(heart);
                            heart--;
                            pickup.Play(0.8f, 0, 0);
                        }
                    }
                }
                //game is over, do some shit and goto gameStage 2
                if (player.health <= 0)
                {
                    gameStage    = 2;
                    timeWhenDied = (float)time;
                }
            }
            #endregion
            #region game-over
            //this one is gameover screen
            else if (gameStage == 2)
            {
                if (emitters.Count > 0)
                {
                    for (int emitter = 0; emitter < emitters.Count; emitter++)
                    {
                        emitters[emitter].Update();
                        if (emitters[emitter].shouldDie)
                        {
                            emitters.RemoveAt(emitter);
                            emitter--;
                        }
                    }
                }
                //destory all existing hearts too
                List <Texture2D> hearts = new List <Texture2D>();
                hearts.Add(heartParticle);
                for (int h = 0; h < heartList.Count; h++)
                {
                    ParticleEngine heartParticles = new ParticleEngine(hearts, heartList[h].position, this);
                    emitters.Add(heartParticles);
                    heartList.RemoveAt(h);
                    h--;
                }
                //kill all satellites
                for (int e = 0; e < enemyList.Count; e++)
                {
                    particleEngine = new ParticleEngine(particleTextures, enemyList[e].position, this);
                    emitters.Add(particleEngine);
                    enemyList.RemoveAt(e);
                    e--;
                    enemiesKilled++;
                }//kill all UFOs
                for (int u = 0; u < ufoList.Count; u++)
                {
                    particleEngine = new ParticleEngine(particleTextures, ufoList[u].position, this);
                    emitters.Add(particleEngine);
                    ufoList.RemoveAt(u);
                    u--;
                    enemiesKilled++;
                }
                if (timeWhenDied + 5 <= time)
                {
                    gameStage = 0;
                }
                end.Play(0.1f, -.5f, -.5f);
                player.health        = 100;
                satelliteCreateDelay = 4f;
                ufoCreateDelay       = 6f;
            }
            #endregion
            base.Update(gameTime);
        }