protected override void Update(GameTime gameTime) { timer += (float)gameTime.ElapsedGameTime.TotalMilliseconds / 1000; timerInt = (int)timer; if (timerInt >= 5) { //Character p = new Character(this, new Vector3(1.25f, 0, 1.25f), new Vector3(0, 90, 0), new Vector3(0, 1, 0), ImageLibrary.getInstance().getImage("Player"), cam, path.origin); //enemys.Add(p); timer = 0; } this.keyboard.Update(); enemysArray = enemys.ToArray(); //Erro ao utilizar foreach no Update. Melhor Solução foi esta. for (int i = 0; i < enemysArray.Length; i++) { enemysArray[i].Update(gameTime); } if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed) this.Exit(); if (this.keyboard.IsKeyDown(Keys.P)) { Random rand = new Random(); int x = rand.Next(3, 6); int y = rand.Next(0, 6); this.path.Search(this.grid.nodes[0, 0], this.grid.nodes[x, y], ref this.grid, this, ref allTrees, ref this.nodePath); ArrangeNodes(ref this.nodePath); player.setPosition(new Vector3(0, 1, 0)); player.target = path.origin; } if (this.keyboard.IsKeyDown(Keys.Space)) //Ação! { if (activeNode.state == nodeState.OPEN) { towers.Add(new Tree(this, new Vector3(1, 1, 1), new Vector3(0, 0, 0), new Vector3(activeNode.x * 2.5f, 0, activeNode.y * 2.5f), cam)); } } if (this.keyboard.IsKeyDown(Keys.Down)) { if (activeNode.y < 5) { activeNode.ChangeTexture(ImageLibrary.getInstance().getImage("Floor")); int x = activeNode.x; int y = activeNode.y; activeNode = grid.nodes[x, y + 1]; activeNode.ChangeTexture(ImageLibrary.getInstance().getImage("FloorSelected")); } } if (this.keyboard.IsKeyDown(Keys.Up)) { if (activeNode.y > 0) { activeNode.ChangeTexture(ImageLibrary.getInstance().getImage("Floor")); int x = activeNode.x; int y = activeNode.y; activeNode = grid.nodes[x, y - 1]; activeNode.ChangeTexture(ImageLibrary.getInstance().getImage("FloorSelected")); } } if (this.keyboard.IsKeyDown(Keys.Right)) { if (activeNode.x < 5) { activeNode.ChangeTexture(ImageLibrary.getInstance().getImage("Floor")); int x = activeNode.x; int y = activeNode.y; activeNode = grid.nodes[x + 1, y]; activeNode.ChangeTexture(ImageLibrary.getInstance().getImage("FloorSelected")); } } if (this.keyboard.IsKeyDown(Keys.Left)) { if (activeNode.x > 0) { activeNode.ChangeTexture(ImageLibrary.getInstance().getImage("Floor")); int x = activeNode.x; int y = activeNode.y; activeNode = grid.nodes[x - 1, y]; activeNode.ChangeTexture(ImageLibrary.getInstance().getImage("FloorSelected")); } } foreach (Tree currentTree in allTrees) { currentTree.Update(); } cam.Update(); this.keyboard.LateUpdate(); base.Update(gameTime); }