Exemple #1
0
        private void updateGamePlaying(GameTime gameTime)
        {
            // TODO: Add your update logic here
            saveScores = true;

            arwing.Update(ks, GraphicsDevice.Viewport, rnd);

            for (int i = 0; i < arwing.Bullets.Count; i++)
            {
                if (arwing.Bullets[i].Position.Y > GraphicsDevice.Viewport.Height)
                {
                    arwing.Bullets.RemoveAt(i);
                    i--;
                }
                else
                {
                    //another for loop for enemies
                    for (int j = 0; j < enemies.Count; j++)
                    {
                        if (arwing.Bullets[i].Hitbox.Intersects(enemies[j].Hitbox))
                        {
                            score += (int)(((float)enemies[j].Score / enemies[j].Scale) * arwing.Bullets[i].multiplier);
                            //stop drawing enemy
                            enemies.RemoveAt(j);
                            j--;

                            //stop drawing bullet
                            arwing.Bullets.RemoveAt(i);
                            i--;

                            break;
                        }
                    }
                }
            }

            for (int i = 0; i < enemies.Count; i++)
            {
                enemies[i].Update(gameTime);
                for (int k = 0; k < enemies[i].Bullets.Count; k++)
                {
                    if (arwing.Hitbox.Intersects(enemies[i].Bullets[k].Hitbox))
                    {
                        lives--;
                        enemies[i].Bullets.Remove(enemies[i].Bullets[k]);
                        if (lives == 0)
                        {
                            gameState = GameState.GameOver;
                        }
                    }
                }
            }

            if (enemies.Count == 0)
            {
                //count a timespan
                delay      += gameTime.ElapsedGameTime;
                arwing.stop = true;
                if (delay > TimeSpan.FromMilliseconds(2000))
                {
                    arwing.stop = false;
                    //if timespan > some amount of time
                    level++;

                    delay = TimeSpan.Zero;
                    Spawn();
                }
            }
        }