Example #1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Particle"/> class.
        /// </summary>
        /// <param name="world">The world.</param>
        /// <param name="pos">The initial position.</param>
        /// <param name="direction">The direction in which the particle is flying.</param>
        /// <param name="owner">The owner of the particle.</param>
        /// <param name="block">The block type of the particle.</param>
        /// <param name="behavior">The partcle behavior. Includes how fare and fast it moves, what happens if it hits a player an obstacle etc.</param>
        public Particle(World world, Vector3I pos, Vector3F direction, Player owner,
                        Block block, IParticleBehavior behavior)
            : base(world)
        {
            _direction = direction.Normalize();
            if (_direction == Vector3F.Zero)
            {
                throw new ArgumentException("direction vector cannot be zero");
            }

            _stepDelay = behavior.ProcessingStepsPerSecond <= 0 || behavior.ProcessingStepsPerSecond > 20
                                                        ? 50
                                                        : 1000 / behavior.ProcessingStepsPerSecond;

            _pos          = pos;
            _startingPos  = pos;
            _currentStep  = 0;
            _owner        = owner;
            _block        = block;
            _restDistance = behavior.MaxDistance;
            _behavior     = behavior;
            lock (_world.SyncRoot)
            {
                //draw it once right now
                if (null != _map && ReferenceEquals(_map, _world.Map))
                {
                    _prevBlock = _map.GetBlock(pos);
                    if (Block.Undefined != _prevBlock)                    //out of bounds!
                    {
                        UpdateMap(new BlockUpdate(null, pos, block));
                    }
                }
            }
        }
Example #2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Particle"/> class.
        /// </summary>
        /// <param name="world">The world.</param>
        /// <param name="pos">The initial position.</param>
        /// <param name="direction">The direction in which the particle is flying.</param>
        /// <param name="owner">The owner of the particle.</param>
        /// <param name="block">The block type of the particle.</param>
        /// <param name="behavior">The partcle behavior. Includes how fare and fast it moves, what happens if it hits a player an obstacle etc.</param>
        public Particle(World world, Vector3I pos, Vector3F direction, Player owner,
            Block block, IParticleBehavior behavior)
            : base(world)
        {
            _direction = direction.Normalize();
            if (_direction == Vector3F.Zero)
                throw new ArgumentException("direction vector cannot be zero");

            _stepDelay = behavior.ProcessingStepsPerSecond <= 0 || behavior.ProcessingStepsPerSecond > 20
                            ? 50
                            : 1000 / behavior.ProcessingStepsPerSecond;

            _pos = pos;
            _startingPos = pos;
            _currentStep = 0;
            _owner = owner;
            _block = block;
            _restDistance = behavior.MaxDistance;
            _behavior = behavior;
            lock (_world.SyncRoot)
            {
                //draw it once right now
                if (null != _map && ReferenceEquals(_map, _world.Map))
                {
                    _prevBlock = _map.GetBlock(pos);
                    if (Block.Undefined != _prevBlock) //out of bounds!
                        UpdateMap(new BlockUpdate(null, pos, block));
                }
            }
        }
Example #3
0
 public void AttachBehavior(IParticleBehavior behavior)
 {
     Behaviors.Add(behavior);
     behavior.Initialize(this);
 }