Exemplo n.º 1
0
		protected override void OnUpdate(GameTime gameTime, InputState istate)
		{
			if (!IsInViewport) return; // No drawing - no updating (state is frozen)

			internalTime += gameTime.GetElapsedSeconds();

			for (int i = ParticleCount - 1; i >= 0; i--)
			{
				particlePool[i].CurrentLifetime += gameTime.GetElapsedSeconds();
				if (particlePool[i].CurrentLifetime >= particlePool[i].MaxLifetime)
				{
					RemoveParticle(i);
				}
				else
				{
					particlePool[i].Position.X += particlePool[i].Velocity.X * gameTime.GetElapsedSeconds();
					particlePool[i].Position.Y += particlePool[i].Velocity.Y * gameTime.GetElapsedSeconds();
				}
			}

			timeSinceLastSpawn += gameTime.GetElapsedSeconds();
			while (timeSinceLastSpawn >= spawnDelay)
			{
				SpawnParticle();
				timeSinceLastSpawn -= spawnDelay;

				spawnDelay = _config.SpawnDelay;
			}
		}
Exemplo n.º 2
0
		public void Update(GameTime gameTime)
		{
			// ReSharper disable once CompareOfFloatsByEqualityOperator
			if (ActualValue < TargetValue)
			{
				ActualValue += deltaSpeed * gameTime.GetElapsedSeconds();
				if (ActualValue > TargetValue) ActualValue = TargetValue;
			}
			else if (ActualValue > TargetValue)
			{
				ActualValue -= deltaSpeed * gameTime.GetElapsedSeconds();
				if (ActualValue < TargetValue) ActualValue = TargetValue;
			}
		}
Exemplo n.º 3
0
		protected override void DoUpdate(GameTime gameTime, InputState istate)
		{
			if (IsOpening && FloatMath.IsNotOne(openingProgress))
			{
				bool hasOpened;
				openingProgress = FloatMath.LimitedInc(openingProgress, gameTime.GetElapsedSeconds() * HUDPauseButton.ANIMATION_SPEED, 1f, out hasOpened);
				if (hasOpened)
				{
					IsOpening = false;
				}

				UpdateOpeningPosition();
			}
			else if (IsClosing)
			{
				bool hasClosed;
				openingProgress = FloatMath.LimitedDec(openingProgress, gameTime.GetElapsedSeconds() * HUDPauseButton.ANIMATION_SPEED, 0f, out hasClosed);
				if (hasClosed)
				{
					Remove();
				}

				UpdateClosingPosition();
			}
		}
		public void Update(GameTime gameTime, InputState istate)
		{
			timeSinceLastUpdate -= gameTime.GetElapsedSeconds();
			if (timeSinceLastUpdate <= 0)
			{
				timeSinceLastUpdate = updateInterval;

				Calculate(istate);
			}
		}
		public void Update(GameTime gameTime)
		{
			// ReSharper disable once CompareOfFloatsByEqualityOperator
			if (ActualValue != TargetValue)
			{
				var radSpeed = deltaSpeed * gameTime.GetElapsedSeconds();
				var diff = FloatMath.DiffModulo(ActualValue, TargetValue, modulo);

				ActualValue = FloatMath.Abs(diff) <= radSpeed ? TargetValue : FloatMath.AddRads(ActualValue, -FloatMath.Sign(diff) * radSpeed);
			}
		}
		public void UpdateDecay(GameTime gameTime, bool first)
		{
			if (age < spawntime && spawntime > 0)
			{
				lifetime -= gameTime.GetElapsedSeconds();
				age += gameTime.GetElapsedSeconds();

				Decay = (float) (age / spawntime);
			}
			else if (lifetime < decaytime)
			{
				if (first)
				{
					lifetime -= gameTime.GetElapsedSeconds();
					age += gameTime.GetElapsedSeconds();

					Decay = (float) (lifetime / decaytime);
				}
				else
				{
					Decay = 1;
				}
			}
			else
			{
				lifetime -= gameTime.GetElapsedSeconds();
				age += gameTime.GetElapsedSeconds();

				Decay = 1;
			}

			if (lifetime < 0) IsAlive = false;

		}
