Exemple #1
0
        public void MoveTo(Level level, Vector2 newPosition)
        {
            var center         = new Vector2(newPosition.X + Size / 2.0f, newPosition.Y + Size / 2.0f);
            var impactEntities = level.GetEntitiesAt(center, new Vector2(Size / 2.0f, Size / 2.0f));

            if (impactEntities != null)
            {
                foreach (var impactEntity in impactEntities)
                {
                    if (impactEntity != this)
                    {
                        impactEntity.Touched(this);
                        //_isMoving = false; // TODO: Is it good to continue moving through an entity like this?  Should the Speed by modified at all?
                    }
                }
            }

            if (CanMoveTo(level, newPosition))
            {
                var oldChunk = level.GetChunk(this);                 // (int)(_position.X + Size / 2), (int)(_position.Y + Size / 2));

                _position = newPosition;

                var newChunk = level.GetChunk(this);

                if (oldChunk != newChunk)
                {
                    oldChunk.RemoveEntity(this);
                    newChunk.AddEntity(this);
                }
            }
            else
            {
                _isMoving = false;
            }
        }
Exemple #2
0
        /// <summary>
        /// This allows us to either update all of the entities in the level, or only the entities in the given chunk, i.e. the player's chunk.
        /// This may not be necessary, or it may need to be expanded to the nearest 3 chunks, etc.
        /// Looking up the player's chunk every frame may slow things down more than just updating every entity.  I'm not sure yet.
        /// </summary>
        private void UpdateEntities(TimeSpan elapsed, Level level)
        {
            var deadEntities = new List <Entity>();

            foreach (var entity in Entities)
            {
                entity.Update(level, elapsed);
                if (!entity.IsAlive)
                {
                    deadEntities.Add(entity);
                }
            }

            foreach (var entity in deadEntities)
            {
                level.GetChunk(entity).RemoveEntity(entity);
            }
        }
Exemple #3
0
		/// <summary>
		/// This allows us to either update all of the entities in the level, or only the entities in the given chunk, i.e. the player's chunk.
		/// This may not be necessary, or it may need to be expanded to the nearest 3 chunks, etc.
		/// Looking up the player's chunk every frame may slow things down more than just updating every entity.  I'm not sure yet.
		/// </summary>
		private void UpdateEntities(TimeSpan elapsed, Level level)
		{
			var deadEntities = new List<Entity>();
			foreach (var entity in Entities)
			{
				entity.Update(level, elapsed);
				if (!entity.IsAlive)
				{
					deadEntities.Add(entity);
				}
			}

			foreach (var entity in deadEntities)
			{
				level.GetChunk(entity).RemoveEntity(entity);
			}
		}
Exemple #4
0
		public void MoveTo(Level level, Vector2 newPosition)
		{
			var center = new Vector2(newPosition.X + Size / 2.0f, newPosition.Y + Size / 2.0f);
			var impactEntities = level.GetEntitiesAt(center, new Vector2(Size / 2.0f, Size / 2.0f));
			if (impactEntities != null)
			{
				foreach (var impactEntity in impactEntities)
				{
					if (impactEntity != this)
					{
						impactEntity.Touched(this);
						//_isMoving = false; // TODO: Is it good to continue moving through an entity like this?  Should the Speed by modified at all?
					}
				}
			}

			if (CanMoveTo(level, newPosition))
			{
				var oldChunk = level.GetChunk(this); // (int)(_position.X + Size / 2), (int)(_position.Y + Size / 2));

				_position = newPosition;

				var newChunk = level.GetChunk(this);

				if (oldChunk != newChunk)
				{
					oldChunk.RemoveEntity(this);
					newChunk.AddEntity(this);
				}
			}
			else
			{
				_isMoving = false;
			}
		}