public MainWindow() : base("XChess", 640, 480) { this.VSync = VSyncMode.Off; Board board = Board.Initial; Game game = new AIGame(0, board); this.Control = this._LayerContainer = new LayerContainer((this._View = new GameBoardView(game))); this.WindowState = WindowState.Maximized; }
private void UpdateInput() { MouseState mouseState = Mouse.GetState(); // SELECT if (AIGame.LeftButtonJustPressed()) { bool was_selected = false; foreach (AIObject aiobj in _aiobjects) { Ray pickRay = MathExtra.CalculateCursorRay(AIGame.camera.ProjectionMatrix, AIGame.camera.ViewMatrix); float?rayLength = aiobj.BoundingBox.Intersects(pickRay); if (rayLength != null) { if (Keyboard.GetState().IsKeyDown(Microsoft.Xna.Framework.Input.Keys.LeftShift)) { SelectTeam(aiobj.Team.TeamType); aiobj.Team.OperateAsAUnit = true; } else { Select(aiobj); } was_selected = true; } } if (!was_selected) { ClearSelect(); } } // MOVE OR ATTACK if (AIGame.RightButtonJustPressed() && AIGame.camera.CurrentBehavior == Camera.Behavior.FreeView) { if (_selectedObject == null) { return; } AIObject temp_aiobj = null; float? rayLength; foreach (AIObject aiobj in _aiobjects) { Ray pickRay = MathExtra.CalculateCursorRay(AIGame.camera.ProjectionMatrix, AIGame.camera.ViewMatrix); rayLength = aiobj.BoundingBox.Intersects(pickRay); if (rayLength != null) { temp_aiobj = aiobj; } } _selectedObject.CancelPreviousActions(); // only move if (temp_aiobj == null) { _selectedObject.MoveTo(AIGame.terrain.groundCursorPosition * Settings.TERRAIN_TEXTURE_SIZE); if (_selectedObject.IsLeader && _selectedTeam.KeepFormation && _selectedTeam.Formation != AIFormation.Spread) { _selectedTeam.ToFormation(_selectedTeam.Formation); } if (_selectedTeam.KeepFormation && _selectedObject == _selectedTeam.Leader) { if (_selectedTeam.Leader.HasJustStopped) { _selectedTeam.ToFormation(_selectedTeam.Formation); } } _selectedObject.IsFollowing = false; _selectedObject.Target = null; } // attack else { if (_selectedObject.Team != temp_aiobj.Team) { _selectedObject.Attack(temp_aiobj); } else { _selectedObject.Follow(temp_aiobj); } } } }