Exemplo n.º 7
0
        private Vector2 CalculateSpeedOnDirection(Direction direction, GameTime gameTime)
        {
            float time = gameTime.GetElapsedSeconds();
            Vector2 accel = direction.Acceleration;

            if (mobile.State == HitBoxState.Airborne)
            {
                accel.X /= MagicNumbers.AerialAccelerationPenaltyOnX;
            }

            Vector2 velocity = accel * direction * (float)Math.Pow(time, MagicNumbers.GameSpeedPower);
            return velocity;
        }
Exemplo n.º 8
0
        public virtual Vector2 CalculateInterpolation(GameTime gameTime)
        {
            Vector2 velocity = CalculateSpeedOnDirection(mobile.Direction, gameTime);
            Vector2 gravity = CalculateGravitySpeed(gameTime);

            Vector2 target = mobile.Speed + gravity + velocity;

            Vector2 afterHorizontal = HorizontalSpeedChanges(target, velocity);
            Vector2 afterVertical = VerticalSpeedChanges(afterHorizontal, gravity);

            mobile.Speed = ConstrainSpeed(afterVertical);

            float time = gameTime.GetElapsedSeconds();
            return mobile.Speed * time;
        }
Exemplo n.º 9
0
		public void Update(GameTime gameTime, InputState istate)
		{
			Lifetime += gameTime.GetElapsedSeconds();

			for (int i = ActiveOperations.Count - 1; i >= 0; i--)
			{
				if (!ActiveOperations[i].Update(this, gameTime, istate))
				{
					ActiveOperations[i].OnEnd(this);
					ActiveOperations.RemoveAt(i);
				}
			}

			OnUpdate(gameTime, istate);
		}
Exemplo n.º 10
0
        protected override void Update(GameTime gameTime)
        {
            var deltaTime = gameTime.GetElapsedSeconds();
            var keyboardState = Keyboard.GetState();
            var mouseState = Mouse.GetState();

            if (keyboardState.IsKeyDown(Keys.Escape))
                Exit();

            if (_player != null && !_player.IsDestroyed)
            {
                const float acceleration = 5f;

                if (keyboardState.IsKeyDown(Keys.W) || keyboardState.IsKeyDown(Keys.Up))
                    _player.Accelerate(acceleration);

                if (keyboardState.IsKeyDown(Keys.S) || keyboardState.IsKeyDown(Keys.Down))
                    _player.Accelerate(-acceleration);

                if (keyboardState.IsKeyDown(Keys.A) || keyboardState.IsKeyDown(Keys.Left))
                    _player.Rotation -= deltaTime*3f;

                if (keyboardState.IsKeyDown(Keys.D) || keyboardState.IsKeyDown(Keys.Right))
                    _player.Rotation += deltaTime*3f;

                if (keyboardState.IsKeyDown(Keys.Space) || mouseState.LeftButton == ButtonState.Pressed)
                    _player.Fire();

                if (_previousMouseState.X != mouseState.X || _previousMouseState.Y != mouseState.Y)
                    _player.LookAt(_camera.ScreenToWorld(new Vector2(mouseState.X, mouseState.Y)));

                _camera.LookAt(_player.Position + _player.Velocity * 0.2f);
            }

            _entityManager.Update(gameTime);

            CheckCollisions();

            _previousMouseState = mouseState;


            _guiManager.Update(gameTime);
            base.Update(gameTime);
        }
Exemplo n.º 11
0
		private void UpdateDrag(GameTime gameTime, InputState istate)
		{
			var delta = istate.PointerPosition - mouseStartPos;

			Screen.MapOffsetX = startOffset.X + delta.X;
			Screen.MapOffsetY = startOffset.Y + delta.Y;

			CalculateOOB();

			lastMousePosTimer += gameTime.GetElapsedSeconds();
			if (lastMousePosTimer > DRAGSPEED_RESOLUTION)
			{
				dragSpeed = (istate.PointerPosition - lastMousePos) / lastMousePosTimer;

				//Debug.WriteLine(dragSpeed);

				lastMousePosTimer = 0f;
				lastMousePos = istate.PointerPosition;
			}
		}
