public override void Update(GameTime gameTime) { if (!drag) { if (Globals.mouseState.LeftButtonHold && startDragGridPosition == Grid.ToGridLocation(Globals.mouseState.Position.ToPoint(), gridLocation, Globals.TileDimensions) && Main.WindowRectangle.Contains(Globals.mouseState.Position)) { dragHoldTimer += (float)gameTime.ElapsedGameTime.TotalMilliseconds; if (!(dragHoldTimer < DRAG_HOLD_TIME)) { drag = true; dragHoldTimer = 0; } } } if (Globals.mouseState.LeftButtonPressed && Main.WindowRectangle.Contains(Globals.mouseState.Position)) { if (selectedCharacter.Hitbox.Contains(Globals.mouseState.Position)) { drag = true; } else { foreach (Character c in Armies.army) { if (c.Hitbox.Contains(Globals.mouseState.Position)) { SelectCharacter(c); } } } // Check switchable unit foreach (KeyValuePair <Character.Rank, Sprite> entry in armyDict) { Rectangle hitbox = new Rectangle((int)entry.Value.position.X, (int)entry.Value.position.Y, entry.Value.sourceRectangle.Width, entry.Value.sourceRectangle.Height); if (hitbox.Contains(Globals.mouseState.Position)) { if (selectedCharacter.special == Character.Special.None) { if (selectedCharacter.rank == entry.Key) { ChangeCharacter(entry.Key); } } else { switch (entry.Key) { case Character.Rank.Spy: case Character.Rank.Miner: case Character.Rank.Healer: ChangeCharacter(entry.Key); break; case Character.Rank.Bomb: if (selectedCharacter.rank == Character.Rank.Bomb) { ChangeCharacter(entry.Key); } break; } } } } if (LeftNextButtonHitbox.Contains(Globals.mouseState.Position)) { switch (currentArmy) { case Character.Army.Normal: SetArmyDictionary(Character.Army.Sea); break; case Character.Army.Tiki: SetArmyDictionary(Character.Army.Normal); break; case Character.Army.Sea: SetArmyDictionary(Character.Army.Tiki); break; } } if (RightNextButtonHitbox.Contains(Globals.mouseState.Position)) { switch (currentArmy) { case Character.Army.Normal: SetArmyDictionary(Character.Army.Tiki); break; case Character.Army.Tiki: SetArmyDictionary(Character.Army.Sea); break; case Character.Army.Sea: SetArmyDictionary(Character.Army.Normal); break; } } } if (drag && Globals.mouseState.LeftButtonReleased) { Vector2 mouseGridPosition = (Grid.ToGridLocation(Globals.mouseState.Position.ToPoint(), gridLocation, Globals.TileDimensions) * Globals.TileDimensions + gridLocation).ToVector2(); if (GridArea.Contains(mouseGridPosition)) { bool overlap = false; // Check for overlapping with another character foreach (Character c in Armies.army) { if (c.position == mouseGridPosition) { overlap = true; // Swap drag Character with overlap character c.position = selectedCharacter.position; selectedCharacter.position = mouseGridPosition; break; } } if (!overlap) { selectedCharacter.position = mouseGridPosition; } } drag = false; } statsUI.UpdateAnimation(gameTime); statsUI.UpdateWeaponChanging(); }
public override void Update(GameTime gameTime) { if (selected != -1 && Armies.army[selected].IsDead) { selected = -1; } if (!IsTurn) { buttons[0].enabled = false; } else { buttons[0].enabled = true; } // UPDATE ANIMTION if (moveArrows != null) { for (int i = 0; i < moveArrows.Count; i++) { moveArrows[i].Update(gameTime); } } if (attackIcons != null) { for (int i = 0; i < attackIcons.Count; i++) { attackIcons[i].Update(gameTime); } } if (selected >= 0 && canAttackThis != null && canAttack[selected]) { for (int i = 0; i < canAttackThis.Count; i++) { Character c = Armies.opponentArmy[canAttackThis[i]]; c.UpdateSpriteSheetAnimation(gameTime); if (c.sprite.CurrentFrame == 1) { c.sprite.CurrentFrame = 2; } } } // END UPDATE ANIMATION // UNFINISHED WIN/LOSE DEFINITION/EFFECT if (Armies.army[0].IsDead || Armies.opponentArmy[0].IsDead) { StateManager.ChangeState(Settings.STATES.Result); } // END UNFINISHED WIN/LOSE DEFINITION/EFFECT // CONNECTION LOST if (Globals.multiplayerConnection.ConnectionLost) { StateManager.ChangeState(Settings.STATES.Result); } // END CONNECTION LOST if (IsTurn && !Globals.multiplayerConnection.IsWaitingForResponse) { CheckIfCanAttack(); if (selected != -1) { if (Globals.mouseState.LeftButtonPressed && Main.WindowRectangle.Contains(Globals.mouseState.Position)) { bool contains = false; contains = TestForMove(gameTime); if (!contains) { contains = TestForAttack(gameTime); } if (!contains) { canMoveTo = null; } moveArrows = null; attackIcons = null; } } if (Globals.mouseState.LeftButtonPressed && Main.WindowRectangle.Contains(Globals.mouseState.Position)) { SelectUnit(gameTime); } } if (StateManager.GetState(1) is GameState) { ((GameState)StateManager.GetState(1)).Update(gameTime); } Globals.multiplayerConnection.Update(gameTime); statsUI.UpdateAnimation(gameTime); if (selected > -1 && !canAttack[selected]) { canAttackThis = null; } }