void GameOverLogic() { if (World == null || !World.GameOver || World.MapEditor) { return; } float dist = (World.DragonLordDeathPos - World.GameOverPos).Length(); float PanTime = CoreMath.LerpRestrict(0, .5f, 1.35f, 2, dist); if (T - World.GameOverTime < PanTime) { DeltaT *= .03f; World.Markers.Hide = true; } else if (T - World.GameOverTime < PanTime + 1.25) { DeltaT *= .35f; if (!World.End_PlayedDeathGroan && T - World.GameOverTime > PanTime + 0.0) { Sounds.DyingDragonLord.MaybePlay(); World.End_PlayedDeathGroan = true; } } else { World.Markers.Hide = false; if (!World.End_PlayedDeathExplosion) { Sounds.EndOfGameDyingDragonLord.MaybePlay(); World.End_PlayedDeathExplosion = true; } } GameInputEnabled = false; float s = (float)Math.Min(1, (T - World.GameOverTime) / PanTime); World.CameraPos = s * World.DragonLordDeathPos + (1 - s) * World.GameOverPos; World.CameraZoom = CoreMath.LogLerpRestrict((float)World.GameOverTime, World.GameOverZoom, (float)World.GameOverTime + 1.25f, 100, (float)T); }
void DrawGrids() { // Draw texture to screen //GameClass.Graphics.SetRenderTarget(null); GameClass.Graphics.Clear(Color.Black); if (MapEditorActive) { PercentSimStepComplete = .9f; } else { PercentSimStepComplete = (float)(SecondsSinceLastUpdate / DelayBetweenUpdates); } float z = 14; // Draw parts of the world outside the playable map float tiles_solid_blend = CoreMath.LogLerpRestrict(1f, 0, 5f, 1, CameraZoom); bool tiles_solid_blend_flag = tiles_solid_blend < 1; if (x_edge > 1 || y_edge > 1) { DrawOutsideTiles.Using(camvec, CameraAspect, DataGroup.Tiles, TileSprite, tiles_solid_blend_flag, tiles_solid_blend); OutsideTiles.SetupVertices(vec(-2.5f, -2f), vec(2.5f, 2), vec(0, 0), vec(-5 / 2, 2 / 1)); OutsideTiles.Draw(GameClass.Graphics); } // The the map tiles DrawTiles.Using(camvec, CameraAspect, DataGroup.Tiles, TileSprite, MapEditorActive && DrawGridLines, tiles_solid_blend_flag, tiles_solid_blend); GridHelper.DrawGrid(); //DrawGeoInfo.Using(camvec, CameraAspect, DataGroup.Geo, Assets.DebugTexture_Arrows); GridHelper.DrawGrid(); //DrawGeoInfo.Using(camvec, CameraAspect, DataGroup.AntiGeo, Assets.DebugTexture_Arrows); GridHelper.DrawGrid(); //DrawDirwardInfo.Using(camvec, CameraAspect, DataGroup.Dirward[Dir.Right], Assets.DebugTexture_Arrows); GridHelper.DrawGrid(); //DrawPolarInfo.Using(camvec, CameraAspect, DataGroup.Geo, DataGroup.GeoInfo, Assets.DebugTexture_Num); GridHelper.DrawGrid(); // Territory and corpses if ((CurUserMode == UserMode.PlaceBuilding || CurUserMode == UserMode.CastSpell && CurSpell.Info.TerritoryRange < float.MaxValue) && !MapEditorActive) { float cutoff = _0; if (CurUserMode == UserMode.PlaceBuilding) { cutoff = DrawTerritoryPlayer.TerritoryCutoff; } else if (CurUserMode == UserMode.CastSpell) { cutoff = CurSpell.Info.TerritoryRange; } DrawTerritoryPlayer.Using(camvec, CameraAspect, DataGroup.DistanceToPlayers, MyPlayerValue, cutoff); GridHelper.DrawGrid(); } else { if (CameraZoom <= z / 4) { float territory_blend = CoreMath.LerpRestrict(z / 4, 0, z / 8, 1, CameraZoom); DrawTerritoryColors.Using(camvec, CameraAspect, DataGroup.DistanceToPlayers, territory_blend); GridHelper.DrawGrid(); } if (CameraZoom >= z / 8) { float corpse_blend = .35f * CoreMath.LerpRestrict(z / 2, 1, z / 16, 0, CameraZoom); DrawCorpses.Using(camvec, CameraAspect, DataGroup.Corpses, UnitsSprite, corpse_blend); GridHelper.DrawGrid(); } } // Dragon Lord marker, before DrawDragonLordMarker(After: false); // Units if (CameraZoom > z / 8) { float second = (DrawCount % 60) / 60f; float selection_blend = CoreMath.LogLerpRestrict(60.0f, 1, 1.25f, 0, CameraZoom); float selection_size = CoreMath.LogLerpRestrict(6.0f, .6f, z / 4, 0, CameraZoom); float solid_blend = CoreMath.LogLerpRestrict(z / 7, 0, z / 2, 1, CameraZoom); bool solid_blend_flag = solid_blend < 1; DrawUnits.Using(camvec, CameraAspect, DataGroup.CurrentData, DataGroup.PreviousData, DataGroup.CurrentUnits, DataGroup.PreviousUnits, UnitsSprite, Assets.ShadowTexture, MyPlayerValue, PercentSimStepComplete, second, selection_blend, selection_size, solid_blend_flag, solid_blend); } else { DrawUnitsZoomedOutBlur.Using(camvec, CameraAspect, DataGroup.CurrentData, DataGroup.CurrentUnits, MyPlayerValue); } GridHelper.DrawGrid(); // Buildings DrawBuildings.Using(camvec, CameraAspect, DataGroup.CurrentData, DataGroup.CurrentUnits, BuildingsSprite, ExsplosionSprite, MyPlayerValue, PercentSimStepComplete); GridHelper.DrawGrid(); // Markers Markers.Update(); Markers.Draw(DrawOrder.AfterTiles); // Antimagic if (CurUserMode == UserMode.CastSpell) { DrawAntiMagic.Using(camvec, CameraAspect, DataGroup.AntiMagic, MyTeamValue); GridHelper.DrawGrid(); } // Markers Markers.Draw(DrawOrder.AfterUnits); // Building icons if (CameraZoom <= z / 4) { float blend = CoreMath.LogLerpRestrict(z / 4, 0, z / 8, 1, CameraZoom); float radius = 5.5f / CameraZoom; DrawBuildingsIcons.Using(camvec, CameraAspect, DataGroup.DistanceToBuildings, DataGroup.CurrentData, DataGroup.CurrentUnits, blend, radius, MyPlayerValue); GridHelper.DrawGrid(); } // Dragon Lord marker, after DrawDragonLordMarker(After: true); }
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); } } }