Exemplo n.º 12
0
		private void UpdateRestDrag(GameTime gameTime)
		{
			float dragX = dragSpeed.X + outOfBoundsForce.X;
			float dragY = dragSpeed.Y + outOfBoundsForce.Y;
			
			Screen.MapOffsetX = Screen.MapOffsetX + dragX * gameTime.GetElapsedSeconds();
			Screen.MapOffsetY = Screen.MapOffsetY + dragY * gameTime.GetElapsedSeconds();

			CalculateOOB();

			dragSpeed -= dragSpeed * FRICTION * gameTime.GetElapsedSeconds();

			if (dragSpeed.LengthSquared() < SPEED_MIN * SPEED_MIN)
			{
				dragSpeed = Vector2.Zero;
			}
		}
Exemplo n.º 13
0
		private void UpdateClosing(GameTime gameTime)
		{
			bool finished;
			openingProgress = FloatMath.LimitedDec(openingProgress, gameTime.GetElapsedSeconds() * OPENING_ANIMATION_CLOSINGSPEED, 0f, out finished);

			for (int i = 0; i < 5; i++)
			{
				speedButtons[i].RelativePosition = RelativePosition + OPENING_VECTORS[i] * openingProgress;
			}

			if (finished)
			{
				foreach (var btn in speedButtons)
				{
					btn.Remove();

					btn.IsOpened = false;
				}
				speedButtons = null;
			}
		}
Exemplo n.º 14
0
		private void UpdateOpening(GameTime gameTime, bool force)
		{
			bool finished;
			openingProgress = FloatMath.LimitedInc(openingProgress, gameTime.GetElapsedSeconds() * OPENING_ANIMATION_TOTALSPEED, 1f, out finished);

			if (force)
			{
				openingProgress = 1f;
				finished = true;
			}

			for (int i = 0; i < 5; i++)
			{
				var progress = FloatMath.LimitedDec(openingProgress, i * OPENING_ANIMATION_DELAY, 0f) / OPENING_ANIMATION_SINGLESPEED;

				speedButtons[i].RelativePosition = RelativePosition + OPENING_VECTORS[i] * FloatMath.FunctionEaseOutElastic(progress);
			}

			if (finished)
			{
				foreach (var btn in speedButtons)
				{
					btn.IsOpened = true;
				}
			}
		}
Exemplo n.º 15
0
		protected override void DoUpdate(GameTime gameTime, InputState istate)
		{
			rotation = FloatMath.IncModulo(rotation, gameTime.GetElapsedSeconds() * HAND_ANIMATION_SPEED * this.GDHUD().GDOwner.GameSpeed, FloatMath.TAU);

			int choosen = -1;

			if (isOpened && isDragging)
			{
				var center = new Vector2(Position.X + Size.Width / 2f, Position.Y + Size.Height / 2f);
				
				var delta = istate.PointerPosition - center;
				if (delta.LengthSquared() >= DRAG_MINIMUMDISTANCE * DRAG_MINIMUMDISTANCE)
				{
					var angle = delta.ToAngle();

					if (angle > -FloatMath.PI && angle < FloatMath.PI / 16f)
						choosen = 0;
					else if (angle > FloatMath.PI / 16f && angle < 3 * FloatMath.PI / 16f)
						choosen = 1;
					else if (angle > 3 * FloatMath.PI / 16f && angle < 5 * FloatMath.PI / 16f)
						choosen = 2;
					else if (angle > 5 * FloatMath.PI / 16f && angle < 7 * FloatMath.PI / 16f)
						choosen = 3;
					else if (angle > 7 * FloatMath.PI / 16f && angle < FloatMath.PI)
						choosen = 4;
				}

				if (istate.IsDown)
				{
					for (int i = 0; i < 5; i++)
					{
						speedButtons[i].Highlighted = (i == choosen);
					}
				}
				else
				{
					if (choosen != -1)
					{
						speedButtons[choosen].Click();
					}

					isDragging = false;
				}
			}

			if (isOpened && FloatMath.IsNotOne(openingProgress))
			{
				UpdateOpening(gameTime, choosen != -1);
			}
			else if (!isOpened && FloatMath.IsNotZero(openingProgress))
			{
				UpdateClosing(gameTime);
			}
		}
