Beispiel #1
0
 public void Update(GameTime gameTime)
 {
     dynamicLoader.Load(game.Camera.RightBound + LoadMargin); // We set the load range to 100.
     if (Mario.Position.X < game.Camera.LeftBound)
     {
         Mario.Position = new Vector2(game.Camera.LeftBound, Mario.Position.Y);
     }
     for (int i = (StaticObjects.Count - 1); i >= 0 && i < StaticObjects.Count; i--)
     {
         IStatic obj = StaticObjects[i];
         BoundaryCheck(obj);
         obj.Update(gameTime);
         if (obj.ObjState == ObjectState.Destroy)
         {
             DestroyFromManager(obj);
         }
         if (obj.ObjState == ObjectState.NonCollidable)
         {
             MoveToNonCollidable(obj);
         }
     }
     for (int i = (DynamicObjects.Count - 1); i >= 0 && i < DynamicObjects.Count; i--)
     {
         IDynamic obj = DynamicObjects[i];
         BoundaryCheck(obj);
         obj.Update(gameTime);
         if (obj.ObjState == ObjectState.Destroy)
         {
             DestroyFromManager(obj);
         }
         if (obj.ObjState == ObjectState.NonCollidable)
         {
             MoveToNonCollidable(obj);
         }
     }
     for (int i = (NonCollidableObjects.Count - 1); i >= 0 && i < NonCollidableObjects.Count; i--)
     {
         BoundaryCheck(NonCollidableObjects[i]);
         IObject obj;
         if (NonCollidableObjects[i] is IStatic)
         {
             obj = (IStatic)NonCollidableObjects[i];
             ((IStatic)obj).Update(gameTime);
         }
         else
         {
             obj = (IDynamic)NonCollidableObjects[i];
             ((IDynamic)obj).Update(gameTime);
         }
         if (obj.ObjState == ObjectState.Destroy)
         {
             DestroyFromNonCollidable(obj);
         }
         if (obj.ObjState == ObjectState.Normal)
         {
             MoveToCollidable(obj);
         }
     }
 }
Beispiel #2
0
        public void Update(GameTime gameTime)
        {
            if (Background != null)
            {
                Background.Update(gameTime);
            }
            viewEvent = ViewEvent.None;
            if (Input.Pause && !paused && winDelay <= 0)
            {
                paused = true;
            }
            else if (Input.Pause && paused)
            {
                paused = false;
            }

            if (paused == true)
            {
                pauseMenu.Update(gameTime);
                switch (pauseMenu.Event.Event)
                {
                case ViewEvent.EventType.Back:
                    paused = false;
                    break;

                case ViewEvent.EventType.ChangeView:
                    viewEvent = pauseMenu.Event;
                    paused    = false;
                    break;

                default:
                    break;
                }
            }
            else if (winDelay > 3)
            {
                winMenu.Update(gameTime);
                switch (winMenu.Event.Event)
                {
                case ViewEvent.EventType.ChangeView:
                    viewEvent = winMenu.Event;
                    break;

                default:
                    break;
                }
            }
            else if (gameOver)
            {
                gameOverMenu.Update(gameTime);
                switch (gameOverMenu.Event.Event)
                {
                case ViewEvent.EventType.ChangeView:
                    viewEvent = gameOverMenu.Event;
                    gameOver  = false;
                    break;

                default:
                    break;
                }
            }
            else
            {
                activeEnemies = aliveEnemies.Where(enemy => enemy.Delay < time).ToList();

                activeEnemies.ForEach(x => x.Update(gameTime));

                player.Update(gameTime);

                List <Enemy>  deletedEnemies = new List <Enemy>();
                List <Bullet> deletedBullets = new List <Bullet>();



                activeEnemies.ForEach(enemy => {
                    player.Bullets.ForEach(bullet => {
                        if (enemy.Bounds.Intersects(bullet.Bounds))
                        {
                            enemy.Health -= bullet.Damage;
                            if (enemy.Health <= 0)
                            {
                                score += enemy.Value * multiplier;
                                deletedEnemies.Add(enemy);
                                deletedBullets.Add(bullet);
                            }
                            else
                            {
                                deletedBullets.Add(bullet);
                            }
                        }
                    });
                    if (player.Bounds.Intersects(enemy.Bounds))
                    {
                        gameOver = true;
                    }
                    Rectangle tmpRect = new Rectangle((int)-enemy.Width, (int)-enemy.Height, (int)(Globals.SCREEN_WIDTH + enemy.Width), (int)(Globals.SCREEN_HEIGHT + enemy.Height));
                    if (!(tmpRect.Contains(enemy.Bounds) || tmpRect.Intersects(enemy.Bounds)))
                    {
                        deletedEnemies.Add(enemy);
                    }
                });

                deletedEnemies.ForEach(enemy => aliveEnemies.Remove(enemy));
                deletedBullets.ForEach(bullet => player.Bullets.Remove(bullet));

                time += gameTime.ElapsedGameTime.Milliseconds / 1000f;
                scoreUi.DisplayText      = "Score: " + score.ToString();
                multiplierUi.DisplayText = "x" + multiplier.ToString();
                multiplierUi.X           = scoreUi.X + scoreUi.Width + 10;

                winScoreText.DisplayText = "Your score: " + score.ToString();

                if (aliveEnemies.Count == 0)
                {
                    winDelay += gameTime.ElapsedGameTime.Milliseconds / 1000f;
                }
            }
        }