public void Draw(SpriteBatch a_spritebatch, GameAssets a_gameAssets, ModelClasses.Game a_game, DebugView a_debugView, ModelClasses.Save a_save) { a_spritebatch.Begin(); //Checks debugoptions and checks the options in Debug menu if they return true else unchecks them CheckState(a_debugView); //Draws differint screens depending on if u won or lost if (a_game.m_state == ModelClasses.Game.GameState.GameOver) { if (a_game.HasWon(a_game.m_player)) { m_menuState = ViewClasses.Menu.Menu.MenuState.Win; } else { m_menuState = ViewClasses.Menu.Menu.MenuState.Lose; } } //Draws the pause overlay that is transparent (black) if state is Pause ^_^ if (a_game.m_state == ModelClasses.Game.GameState.Pause) { DrawObject(a_spritebatch, a_gameAssets.m_pause, m_pause, Color.White); } //Draws the menu DrawMenu(a_spritebatch, a_game, a_gameAssets, a_save); a_spritebatch.End(); }
private void DrawMenu(SpriteBatch a_spriteBatch, ModelClasses.Game a_game, GameAssets a_gameAssets, ModelClasses.Save a_save) { if (m_menuState == MenuState.Main || m_menuState == MenuState.PreGame || m_menuState == MenuState.InGameMenu || m_menuState == MenuState.Options || m_menuState == MenuState.DebugMenu || m_menuState == MenuState.Save || m_menuState == MenuState.Load || m_menuState == MenuState.Win || m_menuState == MenuState.Lose) { if (a_game.m_state == ModelClasses.Game.GameState.Main) { DrawObject(a_spriteBatch, a_gameAssets.m_main, m_mainBackground, Color.White); } DrawObject(a_spriteBatch, a_gameAssets.m_background, m_menu, Color.White); } if (m_menuState == MenuState.Main) { //Draws the items in the main screen DrawMenuItems(a_spriteBatch, a_gameAssets, m_mainButtons); } else if (m_menuState == MenuState.PreGame) { DrawMenuItems(a_spriteBatch, a_gameAssets, null); } else if (m_menuState == MenuState.InGameMenu) { //Draws the items in menu screen DrawMenuItems(a_spriteBatch, a_gameAssets, m_menuButtons); } else if (m_menuState == MenuState.Options) { //Draws the items in options screen DrawMenuItems(a_spriteBatch, a_gameAssets, m_optionsButtons); } else if (m_menuState == MenuState.DebugMenu) { //Draws the items in debug screen DrawMenuItems(a_spriteBatch, a_gameAssets, m_checkBoxes); } else if (m_menuState == MenuState.Save) { //Draws the saveslots DrawMenuItems(a_spriteBatch, a_gameAssets, m_saves); } else if (m_menuState == MenuState.Load) { DrawMenuItems(a_spriteBatch, a_gameAssets, m_loaded); } else if (m_menuState == MenuState.Win) { DrawMenuItems(a_spriteBatch, a_gameAssets, null); } else if (m_menuState == MenuState.Lose) { DrawMenuItems(a_spriteBatch, a_gameAssets, null); } }
private void CameraInputHandling(ModelClasses.Game a_game, ViewClasses.Camera a_camera) { if (m_input.movCameraLeft() || m_input.m_mouse.m_mouseState.X <= 0 + a_camera.m_cameraBorder) { //if it may move left if (a_camera.m_focusPos.X > 0) { a_camera.MoveCameraLeft(); } } else if (m_input.movCameraRight() || m_input.m_mouse.m_mouseState.X >= MasterController.m_windowWidth - a_camera.m_cameraBorder) { //if it may move right if (a_camera.m_focusPos.X < a_game.m_map.m_mapWidth) { a_camera.MoveCameraRight(); } } if (m_input.movCameraForward() || m_input.m_mouse.m_mouseState.Y <= 0 + a_camera.m_cameraBorder) { //if it may move forward if (a_camera.m_focusPos.Y < a_game.m_map.m_mapDepth) { a_camera.MoveCameraForward(); } } else if (m_input.movCameraBackward() || m_input.m_mouse.m_mouseState.Y >= MasterController.m_windowHeight - a_camera.m_cameraBorder) { //if it may move backward if (a_camera.m_focusPos.Y > 0) { a_camera.MoveCameraBackward(); } } if (m_input.moveCameraDown()) { a_camera.MoveCameraDown(); } else if (m_input.moveCameraUp()) { a_camera.MoveCameraUp(); } if (m_input.KeyPressed(m_input.m_home)) { a_camera.ResetCamera(); } }
//draws HUD public void Draw(SpriteBatch a_spritebatch, GameAssets a_gameAssets, ModelClasses.Game a_game) { //Put the spritebatch Begin here, so it doesn't has to be called 5 times :p since it sets some stuff, that's on long term bad! a_spritebatch.Begin(); DrawHUDBackground(a_spritebatch, a_gameAssets); DrawActionbox(a_spritebatch, a_gameAssets, a_game); DrawTooltip(a_spritebatch, a_gameAssets, a_game); DrawInfo(a_spritebatch, a_gameAssets, a_game.m_player); DrawPortrait(a_spritebatch, a_gameAssets, a_game); DrawResourcesInfo(a_game.m_player, a_spritebatch, a_gameAssets); a_spritebatch.End(); }
public void DoInputControl(GraphicsDevice a_graphics, ref ModelClasses.Game a_game, ref ViewClasses.GameView a_gameView, ViewClasses.DebugView a_debugView, ViewClasses.Menu.Menu a_menu, ViewClasses.GameAssets a_gameAssets) { m_input.GetKeyboardMouseState(); if (a_game.m_state == ModelClasses.Game.GameState.Game) { CameraInputHandling(a_game, a_gameView.m_camera); MouseHandling(a_graphics, a_game, a_gameView); HUDHandling(a_graphics, a_game, a_gameView); } MenuHandling(a_graphics, ref a_game, a_menu, a_debugView, a_gameAssets, ref a_gameView); }
private void DrawGame(ModelClasses.Game a_game, GameAssets a_gameAsset, float a_elapsedTime) { //Draws the world objects DrawWorldObjects(a_game.m_map.m_worldObjects); foreach (Player player in a_game.m_allPlayers) { //If the player has surrendered, no need to go inside the function and change color on all models e.t.c.! if (!player.m_surrendered) { DrawPlayer(player, a_gameAsset); } } DrawParticles(a_game, a_gameAsset, a_elapsedTime); }
public void Draw(SpriteBatch a_spriteBatch, GameAssets a_gameAssets, ModelClasses.Game a_game, GraphicsDevice a_gd, DebugView a_debugView, ModelClasses.Save a_save, float a_elapsedTime) { //Sets the view matrix that is used by the shader m_camera.SetViewMatrix(); m_camera.SetElapsedTime(a_elapsedTime); //DrawBackground(a_gameAssets.m_ground); //Draws a unit foreach unit added to a_game.m_units List of type Unit. m_mapTransformer.DrawMap(a_gd, m_camera); DrawGame(a_game, a_gameAssets, a_elapsedTime); DrawSelectionBorder(a_game.m_player, a_gd); //Draws HUD m_HUD.Draw(a_spriteBatch, a_gameAssets, a_game); }
/// <summary> /// Allows the game to perform any initialization it needs to before starting to run. /// This is where it can query for any required services and load any non-graphic /// related content. Calling base.Initialize will enumerate through any components /// and initialize them as well. /// </summary> protected override void Initialize() { base.Initialize(); m_mapSize = 48; graphics.PreferredBackBufferHeight = 800; graphics.PreferredBackBufferWidth = 1024; if (!m_debugView.m_debugOptions.m_withVS) { graphics.SynchronizeWithVerticalRetrace = false; IsFixedTimeStep = false; } graphics.ApplyChanges(); //graphics.ToggleFullScreen(); m_windowHeight = graphics.GraphicsDevice.Viewport.Height; m_windowWidth = graphics.GraphicsDevice.Viewport.Width; m_save = new ModelClasses.Save(); m_menu = new ViewClasses.Menu.Menu(m_gameAssets, m_save); m_game = new ModelClasses.Game(m_gameAssets, m_mapSize, m_mapSize); m_game.m_state = ModelClasses.Game.GameState.Main; m_gameAssets.LoadHeightMap(graphics.GraphicsDevice, m_game.m_map); m_gameView = new ViewClasses.GameView(graphics.GraphicsDevice, m_gameAssets, m_game); m_game.SetParticleHandler(m_gameView.m_particleHandler); m_gameView.m_mapTransformer.LoadGraphicsContent(graphics.GraphicsDevice); m_debugView.InitilizePositions(); //LOLOL Mouse wasn't visible for a strategy game at first, LOLOL!! IsMouseVisible = true; Window.Title = "Cubes are cute"; ViewClasses.BoundingBoxBuffer.InitiliazeBuffers(graphics.GraphicsDevice); }
public void DrawDebug(GraphicsDevice a_graphics, Camera a_camera, ModelClasses.Game a_game, SpriteBatch spriteBatch, GameAssets a_gameAsset, Input a_input) { if (m_debugOptions.m_unitBoundingBoxDraw) { //draws Bounding boxes on units DrawBBOnUnits(a_game.m_player, a_camera, a_graphics); } if (m_debugOptions.m_gridBoundingBoxDraw) { DrawBBOnGrid(a_game.m_map, a_camera, a_graphics); } spriteBatch.Begin(); if (m_debugOptions.m_showFPS) { //Draws the fps meter DrawFPS(spriteBatch, a_gameAsset.m_normalFont); } if (m_debugOptions.m_showUnitInfo) { //If m_focusedTarget is set to something it will draw the extra info about that target if (a_game.m_player.m_focusedTarget != null) { DrawUnitInfo(a_game.m_player.m_focusedTarget, spriteBatch, a_gameAsset.m_normalFont); } } if (m_debugOptions.m_showMouseWpos) { Vector3?f_point = a_input.GetWorldPosition(a_graphics, a_game.m_groundPlane, a_game.m_map, a_camera, a_input.m_mouse.m_mouseState.X, a_input.m_mouse.m_mouseState.Y); if (f_point.HasValue) { DrawMouseWorldPos(f_point.Value, spriteBatch, a_gameAsset.m_normalFont); } } spriteBatch.End(); }
public GameView(GraphicsDevice graphics, GameAssets a_gameAssets, ModelClasses.Game a_game) { m_camera = new Camera(graphics, a_gameAssets, a_game.m_map); m_pSystem = new ParticleSystem(a_gameAssets); m_particleHandler = new ParticlesHandler(m_pSystem); m_pView = new ParticleView(); m_mapTransformer = new MapTransformer(a_game.m_map); int colorID = 0; //SetModelEffect(a_gameAssets.m_normalGround); colorID++; SetModelEffect(a_gameAssets.c_cube, colorID); SetModelEffect(a_gameAssets.c_barbarian, colorID); SetModelEffect(a_gameAssets.c_extractor, colorID); SetModelEffect(a_gameAssets.c_igloo, colorID); SetModelEffect(a_gameAssets.c_barrack, colorID); colorID++; SetModelEffect(a_gameAssets.m_sparkOfLife, colorID); SetModelEffect(a_gameAssets.m_projektil, colorID); }
private void DrawTooltip(SpriteBatch a_spriteBatch, GameAssets a_gameAssets, ModelClasses.Game a_game) { if (m_tooltipData != null) { //format text string text = String.Format("{0} [{1}]\n\n{2}", m_tooltipData.m_name, m_tooltipData.m_hotkey, m_tooltipData.m_tooltip); //make tooltip area Rectangle tooltipArea = m_tooltipBase; //Multiplication 4 times, I think this is faster (A) ^_^ int f_totalPadding = 2 * m_tooltipPadding; //change tooltip area (depending on the text) //NOTE: if you change the font then you will have to change here aswell (to get the correct length) tooltipArea.X -= (int)(a_gameAssets.m_smallFont.MeasureString(text).X *m_tooltipTextScale) + f_totalPadding; tooltipArea.Y -= (int)(a_gameAssets.m_smallFont.MeasureString(text).Y *m_tooltipTextScale) + f_totalPadding; tooltipArea.Width += (int)(a_gameAssets.m_smallFont.MeasureString(text).X *m_tooltipTextScale) + f_totalPadding; tooltipArea.Height += (int)(a_gameAssets.m_smallFont.MeasureString(text).Y *m_tooltipTextScale) + f_totalPadding; //draw tooltip area //TEMP to see the tooltip area a_spriteBatch.Draw(a_gameAssets.m_button, tooltipArea, Color.DarkOrange); //draw text a_spriteBatch.DrawString(a_gameAssets.m_smallFont, text, new Vector2(tooltipArea.X + m_tooltipPadding, tooltipArea.Y + m_tooltipPadding), Color.Black, 0.0f, m_textOrigin, m_tooltipTextScale, SpriteEffects.None, 0.5f); } }
public void HUDHandling(GraphicsDevice a_graphics, ModelClasses.Game a_game, ViewClasses.GameView a_gameView) { //update HUD //MUST HAPPEN FIRST a_gameView.m_HUD.Update(); #region Actionboxes //if there IS a focusedTarget (otherwise there is no need to go through any of this) if (a_game.m_player.m_focusedTarget != null && a_game.m_player.m_focusedTarget.m_ownerID == a_game.m_player.m_playerID) { #region Hotkeys //HOTKEYS //check hotkeys for (int y = 0; y < a_gameView.m_HUD.m_actionboxButtons.GetLength(1); y++) { for (int x = 0; x < a_gameView.m_HUD.m_actionboxButtons.GetLength(0); x++) { if (m_input.KeyClicked(a_game.m_player.m_focusedTarget.m_actionbox[x, y].m_hotkey)) { //clear all pending buttons a_gameView.m_HUD.ClearPendingButtons(); //add cooldown check here if (a_game.m_player.m_focusedTarget.m_actionbox[x, y].m_type == ModelClasses.ObjectAction.Type.Instant) { //current position point (it needs a point with a value, even if the actual function does not) Vector3?point = a_game.m_player.m_focusedTarget.m_currentposition; //do action a_game.m_player.m_focusedTarget.m_actionbox[x, y].m_function(a_game, point.Value); } else { //set pending a_gameView.m_HUD.m_actionboxButtons[x, y].m_state = Button.BtnState.Pending; if (a_game.m_player.m_focusedTarget.m_actionbox[x, y].m_buildTag && a_game.m_player.m_selectedWorkers >= a_game.m_player.m_focusedTarget.m_actionbox[x, y].m_price) { a_game.m_player.m_tryingToBuild = true; a_gameView.m_HUD.m_visibleBuildingSize = a_game.m_player.m_focusedTarget.m_actionbox[x, y].m_buildSize; a_gameView.m_HUD.m_buildingNeedsWO = a_game.m_player.m_focusedTarget.m_actionbox[x, y].m_lookingForWO; } else if (a_game.m_player.m_focusedTarget.m_actionbox[x, y].m_buildTag && a_game.m_player.m_selectedWorkers < a_game.m_player.m_focusedTarget.m_actionbox[x, y].m_price) { a_gameView.m_HUD.m_actionboxButtons[x, y].NormalState(); //Play some event here... } } }//If key is down but not pressed, do graphics for showing button is pressed! else if (m_input.KeyPressed(a_game.m_player.m_focusedTarget.m_actionbox[x, y].m_hotkey)) { a_gameView.m_HUD.m_actionboxButtons[x, y].Press(); } } } #endregion #region MouseOver //mouse part //if the mouse in in the HUD area if (m_input.m_mouse.m_mouseState.Y > HUD.m_area.Top) { //the visual part //check buttons for (int y = 0; y < a_gameView.m_HUD.m_actionboxButtons.GetLength(1); y++) { for (int x = 0; x < a_gameView.m_HUD.m_actionboxButtons.GetLength(0); x++) { //if inside a button if (a_gameView.m_HUD.m_actionboxButtons[x, y].IsMouseOver(m_input.m_mouse.m_mouseState.X, m_input.m_mouse.m_mouseState.Y)) { //if the button DOES have a function if (a_game.m_player.m_focusedTarget.m_actionbox[x, y].m_function != null) { //set tooltip data a_gameView.m_HUD.m_tooltipData = a_game.m_player.m_focusedTarget.m_actionbox[x, y]; //add cooldown check here if (m_input.mouseLeftButtonDown()) { //press button a_gameView.m_HUD.m_actionboxButtons[x, y].Press(); } } } } } #endregion #region MouseClick //the action part if (m_input.mouseLeftClick()) { //MOUSE CLICKED //check buttons for (int y = 0; y < a_gameView.m_HUD.m_actionboxButtons.GetLength(1); y++) { for (int x = 0; x < a_gameView.m_HUD.m_actionboxButtons.GetLength(0); x++) { //if inside a button if (a_gameView.m_HUD.m_actionboxButtons[x, y].m_rectangle.Contains(m_input.m_mouse.m_mouseState.X, m_input.m_mouse.m_mouseState.Y)) { //if the button DOES have a function if (a_game.m_player.m_focusedTarget.m_actionbox[x, y].m_function != null) { //add cooldown check here //if the action type is instant (no target needed) if (a_game.m_player.m_focusedTarget.m_actionbox[x, y].m_type == ModelClasses.ObjectAction.Type.Instant) { //current position point (it needs a point with a value, even if the actual function does not) Vector3?point = a_game.m_player.m_focusedTarget.m_currentposition; //clear pending buttons a_gameView.m_HUD.ClearPendingButtons(); //do action a_game.m_player.m_focusedTarget.m_actionbox[x, y].m_function(a_game, point.Value); } //if the action needs a target else { //clear pending buttons a_gameView.m_HUD.ClearPendingButtons(); //set pending a_gameView.m_HUD.m_actionboxButtons[x, y].m_state = Button.BtnState.Pending; if (a_game.m_player.m_focusedTarget.m_actionbox[x, y].m_buildTag && a_game.m_player.m_selectedWorkers >= a_game.m_player.m_focusedTarget.m_actionbox[x, y].m_price) { a_game.m_player.m_tryingToBuild = true; a_gameView.m_HUD.m_visibleBuildingSize = a_game.m_player.m_focusedTarget.m_actionbox[x, y].m_buildSize; a_gameView.m_HUD.m_buildingNeedsWO = a_game.m_player.m_focusedTarget.m_actionbox[x, y].m_lookingForWO; } else if (a_game.m_player.m_focusedTarget.m_actionbox[x, y].m_buildTag && a_game.m_player.m_selectedWorkers < a_game.m_player.m_focusedTarget.m_actionbox[x, y].m_price) { a_gameView.m_HUD.m_actionboxButtons[x, y].NormalState(); //Play some event here... } } } } } } } #endregion } } #endregion }
//Draws the portrait private void DrawPortrait(SpriteBatch a_spriteBatch, GameAssets a_gameAssets, ModelClasses.Game a_game) { if (a_game.m_player.m_focusedTarget != null) { //Draws portrait (depending on what type the focused unit is) switch (a_game.m_player.m_focusedTarget.m_type) { case ModelClasses.Units.ThingType.C_Cube: a_spriteBatch.Draw(a_gameAssets.m_cubePortrait, m_portraitArea, Color.White); break; default: break; } } }
public void DrawParticles(ModelClasses.Game a_game, GameAssets a_assets, float a_elapsedTime) { m_pSystem.Update(a_elapsedTime); m_pView.Render(m_camera, m_pSystem, a_assets); }
public void MenuHandling(GraphicsDevice a_graphics, ref ModelClasses.Game a_game, ViewClasses.Menu.Menu a_menu, ViewClasses.DebugView a_debugView, ViewClasses.GameAssets a_gameAssets, ref ViewClasses.GameView a_gameView) { //When menu is opened if (m_input.KeyClicked(m_input.m_f1)) { if (a_menu.m_menuState == Menu.MenuState.None) { a_game.m_state = ModelClasses.Game.GameState.Pause; a_menu.m_menuState = Menu.MenuState.InGameMenu; } else if (a_menu.m_menuState == Menu.MenuState.Main) { //Nothing } //when it's closed else { a_game.m_state = ModelClasses.Game.GameState.Game; } } else { //Checks to se if mouse is in the menu area if (m_input.m_mouse.m_mouseState.Y < Menu.m_menu.Bottom && m_input.m_mouse.m_mouseState.X > Menu.m_menu.Left) { VisualMenuCheck(a_menu); if (m_input.mouseLeftClick()) { if (a_menu.m_menuState == Menu.MenuState.Main) { if (ButtonPress(a_menu.m_mainButtons[0])) { a_menu.m_menuState = Menu.MenuState.PreGame; } else if (ButtonPress(a_menu.m_mainButtons[1])) { a_menu.m_menuState = Menu.MenuState.Load; } else if (ButtonPress(a_menu.m_mainButtons[2])) { a_menu.m_menuState = Menu.MenuState.Options; } else if (ButtonPress(a_menu.m_mainButtons[3])) { MasterController.m_exit = true; } } else if (a_menu.m_menuState == Menu.MenuState.PreGame) { //Starts a session to play against computer if (ButtonPress(a_menu.m_play)) { ModelClasses.Game f_game = new ModelClasses.Game(a_gameAssets, MasterController.m_mapSize, MasterController.m_mapSize); GameBuilder f_gameBuilder = new GameBuilder(); f_gameBuilder.BuildWorldForFour(f_game, a_gameAssets); a_gameAssets.LoadHeightMap(a_graphics, f_game.m_map); a_gameView = new ViewClasses.GameView(a_graphics, a_gameAssets, f_game); f_game.SetParticleHandler(a_gameView.m_particleHandler); a_gameView.m_mapTransformer.LoadGraphicsContent(a_graphics); a_game = f_game; a_menu.m_menuState = Menu.MenuState.None; } //Starts a Session to observe a Computer battle else if (ButtonPress(a_menu.m_observer)) { ModelClasses.Game f_game = new ModelClasses.Game(a_gameAssets, MasterController.m_mapSize, MasterController.m_mapSize); f_game.SetParticleHandler(a_gameView.m_particleHandler); a_gameAssets.LoadHeightMap(a_graphics, f_game.m_map); a_gameView = new ViewClasses.GameView(a_graphics, a_gameAssets, f_game); f_game.SetParticleHandler(a_gameView.m_particleHandler); a_gameView.m_mapTransformer.LoadGraphicsContent(a_graphics); a_game = f_game; a_menu.m_menuState = Menu.MenuState.None; } //Return u to main menu else if (ButtonPress(a_menu.m_ret)) { a_menu.m_menuState = Menu.MenuState.Main; } } else if (a_menu.m_menuState == Menu.MenuState.InGameMenu) { //Return to game button if (ButtonPress(a_menu.m_return)) { a_game.m_state = ModelClasses.Game.GameState.Game; } //Options button else if (ButtonPress(a_menu.m_options)) { a_menu.m_menuState = Menu.MenuState.Options; } //Save button else if (ButtonPress(a_menu.m_save)) { a_menu.m_menuState = Menu.MenuState.Save; } //Load Button else if (ButtonPress(a_menu.m_load)) { a_menu.m_menuState = Menu.MenuState.Load; } //Main Menu Button else if (ButtonPress(a_menu.m_quit)) { a_game.m_state = ModelClasses.Game.GameState.Main; a_menu.m_menuState = Menu.MenuState.Main; } //Quit button else if (ButtonPress(a_menu.m_ret)) { MasterController.m_exit = true; } } //Options Screen else if (a_menu.m_menuState == Menu.MenuState.Options) { if (a_game.m_state == ModelClasses.Game.GameState.Main) { //Debug Button if (ButtonPress(a_menu.m_debug)) { a_menu.m_menuState = Menu.MenuState.DebugMenu; } else if (ButtonPress(a_menu.m_ret)) { a_menu.m_menuState = Menu.MenuState.Main; } } else { //Debug Button if (ButtonPress(a_menu.m_debug)) { a_menu.m_menuState = Menu.MenuState.DebugMenu; } else if (ButtonPress(a_menu.m_ret)) { a_menu.m_menuState = Menu.MenuState.InGameMenu; } } } //Debug Screen else if (a_menu.m_menuState == Menu.MenuState.DebugMenu) { if (ButtonPress(a_menu.m_ret)) { a_menu.m_menuState = Menu.MenuState.Options; } else { for (int i = 0; i < a_menu.m_checkBoxes.Length; i++) { if (a_menu.m_checkBoxes[i].m_state == CheckBox.ChkState.Checked) { a_debugView.m_debugOptions.m_options[i] = true; a_debugView.m_debugOptions.Update(); } else if (a_menu.m_checkBoxes[i].m_state == CheckBox.ChkState.Unchecked) { a_debugView.m_debugOptions.m_options[i] = false; a_debugView.m_debugOptions.Update(); } } } } //Save screen else if (a_menu.m_menuState == Menu.MenuState.Save) { if (ButtonPress(a_menu.m_ret)) { a_menu.m_menuState = Menu.MenuState.InGameMenu; } //New save button //It creates a new save slot and saves the game and adds it to the save/load screens else if (ButtonPress(a_menu.m_newSave)) { m_save.TryToSave(a_game, "New Save"); //in order to update save/load screens to populate new saves a_menu.UpdateSlots(a_gameAssets, m_save); a_game.m_state = ModelClasses.Game.GameState.Game; } else if (ButtonPress(a_menu.m_Sup)) { a_menu.ScrollUp(); a_menu.UpdateSlots(a_gameAssets, m_save); } else if (ButtonPress(a_menu.m_Sdown)) { a_menu.ScrollDown(); a_menu.UpdateSlots(a_gameAssets, m_save); } else { //Loops through the saves to see if user have pressed a save and if true it saves the game and break Button f_click = ButtonClicked(a_menu.m_saves); if (f_click != null) { m_save.TryToSave(a_game, f_click.m_buttonText); a_menu.UpdateSlots(a_gameAssets, m_save); a_game.m_state = ModelClasses.Game.GameState.Game; } } } //Load screen else if (a_menu.m_menuState == Menu.MenuState.Load) { if (ButtonPress(a_menu.m_Lup)) { a_menu.ScrollUp(); a_menu.UpdateSlots(a_gameAssets, m_save); } else if (ButtonPress(a_menu.m_Ldown)) { a_menu.ScrollDown(); a_menu.UpdateSlots(a_gameAssets, m_save); } else { Button f_click = ButtonClicked(a_menu.m_loaded); if (f_click != null) { ModelClasses.Game f_game = m_save.TryToLoad(f_click.m_buttonText); if (f_game != null) { f_game.InitializeModels(a_gameView.m_particleHandler, a_gameAssets); a_gameAssets.LoadHeightMap(a_graphics, f_game.m_map); a_gameView = new ViewClasses.GameView(a_graphics, a_gameAssets, f_game); f_game.SetParticleHandler(a_gameView.m_particleHandler); a_gameView.m_mapTransformer = new ViewClasses.MapTransformer(f_game.m_map); a_gameView.m_mapTransformer.LoadGraphicsContent(a_graphics); a_game = f_game; a_game.m_state = ModelClasses.Game.GameState.Game; } } } if (a_game.m_state == ModelClasses.Game.GameState.Main) { if (ButtonPress(a_menu.m_ret)) { a_menu.m_menuState = Menu.MenuState.Main; } } else { if (ButtonPress(a_menu.m_ret)) { a_menu.m_menuState = Menu.MenuState.InGameMenu; } } } else if (a_menu.m_menuState == Menu.MenuState.Win) { if (a_game.m_state == ModelClasses.Game.GameState.GameOver) { if (ButtonPress(a_menu.m_ret)) { a_game.m_state = ModelClasses.Game.GameState.Main; a_menu.m_menuState = Menu.MenuState.Main; } } } else if (a_menu.m_menuState == Menu.MenuState.Lose) { if (a_game.m_state == ModelClasses.Game.GameState.GameOver) { if (ButtonPress(a_menu.m_ret)) { a_game.m_state = ModelClasses.Game.GameState.Main; a_menu.m_menuState = Menu.MenuState.Main; } } } } } } }
private void MouseHandling(GraphicsDevice a_graphics, ModelClasses.Game a_game, ViewClasses.GameView a_gameView) { if (m_input.mouseRightClick()) { //Check if Ray from right clicking hit anything //If it did attack that target //If it didn't, Move to that target //If Attack is active Set units to hunting towards target //gets a world position based on a plane, and mouse position //rightclicks clears pending actions a_gameView.m_HUD.ClearPendingButtons(); a_game.m_player.m_tryingToBuild = false; Ray f_worldRay = m_input.GetWorldRay(a_graphics, a_gameView.m_camera, m_input.m_mouse.m_mouseState.X, m_input.m_mouse.m_mouseState.Y); ModelClasses.Units.Thing f_target = a_game.TryToAttackOrMove(f_worldRay); //If didn't find any target, then move to location! if (f_target == null) { //Get world pos point Vector3?point = m_input.GetWorldPosition(a_graphics, a_game.m_groundPlane, a_game.m_map, a_gameView.m_camera, m_input.m_mouse.m_mouseState.X, m_input.m_mouse.m_mouseState.Y); if (point.HasValue) { //Check if shift is down, do queue up paths if (m_input.m_keyboardState.IsKeyDown(Microsoft.Xna.Framework.Input.Keys.LeftShift)) { a_game.TryToAddDestination(a_game.m_player, point.Value, false); } else { a_game.TryToAddDestination(a_game.m_player, point.Value, true); } } }//If it found a target from the ray else { //If the target isn't owned by player, attack!!!! if (f_target.m_ownerID != a_game.m_player.m_playerID) { a_game.m_player.SetAttackTarget(f_target); }//If player owns the target, move towards! else { //If the target is building and has standardbuild as build interface if (!f_target.m_isUnit && f_target.m_buildBehavior is ModelClasses.BehaviorInterfaces.StandardBuild && f_target.m_thingState != ModelClasses.Units.ThingState.BeingBuilt) { //Creates the bounding box BoundingBox f_box = (BoundingBox)f_target.m_model.Tag; f_box.Max += f_target.m_currentposition; f_box.Min += f_target.m_currentposition; foreach (ModelClasses.Units.Thing selectedThing in a_game.m_player.m_selectedThings) { //The direction of the ray (from selectedItem -> target) Vector3 f_dir = new Vector3(f_target.m_currentposition.X - selectedThing.m_currentposition.X, f_target.m_currentposition.Y - selectedThing.m_currentposition.Y, 0); f_dir.Normalize(); //The ray from unit -> building Ray f_tempRay = new Ray(new Vector3(selectedThing.m_currentposition.X, selectedThing.m_currentposition.Y, f_target.m_currentposition.Z), f_dir); float?f_intersection = f_tempRay.Intersects(f_box); if (f_intersection.HasValue) { //Point = Raypos + (Raydir * distanceToPoint) Vector3 point = (f_tempRay.Position + f_tempRay.Direction * f_intersection.Value); //If it finds a path // Martin: The pathfinder IS working correctly. However there is no way to find a path to a tile which is surrounded by blocked tiles. // A center position of a building of 3x3 size is obviously unreachable. // Also, the pathfinder doesn't use the height when calculating a path, it only cares about if a tile is blocked or not if (a_game.m_pathFinder.FindPath(selectedThing.m_currentposition, point) == 1) { selectedThing.ChangeDestination(a_game.m_pathFinder.m_pathList); if (selectedThing.m_type == ModelClasses.Units.ThingType.C_Cube) { f_target.m_buildBehavior.AddSacrifice(selectedThing); } } } } }//If not, move towards point! else { //Get world pos point Vector3?point = m_input.GetWorldPosition(a_graphics, a_game.m_groundPlane, a_game.m_map, a_gameView.m_camera, m_input.m_mouse.m_mouseState.X, m_input.m_mouse.m_mouseState.Y); if (point.HasValue) { //Check if shift is down, do queue up paths if (m_input.m_keyboardState.IsKeyDown(Microsoft.Xna.Framework.Input.Keys.LeftShift)) { a_game.TryToAddDestination(a_game.m_player, point.Value, false); } else { a_game.TryToAddDestination(a_game.m_player, point.Value, true); } } } } } } if (m_input.mouseLeftButtonDown() && !a_game.m_player.m_tryingToBuild) { BoundingBox?box = m_input.CreateBBSelection(a_graphics, a_game.m_groundPlane, a_game.m_map, a_gameView.m_camera); if (box.HasValue) { ViewClasses.BoundingBoxBuffer.m_color = Color.White; ViewClasses.GameView.DrawBoundingBox(box.Value, a_graphics, Matrix.Identity, a_gameView.m_camera); } } if (m_input.mouseLeftClick()) { //if the focused unit does NOT have any pending buttons if (!a_gameView.m_HUD.HasAPendingButton()) { //If mouse hasn't moved, for eg. you clicked if (m_input.m_mouse.m_mouseState.X == m_input.m_mouse.m_oldXpos && m_input.m_mouse.m_mouseState.Y == m_input.m_mouse.m_oldYpos) { if (m_input.m_mouse.m_mouseState.Y <= HUD.m_area.Top) { a_game.TryToSelect(m_input.GetWorldRay(a_graphics, a_gameView.m_camera, m_input.m_mouse.m_mouseState.X, m_input.m_mouse.m_mouseState.Y)); } }//If mouse moved after you pressed it else { BoundingBox?f_mouseBox = m_input.CreateBBSelection(a_graphics, a_game.m_groundPlane, a_game.m_map, a_gameView.m_camera); if (f_mouseBox.HasValue) { a_game.TryToSelect(f_mouseBox.Value); } } } else { //the mouse point Vector3?point = m_input.GetWorldPosition(a_graphics, a_game.m_groundPlane, a_game.m_map, a_gameView.m_camera, m_input.m_mouse.m_mouseState.X, m_input.m_mouse.m_mouseState.Y); //Gotta check if it's null or not, or might get null exception if (point.HasValue) { //check buttons for (int y = 0; y < a_gameView.m_HUD.m_actionboxButtons.GetLength(1); y++) { for (int x = 0; x < a_gameView.m_HUD.m_actionboxButtons.GetLength(0); x++) { //if the button is pending if (a_gameView.m_HUD.m_actionboxButtons[x, y].m_state == Button.BtnState.Pending) { //use the function of the pending button a_game.m_player.m_focusedTarget.m_actionbox[x, y].m_function(a_game, point.Value); //reset the now used button a_gameView.m_HUD.m_actionboxButtons[x, y].m_state = Button.BtnState.Normal; a_game.m_player.m_tryingToBuild = false; } } } } } } }
private void DrawActionbox(SpriteBatch a_spriteBatch, GameAssets a_gameAssets, ModelClasses.Game a_game) { //draws actionbox for (int y = 0; y < m_actionboxButtons.GetLength(0); y++) { for (int x = 0; x < m_actionboxButtons.GetLength(1); x++) { if (a_game.m_player.m_focusedTarget != null) { //TEMP the real solution should use focusedUnit and depending on what it is, it will draw something different a_spriteBatch.Draw(a_gameAssets.m_emptybox, m_actionboxButtons[x, y].m_rectangle, Color.White); if (a_game.m_player.m_focusedTarget.m_moveBehavior != null) { a_spriteBatch.Draw(a_gameAssets.m_move, m_actionboxButtons[0, 0].m_rectangle, Color.White); a_spriteBatch.Draw(a_gameAssets.m_hold, m_actionboxButtons[0, 1].m_rectangle, Color.White); a_spriteBatch.Draw(a_gameAssets.m_hold, m_actionboxButtons[1, 0].m_rectangle, Color.White); } if (a_game.m_player.m_focusedTarget.m_type == ThingType.C_Cube) { a_spriteBatch.Draw(a_gameAssets.m_factory, m_actionboxButtons[0, 2].m_rectangle, Color.White); a_spriteBatch.Draw(a_gameAssets.m_igloo, m_actionboxButtons[1, 2].m_rectangle, Color.White); a_spriteBatch.Draw(a_gameAssets.m_factory, m_actionboxButtons[2, 2].m_rectangle, Color.White); } else if (a_game.m_player.m_focusedTarget.m_type == ThingType.C_Barrack) { if (a_game.m_player.m_focusedTarget.m_thingState != ThingState.BeingBuilt) { a_spriteBatch.Draw(a_gameAssets.m_barbarian, m_actionboxButtons[0, 2].m_rectangle, Color.White); a_spriteBatch.Draw(a_gameAssets.m_cancel, m_actionboxButtons[0, 0].m_rectangle, Color.White); a_spriteBatch.Draw(a_gameAssets.m_cancelAll, m_actionboxButtons[1, 0].m_rectangle, Color.White); a_spriteBatch.Draw(a_gameAssets.m_cancelBuild, m_actionboxButtons[2, 2].m_rectangle, Color.White); } } } } } }