Exemplo n.º 16
0
		private void ColorGridCell(GameTime gameTime, BackgroundParticle p, int x, int y)
		{
			if (x < -1) return;
			if (y < -1) return;
			if (x > TILE_COUNT_X) return;
			if (y > TILE_COUNT_Y) return;

			var power = gameTime.GetElapsedSeconds() * GRID_ADAPTION_SPEED * p.PowerPercentage;

			ColorGridCellDirect(p.Fraction, x, y, power);
		}
Exemplo n.º 17
0
 protected virtual Vector2 CalculateInterpolation(GameTime gameTime)
 {
     float time = gameTime.GetElapsedSeconds();
     Vector2 interpolation = Direction * Speed * time;
     return interpolation;
 }
Exemplo n.º 18
0
		public void UpdatePosition(GameTime gameTime, SpriteFont font, int lineCount, ref float posY)
		{
			if (InertiaPosition < 0)
			{
				InertiaPosition = posY;
			}
			else if (posY < InertiaPosition)
			{
				var speed = gameTime.GetElapsedSeconds() * DebugTextDisplay.INERTIA_SPEED * FloatMath.Max(1, FloatMath.Round((InertiaPosition - posY) / font.LineSpacing));

				if (lineCount > DebugTextDisplay.OVERFLOW_MAX) speed = 99999;

				InertiaPosition = FloatMath.LimitedDec(InertiaPosition, speed, posY);
				posY = InertiaPosition;
			}
			else if (posY > InertiaPosition)
			{
				// should never happen ^^
				InertiaPosition = posY;
			}

			PositionY = posY;
			
			posY += font.MeasureString(DisplayText()).Y * DebugTextDisplay.TEXT_SPACING;
		}
Exemplo n.º 19
0
		protected override void DoUpdate(GameTime gameTime, InputState istate)
		{
			if (isOpened && FloatMath.IsNotOne(animationProgress))
			{
				animationProgress = FloatMath.LimitedInc(animationProgress, gameTime.GetElapsedSeconds() * ANIMATION_SPEED, 1f);
			}
			else if (!isOpened && FloatMath.IsNotZero(animationProgress))
			{
				animationProgress = FloatMath.LimitedDec(animationProgress, gameTime.GetElapsedSeconds() * ANIMATION_SPEED, 0f);
			}
		}
