// updates blasts and removes them from list when size reached public static void UpdateShrinkers(GameTime gameTime) { for (int i = 0; i < Shrinkers.Count; i++) { Shrinker s = Shrinkers[i]; if (s.Update(gameTime)) { Shrinkers.Remove(s); i--; } } }
void createMoveCommandShrinker(Vector2 position, bool attackMove) { Shrinker moveCommandThing; if (Rts.pathFinder.Tools.IsPointWalkable(position)) { moveCommandThing = new Shrinker(position - new Vector2(moveCommandShrinkerSize / 2f, moveCommandShrinkerSize / 2f), moveCommandShrinkerSize, moveCommandShrinkDelay); } else { moveCommandThing = new Shrinker(map.FindNearestWalkableTile(position) - new Vector2(moveCommandShrinkerSize / 2f, moveCommandShrinkerSize / 2f), moveCommandShrinkerSize, moveCommandShrinkDelay); } if (attackMove) { moveCommandThing.Texture = attackMoveCommandShrinkerTexture; } else { moveCommandThing.Texture = moveCommandShrinkerTexture; } }
void createMoveCommandShrinker(Vector2 position, bool attackMove) { Shrinker moveCommandThing; if (Rts.pathFinder.Tools.IsPointWalkable(position)) moveCommandThing = new Shrinker(position - new Vector2(moveCommandShrinkerSize / 2f, moveCommandShrinkerSize / 2f), moveCommandShrinkerSize, moveCommandShrinkDelay); else moveCommandThing = new Shrinker(map.FindNearestWalkableTile(position) - new Vector2(moveCommandShrinkerSize / 2f, moveCommandShrinkerSize / 2f), moveCommandShrinkerSize, moveCommandShrinkDelay); if (attackMove) moveCommandThing.Texture = attackMoveCommandShrinkerTexture; else moveCommandThing.Texture = moveCommandShrinkerTexture; }
public override void Update(GameTime gameTime) { int i = Player.Me.UnitArray.Length; // check for exit /*if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed) * Game1.Game.Exit(); * if (Keyboard.GetState(PlayerIndex.One).IsKeyDown(Keys.Escape)) * { * //Graphics.ToggleFullScreen(); * cleanup(); * returnControl("exit"); * return; * }*/ //Cursor.Clip = new System.Drawing.Rectangle(winForm.Location, winForm.Size); Rts.gameTime = gameTime; if (!waitingForMessage) { GameClock += (float)gameTime.ElapsedGameTime.TotalSeconds * GameSpeed; } // count down if (doCountDown()) { return; } // send time sync message if server checkToSync(gameTime); // just checkup if not server checkToCheckup(gameTime); // receive and process network messages receiveData(gameTime); // mute check checkForMute(); // update mouse and keyboard state mouseState = Mouse.GetState(); keyboardState = Keyboard.GetState(); // pause check /*if (Keyboard.GetState(PlayerIndex.One).IsKeyUp(Keys.P)) * allowPause = true; * if (allowPause && Keyboard.GetState(PlayerIndex.One).IsKeyDown(Keys.P)) * { * paused ^= true; * allowPause = false; * if (paused) * { * MediaPlayer.Volume /= 4; * //GameTimer.Stop(); * } * else * { * MediaPlayer.Volume *= 4; * //GameTimer.Start(); * } * }*/ // do cleanup of player unit/structure arrays Player.SetNullIDS(); // pathfinding performance info if (Game1.DEBUG) { timeForPathFindingProfiling += gameTime.ElapsedGameTime.TotalMilliseconds; if (timeForPathFindingProfiling >= 500) { double pathFindingTime; lock (Rts.pathFinder.TimeSpentPathFindingLock) { pathFindingTime = Rts.pathFinder.TimeSpentPathFinding.TotalMilliseconds; Rts.pathFinder.TimeSpentPathFinding = TimeSpan.Zero; } pathFindingPercentage = pathFindingTime / timeForPathFindingProfiling * 100; timeForPathFindingProfiling = 0; lock (PathFindRequest.HighPriorityPathFindRequests) { pathFindQueueSize = PathFindRequest.HighPriorityPathFindRequests.Count; } } } //update fps fpsElapsedTime += gameTime.ElapsedGameTime; if (fpsElapsedTime > TimeSpan.FromSeconds(1)) { //Game1.Game.Window.Title = "FPS: " + (frameCounter > 2 ? frameCounter.ToString() : "COOL"); fpsMessage = "FPS: " + (frameCounter > 2 ? frameCounter.ToString() : "COOL"); if (Game1.DEBUG) { fpsMessage += " - Unit count: " + Unit.Units.Count; } fpsElapsedTime -= TimeSpan.FromSeconds(1); frameCounter = 0; } // do nothing else if paused if (paused) { return; } // input processing checkForShift(gameTime); checkForCommands(); SimpleButton.UpdateAll(mouseState, keyboardState); checkHotKeyGroups(gameTime); checkForLeftClick(gameTime); checkForRightClick(); checkForTab(); checkForMouseCameraScroll(gameTime); checkForCameraZoom(gameTime); checkForCameraRotate(gameTime); if (keyboardState.IsKeyDown(Keys.Space)) { centerCameraOnSelectedUnits(); } clampCameraToMap(); updatePlacingStructure(); updatePlacedStructures(); if (!placingStructure) { SelectBox.Update(worldViewport, camera); } Shrinker.UpdateShrinkers(gameTime); // do nothing else if waiting for message if (waitingForMessage) { return; } doScheduledActions(); checkForUnitStatusUpdates(gameTime); checkForStructureStatusUpdates(gameTime); //update stats updateStats(gameTime); map.UpdateBoundingBoxes(); updateCogWheels(gameTime); RtsBullet.UpdateAll(gameTime); Resource.UpdateResources(gameTime); Structure.UpdateStructures(gameTime); Unit.UpdateUnits(gameTime, netPeer, connection); UnitAnimation.UpdateAll(gameTime); removeDeadUnitsFromSelections(); applyVisibilityToMap(); }
void giveMoveCommand(Vector2 mousePosition) { // create move command shrinker thing Shrinker moveCommandThing; if (Unit.PathFinder.IsPointWalkable(mousePosition)) moveCommandThing = new Shrinker(mousePosition - new Vector2(moveCommandShrinkerSize / 2f, moveCommandShrinkerSize / 2f), moveCommandShrinkerSize, 10); else moveCommandThing = new Shrinker(map.FindNearestWalkableTile(mousePosition) - new Vector2(moveCommandShrinkerSize / 2f, moveCommandShrinkerSize / 2f), moveCommandShrinkerSize, 10); moveCommandThing.Texture = moveCommandTexture; // create magic box Rectangle magicBox = SelectedUnits[0]; foreach (Unit unit in SelectedUnits) magicBox = Rectangle.Union(magicBox, unit.Rectangle); // box is too big or clicked inside magic box if (magicBox.Width > magicBoxMaxSize || magicBox.Height > magicBoxMaxSize || magicBox.Contains((int)mousePosition.X, (int)mousePosition.Y)) { //bool isPointWalkable = Unit.PathFinder.IsPointWalkable(mousePosition); // assign move targets to mouse position foreach (Unit unit in SelectedUnits) { // if mouse position is not in a walkable tile, find nearest walkable tile Vector2 destinationPoint; //if (isPointWalkable) if (Unit.PathFinder.IsPointWalkable(mousePosition, unit)) destinationPoint = mousePosition; else destinationPoint = map.FindNearestWalkableTile(mousePosition); // not holding shift if (keyboardState.IsKeyUp(Keys.LeftShift)) { //float distanceToDestination = Vector2.Distance(unit.CurrentPathNode.Tile.CenterPoint, destinationPoint); //if (distanceToDestination <= unit.Diameter) //unit.GiveCommand(new MoveCommand(destinationPoint, 1)); //else MoveCommand command = new MoveCommand(destinationPoint, 1); unit.GiveCommand(command); } // holding shift else { //float distanceBetweenCurrentAndNewMoveTarget = Vector2.Distance(unit.FinalMoveDestination, destinationPoint); //if (distanceBetweenCurrentAndNewMoveTarget <= unit.Diameter) // unit.QueueCommand(new MoveCommand(destinationPoint, 1)); //else MoveCommand command = new MoveCommand(destinationPoint, 1); unit.QueueCommand(command); //Unit.PathFinder.AddPathFindRequest(unit, command, unit.CurrentPathNode); } } } // clicked outside magic box else { // make destination box and keep in screen Rectangle destBox = magicBox; destBox.X = (int)mousePosition.X - destBox.Width / 2; destBox.Y = (int)mousePosition.Y - destBox.Height / 2; // calculate angle from magic box to destination box float angle = (float)Math.Atan2(destBox.Center.Y - magicBox.Center.Y, destBox.Center.X - magicBox.Center.X); float angleX = (float)Math.Cos(angle); float angleY = (float)Math.Sin(angle); float distance = Vector2.Distance(new Vector2(magicBox.Center.X, magicBox.Center.Y), new Vector2(destBox.Center.X, destBox.Center.Y)); // assign move targets based on angle foreach (Unit unit in SelectedUnits) { // if mouse position is not in a walkable tile, find nearest walkable tile Vector2 destinationPoint = unit.CenterPoint + new Vector2(distance * angleX, distance * angleY); if (!Unit.PathFinder.IsPointWalkable(destinationPoint, unit)) destinationPoint = map.FindNearestWalkableTile(destinationPoint); // not holding shift if (keyboardState.IsKeyUp(Keys.LeftShift)) { //float distanceToDestination = Vector2.Distance(unit.CurrentPathNode.Tile.CenterPoint, destinationPoint); //if (distanceToDestination <= unit.Diameter) // unit.GiveCommand(new MoveCommand(destinationPoint, 1)); //else MoveCommand command = new MoveCommand(destinationPoint, 1); unit.GiveCommand(command); //Unit.PathFinder.AddPathFindRequest(unit, command, unit.CurrentPathNode, 0, false); } // holding shift else { //float distanceBetweenCurrentAndNewMoveTarget = Vector2.Distance(unit.FinalMoveDestination, destinationPoint); //if (distanceBetweenCurrentAndNewMoveTarget <= unit.Diameter) // unit.QueueCommand(new MoveCommand(destinationPoint, 1)); //else unit.QueueCommand(new MoveCommand(destinationPoint, 1)); } } } }