void DrawGame(GameTime gameTime) { if (GameClass.GameActive && GameClass.HasFocus) { ////#if DEBUG // if (Keys.S.Pressed() && Keys.LeftControl.Down()) // { // World.SaveCurrentStateInBuffer(); // File.WriteAllBytes("TestDump", World.WorldBytes); // } // if (Keys.L.Pressed() && Keys.LeftControl.Down()) // { // //World.LoadStateFromBuffer(); // World.Reload(World.SimStep, World.WorldBytes); // } ////#endif // if (Keys.D.Pressed() && Keys.LeftControl.Down()) // { // World.SynchronizeNetwork(); // } if (World.MapEditorActive) { if (Keys.S.Pressed() && InputHelper.CtrlDown() && InputHelper.ShiftDown()) { SendCommand("save-as"); } else if (Keys.S.Pressed() && InputHelper.CtrlDown()) { SendCommand("save"); } else if (Keys.L.Pressed() && InputHelper.CtrlDown()) { SendCommand("load"); } } World.Update(); UpdateJsData(); UpdateParams(); } World.Draw(); }
public void Update() { if (!GameClass.Game.GameInputEnabled || DesyncPause) { return; } EditorUpdate(); float FpsRateModifier = 1; //const float MaxZoomOut = 5.33333f, MaxZoomIn = 200f; //const float MaxZoomOut = 3.2f, MaxZoomIn = 200f; //const float MaxZoomOut = 1f, MaxZoomIn = 200f; // Full zoom-in/out float MaxZoomOut, MaxZoomIn; if (MapEditorActive) { // Full zoom-in/out MaxZoomOut = .733f; MaxZoomIn = 200f; } else { MaxZoomOut = World.StaticMaxZoomOut; MaxZoomIn = 200f; // Full zoom-in, Partial zoom-out } // Focus on player's dragon lord. if (!GameClass.Game.ShowChat && Keys.Space.Down()) { var dl_pos = PrevDragonLordPos[MyPlayerNumber]; if (dl_pos > vec(1, 1)) { CameraPos = GridToWorldCood(dl_pos); CameraZoom = 24; } } // Zoom all the way out //if (!GameClass.Game.ShowChat && Keys.Space.Down()) //{ // CameraZoom = MaxZoomOut; //} // Zoom in/out, into the location of the cursor var world_mouse_pos = ScreenToWorldCoord(Input.CurMousePos); var hold_camvec = camvec; if (GameClass.MouseEnabled) { float MouseWheelZoomRate = 1.3333f * FpsRateModifier; if (Input.DeltaMouseScroll < 0) { CameraZoom /= MouseWheelZoomRate; } else if (Input.DeltaMouseScroll > 0) { CameraZoom *= MouseWheelZoomRate; } } float KeyZoomRate = 1.125f * FpsRateModifier; if (!GameClass.Game.ShowChat && (Buttons.X.Down() || Keys.X.Down() || Keys.E.Down())) { CameraZoom /= KeyZoomRate; } else if (!GameClass.Game.ShowChat && (Buttons.A.Down() || Keys.Z.Down() || Keys.Q.Down())) { CameraZoom *= KeyZoomRate; } if (CameraZoom < MaxZoomOut) { CameraZoom = MaxZoomOut; } if (CameraZoom > MaxZoomIn) { CameraZoom = MaxZoomIn; } if (GameClass.MouseEnabled && !(Buttons.A.Pressed() || Buttons.X.Pressed())) { if (MouseOverMinimap) { //var zoom_center = (UiMousePos - MinimapQuad.pos) / MinimapQuad.size; //var shifted = GetShiftedCameraMinimap(Input.CurMousePos, camvec, zoom_center); //CameraPos = shifted; } else { vec2 zoom_center = world_mouse_pos; var shifted = GetShiftedCamera(Input.CurMousePos, camvec, zoom_center); CameraPos = shifted; } } // Move the camera via: Click And Drag //float MoveRate_ClickAndDrag = .00165f * FpsRateModifier; //if (Input.LeftMouseDown) // CameraPos += Input.DeltaMousPos / CameraZoom * MoveRate_ClickAndDrag * new vec2(-1, 1); // Move the camera via: Push Edge if (GameClass.MouseEnabled && (GameClass.Game.CurrentConfig.Fullscreen || BoxSelecting) && (!Program.DisableScreenEdge || BoxSelecting)) { float MoveRate_PushEdge = .075f * FpsRateModifier; var push_dir = vec2.Zero; float EdgeRatio = .005f; push_dir.x += -CoreMath.Restrict(0, 1, (EdgeRatio * GameClass.Screen.x - Input.CurMousePos.x) / (EdgeRatio * GameClass.Screen.x)); push_dir.x += CoreMath.Restrict(0, 1, (Input.CurMousePos.x - (1 - EdgeRatio) * GameClass.Screen.x) / (EdgeRatio * GameClass.Screen.x)); push_dir.y -= -CoreMath.Restrict(0, 1, (EdgeRatio * GameClass.Screen.y - Input.CurMousePos.y) / (EdgeRatio * GameClass.Screen.y)); push_dir.y -= CoreMath.Restrict(0, 1, (Input.CurMousePos.y - (1 - EdgeRatio) * GameClass.Screen.y) / (EdgeRatio * GameClass.Screen.y)); CameraPos += push_dir / CameraZoom * MoveRate_PushEdge; } // Move the camera via: Keyboard or Gamepad if (!GameClass.Game.ShowChat && !(MapEditorActive && InputHelper.CtrlDown())) { var dir = Input.Direction(); float MoveRate_Keyboard = .07f * FpsRateModifier; CameraPos += dir / CameraZoom * MoveRate_Keyboard; } // Move the camera via: Minimap if ((LeftMouseDown || Input.DeltaMouseScroll != 0) && !BoxSelecting && MouseOverMinimap) { CameraPos = MinimapWorldPos(); } // Make sure the camera doesn't go too far offscreen y_edge = 1 + 0.433f / CameraZoom; x_edge = Math.Max(.5f * (CameraAspect / CameraZoom) + .5f * (CameraAspect / MaxZoomOut), 1); // Old style zoom out bounds. x_edge = Math.Min(x_edge, y_edge * CameraAspect); x_edge = CoreMath.LogLerpRestrict(MaxZoomIn, 1 + .35f / CameraZoom, MaxZoomOut, x_edge, CameraZoom); if (CameraZoom == MaxZoomOut) { CameraPos = vec(0, -0.07f); } var TR = ScreenToWorldCoord(new vec2(GameClass.Screen.x, 0)); if (TR.x > x_edge) { CameraPos = new vec2(CameraPos.x - (TR.x - x_edge), CameraPos.y); } if (TR.y > y_edge) { CameraPos = new vec2(CameraPos.x, CameraPos.y - (TR.y - y_edge)); } var BL = ScreenToWorldCoord(new vec2(0, GameClass.Screen.y)); if (BL.x < -x_edge) { CameraPos = new vec2(CameraPos.x - (BL.x + x_edge), CameraPos.y); } if (BL.y < -y_edge) { CameraPos = new vec2(CameraPos.x, CameraPos.y - (BL.y + y_edge)); } // Switch to chat if (!GameClass.Game.ShowChat && Keys.Enter.Pressed() && ChatInhibitor <= 0) { GameClass.Game.ChatGlobal = !(Keys.LeftShift.Down() || Keys.RightShift.Down()); GameClass.Game.ToggleChatViaFlag(); } if (GameClass.Game.ShowChat) { ChatInhibitor = 5; return; } if (ChatInhibitor > 0 && !Keys.Enter.Down()) { ChatInhibitor--; } // Switch input modes // Switch to spells (must be playing, not in editor) if (!SimulationPaused) { if (Keys.D1.Pressed()) { StartSpell(Spells.Fireball); } if (Keys.D2.Pressed()) { StartSpell(Spells.SkeletonArmy); } if (Keys.D3.Pressed()) { StartSpell(Spells.Necromancer); } if (Keys.D4.Pressed()) { StartSpell(Spells.TerracottaArmy); } } // Switch to building placement if (Keys.B.Down()) { StartPlacingBuilding(UnitType.Barracks); } if (Keys.G.Down()) { StartPlacingBuilding(UnitType.GoldMine); } if (Keys.J.Down()) { StartPlacingBuilding(UnitType.JadeMine); } // Switch to standard select if (Keys.Escape.Down() || Keys.Back.Down() || Input.RightMousePressed) { SetModeToSelect(); } // Switch to unit placement (editor only) if (MapEditorActive) { if (Keys.R.Down()) { StartUnitPaint(UnitType.Footman); } if (Keys.T.Down()) { StartUnitPaint(UnitType.DragonLord); } if (Keys.Y.Down()) { StartUnitPaint(UnitType.Necromancer); } if (Keys.U.Down()) { StartUnitPaint(UnitType.Skeleton); } if (Keys.I.Down()) { StartUnitPaint(UnitType.ClaySoldier); } if (Keys.C.Down()) { StartTilePaint(TileType.Dirt); } if (Keys.V.Down()) { StartTilePaint(TileType.Grass); } if (Keys.N.Down()) { StartTilePaint(TileType.Trees); } if (Keys.Tab.Pressed()) { SetUnitPlaceStyle((int)Math.Round(UnitPlaceStyle) + 1); } } }