public static Vector2 ChangeDirection(GameTime gameTime, Vector2 dir, Vector2 pos, Vector2 followedPos, double degreeChange) { double radians = RadiansFromDir(dir); double radianChange = degreeChange * (Math.PI / 180); Vector2 dirToFollowed = new Vector2(followedPos.X - pos.X, followedPos.Y - pos.Y); dirToFollowed = MathFunctions.ScaleDirection(dirToFollowed); double dirFolRadians; if (dirToFollowed.Y > 0) { dirFolRadians = Math.Acos(dirToFollowed.X); } else { dirFolRadians = 2 * Math.PI - (Math.Acos(dirToFollowed.X)); } if (dirFolRadians > 2 * Math.PI) { dirFolRadians -= 2 * Math.PI; } double deltaRadians = MathFunctions.DeltaRadians(radians, dirFolRadians); // If target angle is closer to current than the given delta angle, assign target angle if (Math.Abs(deltaRadians) < Math.Abs(radianChange)) { radians = dirFolRadians; } // If not, increment current angle by given delta angle else { var fpsCompensatedRadianChange = radianChange * MathFunctions.FPSSyncFactor(gameTime); if (deltaRadians > 0 && deltaRadians <= 180) { radians += fpsCompensatedRadianChange; } else if (deltaRadians < 0 && deltaRadians <= 180) { radians -= fpsCompensatedRadianChange; } else if (deltaRadians > 0 && deltaRadians > 180) { radians -= fpsCompensatedRadianChange; } else //(dirFolRadians < Radians && (dirFolRadians - Radians) > 180) { radians += fpsCompensatedRadianChange; } } Vector2 newDir = Vector2.Zero; newDir.X = (float)(Math.Cos(radians)); newDir.Y = (float)(Math.Sin(radians)); return(newDir); }
public void UpdateMovement(GameTime gameTime) { if (aI.Accelerate) { Speed += Acceleration * MathFunctions.FPSSyncFactor(gameTime); aI.Accelerate = false; } else if (aI.Deccelerate) { Speed -= Acceleration * MathFunctions.FPSSyncFactor(gameTime); aI.Deccelerate = false; } if (Speed > 0) { Speed -= Decceleration * MathFunctions.FPSSyncFactor(gameTime); } else if (Speed < 0) { Speed += Decceleration * MathFunctions.FPSSyncFactor(gameTime); } if (Speed > MaxSpeed) { Speed = MaxSpeed; } else if (Speed < -MaxSpeed) { Speed = -MaxSpeed; } if (PositionX + CenterPointX > Game1.ScreenSize.X) { Speed = 0; PositionX = (Game1.ScreenSize.X - CenterPointX) - 1; } else if (PositionX - CenterPointX < 0) { Speed = 0; PositionX = CenterPointX + 1; } if (PositionY + CenterPointY > Game1.ScreenSize.Y) { Speed = 0; PositionY = (Game1.ScreenSize.Y - CenterPointY) - 1; } else if (PositionY - CenterPointY < 0) { Speed = 0; PositionY = CenterPointY + 1; } CheckCollisionsEdges(); }
public override void Update(GameTime gameTime) { base.Update(gameTime); if (IsKilled && useDeathAnim) { Game.stateManager.shooterState.backgroundObjects.Add( ExplosionGenerator.GenerateShipExplosion(Game, spriteSheet, this)); } if (movement != Movement.None) { movementModule.Update(gameTime, this); } CheckWallCollision(); if (hasShield) { currentShield += shieldRegeneration * MathFunctions.FPSSyncFactor(gameTime); if (currentShield > shieldCapacity) { currentShield = shieldCapacity; } } DisruptionLogic(gameTime); if (!IsDisrupted) { ObjectColor = GetDamageTintColor(); } }
protected static byte UpdateSingleColor(GameTime gameTime, byte initialColor, int fadeOutRate) { byte colorFadeDelta = (byte)(fadeOutRate * MathFunctions.FPSSyncFactor(gameTime)); if ((int)(initialColor - colorFadeDelta) > 0) { return((byte)(initialColor - colorFadeDelta)); } else { return(0); } }
public virtual void Update(GameTime gameTime, GameObjectOverworld obj) { Direction = obj.Direction; //Note to self: This code needs to be fixed to compensate for diagonal movement float particleMoveDistance = 0.5f * MathFunctions.FPSSyncFactor(gameTime); if (position.X < obj.position.X) { position.X += particleMoveDistance; } else if (position.X > obj.position.X) { position.X -= particleMoveDistance; } if (position.Y < obj.position.Y) { position.Y += particleMoveDistance; } else if (position.Y > obj.position.Y) { position.Y -= particleMoveDistance; } if (scale > 0) { scale -= 0.03f * MathFunctions.FPSSyncFactor(gameTime); } else { scale = 0; } color = GetFadingFireColor(gameTime, color) * opacity; if (lifeSpawn > 0) { lifeSpawn -= 1.0f * MathFunctions.FPSSyncFactor(gameTime); } yScale = scale + speed * ScaleStretch; parAngle = (float)((Math.PI * 90) / 180) + (float)(MathFunctions.RadiansFromDir(Direction.GetDirectionAsVector())); base.Update(gameTime); }
public void Update(GameTime gameTime) { Vector2 s1 = startingDirection * startingSpeed; Vector2 s2 = direction * speed; position += (s1 + s2) * gameTime.ElapsedGameTime.Milliseconds; lifeTime -= 1 * MathFunctions.FPSSyncFactor(gameTime); if (g > 69) { g -= 3; } if (b > 5) { b -= 5; } }
public void Update(GameTime gameTime, List <GameObjectOverworld> objectsInOverworld, Vector2 cameraPos) { objectsVisibleOnRadar.Clear(); missionArrows.Clear(); availableMainMissionArrows.Clear(); availableMainMissionLocationNames.Clear(); availableMainMissionLocationNames = MissionManager.GetAvailableMainMissionLocationNames(); colorSwapCounter += 1 * MathFunctions.FPSSyncFactor(gameTime); foreach (GameObjectOverworld obj in objectsInOverworld) { // Adds visible game objects if (CollisionDetection.IsPointInsideCircle(obj.position, game.player.position, viewRadius)) { objectsVisibleOnRadar.Add(obj); } // Adds mission arrows for non-visible mission coordinates else if (MissionManager.IsCurrentObjectiveDestination(obj) || MissionManager.IsFailedMissionDestination(obj)) { Boolean isMain = MissionManager.IsMainMissionDestination(obj); missionArrows.Add(new DirectionArrow(spriteSheet, obj.position, playerpos, isMain)); } else if (MissionManager.IsNoMainMissionActive()) { foreach (String str in availableMainMissionLocationNames) { if (obj.name.ToLower().Equals(str.ToLower())) { availableMainMissionArrows.Add(new DirectionArrow(spriteSheet, obj.position, playerpos, true)); break; } } } } playerpos = game.player.position; Origin = new Vector2(cameraPos.X + Game1.ScreenSize.X / 2 - background.SourceRectangle.Value.Width, cameraPos.Y + Game1.ScreenSize.Y / 2 - background.SourceRectangle.Value.Height); }
// Updates camera position relative to players position if camera is within bounds of screen public void CameraUpdate(GameTime gameTime, PlayerOverworld player) { // Camera panning if (ZoomMap.MapState == MapState.On) { if (ControlManager.CheckHold(RebindableKeys.Right)) { cameraPos.X += CameraPanSpeed * MathFunctions.FPSSyncFactor(gameTime); } else if (ControlManager.CheckHold(RebindableKeys.Left)) { cameraPos.X -= CameraPanSpeed * MathFunctions.FPSSyncFactor(gameTime); } if (ControlManager.CheckHold(RebindableKeys.Up)) { cameraPos.Y -= CameraPanSpeed * MathFunctions.FPSSyncFactor(gameTime); } else if (ControlManager.CheckHold(RebindableKeys.Down)) { cameraPos.Y += CameraPanSpeed * MathFunctions.FPSSyncFactor(gameTime); } } else { originalCameraPos = cameraPos; } if (ZoomMap.MapState != MapState.On && ((cameraPos.X - (Game1.ScreenSize.X / 2) >= 0 && (cameraPos.X + Game1.ScreenSize.X / 2) <= WorldWidth) || (cameraPos.Y - (Game1.ScreenSize.Y / 2) >= 0 && cameraPos.Y + (Game1.ScreenSize.Y / 2) <= WorldHeight))) { Position = player.position; } }
public override void Update(GameTime gameTime, GameObjectVertical obj) { if (zigzagDirRight) { zigzagXdir += (zigzagInterval / 60) * MathFunctions.FPSSyncFactor(gameTime); } else { zigzagXdir -= (zigzagInterval / 60) * MathFunctions.FPSSyncFactor(gameTime); } if (zigzagXdir > zigzagInterval) { zigzagDirRight = false; } if (zigzagXdir < -zigzagInterval) { zigzagDirRight = true; } obj.DirectionX = zigzagXdir; }
private void UpdateRuntimeStats(GameTime gameTime) { float MPgain = MPgainedSec * gameTime.ElapsedGameTime.Milliseconds / 1000; if (MP < MPmax - MPgain) { MP += MPgain; } else { MP = MPmax; } float shieldGain = ShieldRegeneration * MathFunctions.FPSSyncFactor(gameTime); if (Shield < ShieldMax - shieldGain) { Shield += shieldGain; } else { Shield = ShieldMax; } }
private void PlayerMovement(GameTime gameTime) { if (speed > maxSpeed) { speed = maxSpeed; } else if (speed < -maxSpeed) { speed = -maxSpeed; } if (StatsManager.Fuel >= normalFuelCost) { if (ControlManager.CheckHold(RebindableKeys.Action3) && isHyperSpeedUnlocked && !isDevelopSpeedUnlocked && controlsEnabled) { maxSpeed = boostSpeed; turningSpeed = boostTurningSpeed; playerAcc = commonAcc; usingBoost = true; } else if (ControlManager.CheckHold(RebindableKeys.Action3) && isDevelopSpeedUnlocked && controlsEnabled) { maxSpeed = developSpeed; turningSpeed = boostTurningSpeed; playerAcc = developAcc; usingBoost = true; } else { maxSpeed = commonSpeed; turningSpeed = commonTurningSpeed; playerAcc = commonAcc; usingBoost = false; } } if (ControlManager.CheckHold(RebindableKeys.Up) && controlsEnabled) { if (StatsManager.Fuel > normalFuelCost) { if (ControlManager.GamepadReady && ControlManager.ThumbStickAngleY != 0) { if (StatsManager.Fuel > normalFuelCost) { speed += playerAcc * MathFunctions.FPSSyncFactor(gameTime); } AddParticle(); } else { if (StatsManager.Fuel > normalFuelCost) { speed += playerAcc * MathFunctions.FPSSyncFactor(gameTime); } AddParticle(); Game.soundEffectsManager.PlaySoundEffect(SoundEffects.OverworldEngine, 0f, 0f); } } } if (ControlManager.CheckHold(RebindableKeys.Right) && controlsEnabled) { if (StatsManager.Fuel > normalFuelCost) { Direction.SetDirection(Direction.GetDirectionAsDegree() + turningSpeed * MathFunctions.FPSSyncFactor(gameTime)); } } else if (ControlManager.CheckHold(RebindableKeys.Left) && controlsEnabled) { if (StatsManager.Fuel > normalFuelCost) { Direction.SetDirection(Direction.GetDirectionAsDegree() - turningSpeed * MathFunctions.FPSSyncFactor(gameTime)); } } if (!ControlManager.CheckHold(RebindableKeys.Up) && controlsEnabled) { if (speed > 0) { speed -= playerAcc * MathFunctions.FPSSyncFactor(gameTime); } else if (speed <= 0) { speed = 0; } Game.soundEffectsManager.FadeOutSoundEffect(SoundEffects.OverworldEngine); } angle = (float)(MathFunctions.RadiansFromDir(new Vector2( Direction.GetDirectionAsVector().X, Direction.GetDirectionAsVector().Y)) + (Math.PI * 90) / 180); }
public virtual void Update(GameTime gameTime) { soundPan = (_position.X - Game.stateManager.shooterState.CurrentLevel.PlayerPosition.X) / Game.stateManager.shooterState.CurrentLevel.LevelWidth; // Movement if (Enable) { Position += Direction * Speed * gameTime.ElapsedGameTime.Milliseconds; } // Rotation RotationAngle += Rotation * MathFunctions.FPSSyncFactor(gameTime); // Invicibility if (tempInvincibility > 0) { tempInvincibility -= gameTime.ElapsedGameTime.Milliseconds; } // Kill of object if (hp <= 0) { if (this is AllianceFighterAlly) { ((AllianceFighterAlly)this).OnKilled(); } IsKilled = true; } //Set degree if (DirectionY > 0) { Radians = Math.Acos(DirectionX); } else { Radians = 2 * Math.PI - (Math.Acos(DirectionX)); } if (Radians >= 2 * Math.PI) { Radians -= 2 * Math.PI; } //Hantering av "Disable FollowObject" if (disableFollowObject > 0) { disableFollowObject -= gameTime.ElapsedGameTime.Milliseconds; } if (Follows) { FindFollowObject(); if (FollowObject != null) { UpdateFollowing(gameTime); } } //Bullet-duration if (this is Bullet) { if (duration > 0) { duration -= gameTime.ElapsedGameTime.Milliseconds; } else { IsKilled = true; } } if (shootObject != null) { if (shootObject.IsKilled || shootObject.IsOutside) { shootObject = null; } } if (IsKilled) { OnKilled(); } }
public void RotateTowardsPointSingleTurn(GameTime gameTime, Vector2 startingPoint, Vector2 preferredPoint, float rotateSpeed) { if (startingPoint.Equals(preferredPoint)) { return; } SetDirection(scaledDirection + (preferredPoint - startingPoint) * rotateSpeed * MathFunctions.FPSSyncFactor(gameTime)); }