Exemplo n.º 20
0
		public override void Update(GameTime gameTime, InputState state)
		{
			foreach (var particle in Particles.ToList())
			{
				if (! particle.Alive) continue;
				
				switch (particle.Direction)
				{
					case Direction4.North:
						#region North
						{
							var before = particle.Y;
							particle.Y -= BackgroundParticle.PARTICLE_SPEED * gameTime.GetElapsedSeconds();
							var after = particle.Y;

							var coll = particle.TravelSection.FirstOrDefault(p => p != particle && p.Direction == Direction4.South && p.Y >= after && p.Y <= before);
							var merge = particle.TravelSection.FirstOrDefault(p => p != particle && p.Direction == Direction4.North && p.Y >= after && p.Y <= before);

							int x = (int)particle.X / GDConstants.TILE_WIDTH;
							int y = (int)(before / GDConstants.TILE_WIDTH);

							if (merge != null)
							{
								MergeParticles(merge, particle);
							}
							else if (coll != null)
							{
								RemoveParticles(coll, particle);
							}
							else if (FloatMath.Floor(before / GDConstants.TILE_WIDTH) != FloatMath.Floor(after / GDConstants.TILE_WIDTH))
							{
								RemoveParticle(particle);

								if (particle.OriginY >= y) AddParticle(new BackgroundParticle(particle, x * GDConstants.TILE_WIDTH, y * GDConstants.TILE_WIDTH - 0.01f, Direction4.North), x, y);
								if (particle.OriginX <= x) AddParticle(new BackgroundParticle(particle, x * GDConstants.TILE_WIDTH + 0.01f, y * GDConstants.TILE_WIDTH, Direction4.East), x, y);
								if (particle.OriginY <= y) AddParticle(new BackgroundParticle(particle, x * GDConstants.TILE_WIDTH, y * GDConstants.TILE_WIDTH + 0.01f, Direction4.South), x, y);
								if (particle.OriginX >= x) AddParticle(new BackgroundParticle(particle, x * GDConstants.TILE_WIDTH - 0.01f, y * GDConstants.TILE_WIDTH, Direction4.West), x, y);
							}
							else
							{
								ColorGridCell(gameTime, particle, x + 0, y + 0);
								ColorGridCell(gameTime, particle, x - 1, y + 0);
							}

							break;
						}
					#endregion
					case Direction4.East:
						#region East
						{
							var before = particle.X;
							particle.X += BackgroundParticle.PARTICLE_SPEED * gameTime.GetElapsedSeconds();
							var after = particle.X;

							var coll = particle.TravelSection.FirstOrDefault(p => p != particle && p.Direction == Direction4.West && p.X >= before && p.X <= after);
							var merge = particle.TravelSection.FirstOrDefault(p => p != particle && p.Direction == Direction4.East && p.X >= before && p.X <= after);

							int x = (int)(after / GDConstants.TILE_WIDTH);
							int y = (int)particle.Y / GDConstants.TILE_WIDTH;

							if (merge != null)
							{
								MergeParticles(merge, particle);
							}
							else if (coll != null)
							{
								RemoveParticles(coll, particle);
							}
							else if (FloatMath.Floor(before / GDConstants.TILE_WIDTH) != FloatMath.Floor(after / GDConstants.TILE_WIDTH))
							{
								RemoveParticle(particle);

								if (particle.OriginY >= y) AddParticle(new BackgroundParticle(particle, x * GDConstants.TILE_WIDTH, y * GDConstants.TILE_WIDTH - 0.01f, Direction4.North), x, y);
								if (particle.OriginX <= x) AddParticle(new BackgroundParticle(particle, x * GDConstants.TILE_WIDTH + 0.01f, y * GDConstants.TILE_WIDTH, Direction4.East), x, y);
								if (particle.OriginY <= y) AddParticle(new BackgroundParticle(particle, x * GDConstants.TILE_WIDTH, y * GDConstants.TILE_WIDTH + 0.01f, Direction4.South), x, y);
								if (particle.OriginX >= x) AddParticle(new BackgroundParticle(particle, x * GDConstants.TILE_WIDTH - 0.01f, y * GDConstants.TILE_WIDTH, Direction4.West), x, y);
							}
							else
							{
								ColorGridCell(gameTime, particle, x, y - 1);
								ColorGridCell(gameTime, particle, x, y + 0);
							}

							break;
						}
					#endregion
					case Direction4.South:
						#region South
						{
							var before = particle.Y;
							particle.Y += BackgroundParticle.PARTICLE_SPEED * gameTime.GetElapsedSeconds();
							var after = particle.Y;

							var coll = particle.TravelSection.FirstOrDefault(p => p != particle && p.Direction == Direction4.North && p.Y >= before && p.Y <= after);
							var merge = particle.TravelSection.FirstOrDefault(p => p != particle && p.Direction == Direction4.South && p.Y >= before && p.Y <= after);

							int x = (int)particle.X / GDConstants.TILE_WIDTH;
							int y = (int)(after / GDConstants.TILE_WIDTH);

							if (merge != null)
							{
								MergeParticles(merge, particle);
							}
							else if (coll != null)
							{
								RemoveParticles(coll, particle);
							}
							else if (FloatMath.Floor(before / GDConstants.TILE_WIDTH) != FloatMath.Floor(after / GDConstants.TILE_WIDTH))
							{
								RemoveParticle(particle);

								if (particle.OriginY >= y) AddParticle(new BackgroundParticle(particle, x * GDConstants.TILE_WIDTH, y * GDConstants.TILE_WIDTH - 0.01f, Direction4.North), x, y);
								if (particle.OriginX <= x) AddParticle(new BackgroundParticle(particle, x * GDConstants.TILE_WIDTH + 0.01f, y * GDConstants.TILE_WIDTH, Direction4.East), x, y);
								if (particle.OriginY <= y) AddParticle(new BackgroundParticle(particle, x * GDConstants.TILE_WIDTH, y * GDConstants.TILE_WIDTH + 0.01f, Direction4.South), x, y);
								if (particle.OriginX >= x) AddParticle(new BackgroundParticle(particle, x * GDConstants.TILE_WIDTH - 0.01f, y * GDConstants.TILE_WIDTH, Direction4.West), x, y);
							}
							else
							{
								ColorGridCell(gameTime, particle, x - 1, y);
								ColorGridCell(gameTime, particle, x + 0, y);
							}

							break;
						}
						#endregion
					case Direction4.West:
						#region West
						{
							var before = particle.X;
							particle.X -= BackgroundParticle.PARTICLE_SPEED * gameTime.GetElapsedSeconds();
							var after = particle.X;

							var coll = particle.TravelSection.FirstOrDefault(p => p != particle && p.Direction == Direction4.East && p.X >= after && p.X <= before);
							var merge = particle.TravelSection.FirstOrDefault(p => p != particle && p.Direction == Direction4.West && p.X >= after && p.X <= before);

							int x = (int)(before / GDConstants.TILE_WIDTH);
							int y = (int)particle.Y / GDConstants.TILE_WIDTH;

							if (merge != null)
							{
								MergeParticles(merge, particle);
							}
							else if (coll != null)
							{
								RemoveParticles(coll, particle);
							}
							else if (FloatMath.Floor(before/GDConstants.TILE_WIDTH) != FloatMath.Floor(after/GDConstants.TILE_WIDTH))
							{
								RemoveParticle(particle);

								if (particle.OriginY >= y) AddParticle(new BackgroundParticle(particle, x*GDConstants.TILE_WIDTH, y*GDConstants.TILE_WIDTH - 0.01f, Direction4.North), x, y);
								if (particle.OriginX <= x) AddParticle(new BackgroundParticle(particle, x*GDConstants.TILE_WIDTH + 0.01f, y*GDConstants.TILE_WIDTH, Direction4.East), x, y);
								if (particle.OriginY <= y) AddParticle(new BackgroundParticle(particle, x*GDConstants.TILE_WIDTH, y*GDConstants.TILE_WIDTH + 0.01f, Direction4.South), x, y);
								if (particle.OriginX >= x) AddParticle(new BackgroundParticle(particle, x*GDConstants.TILE_WIDTH - 0.01f, y*GDConstants.TILE_WIDTH, Direction4.West), x, y);
							}
							else
							{
								ColorGridCell(gameTime, particle, x + 0, y - 1);
								ColorGridCell(gameTime, particle, x + 0, y + 0);
							}

							break;
						}
						#endregion
				}
			}

			for (int x = 0; x <= TILE_COUNT_X; x++)
			{
				for (int y = 0; y <= TILE_COUNT_Y; y++)
				{
					if (blockedGridPoints[x, y].Any(p => FloatMath.IsOne(p.CannonHealth.TargetValue)))
					{
						var f = blockedGridPoints[x, y].First().Fraction;
						if (f.IsNeutral) f = null;

						ColorGridCellDirect(f, x - 0, y - 0, gameTime.GetElapsedSeconds() * GRID_ADAPTION_SPEED_DIRECT);
						ColorGridCellDirect(f, x - 1, y - 0, gameTime.GetElapsedSeconds() * GRID_ADAPTION_SPEED_DIRECT);
						ColorGridCellDirect(f, x - 0, y - 1, gameTime.GetElapsedSeconds() * GRID_ADAPTION_SPEED_DIRECT);
						ColorGridCellDirect(f, x - 1, y - 1, gameTime.GetElapsedSeconds() * GRID_ADAPTION_SPEED_DIRECT);
					}
				}
			}
		}