Ejemplo n.º 1
0
 /// <summary>
 /// Add a collision behavior.
 /// </summary>
 /// <param name="behavior">Behavior to add.</param>
 public void AddCollisionBehavior(CollisionBehavior behavior)
 {
     if (!HasCollisionBehavior(behavior))
     {
         collisionModes.Add(behavior);
     }
 }
Ejemplo n.º 2
0
        public void CanApplyCollisionForce()
        {
            NativeArray <AgentKinematics> agents   = new NativeArray <AgentKinematics>(1, Allocator.Persistent);
            NativeArray <float3>          steering = new NativeArray <float3>(1, Allocator.Persistent);

            NativeArray <int>           agentMovementTypes = new NativeArray <int>(1, Allocator.Persistent);
            NativeArray <AgentMovement> movementTypes      = new NativeArray <AgentMovement>(1, Allocator.Persistent);

            movementTypes[0] = new AgentMovement()
            {
                mass = 1f, topSpeed = 1f, turnSpeed = 1f
            };

            int height = 1;

            CollisionBehavior job = new CollisionBehavior()
            {
                minDistance     = 0.01f,
                movement        = agentMovementTypes,
                movementConfigs = movementTypes,
                collision       = new AgentCollision()
                {
                    radius = 0.5f, height = height
                },
                steering = steering,
                agents   = agents,
            };

            /// test no steering forces are applied
            /// when the target and source are the same

            SpatialMapData target = new SpatialMapData()
            {
                position = float3.zero, height = height
            };

            job.ApplyCollisionForce(0, target);
            Assert.AreEqual(float3.zero, steering[0]);
            steering[0] = float3.zero;

            /// test steering forces can be applied
            /// when the agents are within collision distance

            target = new SpatialMapData()
            {
                mass     = 1f, radius = 0.5f,
                position = new float3(1f, 0, 0),
                height   = height
            };

            job.ApplyCollisionForce(0, target);
            Assert.AreEqual(new float3(-1f, 0, 0), steering[0]);

            agents.Dispose();
            steering.Dispose();
            movementTypes.Dispose();
            agentMovementTypes.Dispose();
        }
Ejemplo n.º 3
0
        public bool IsPhasing; //Used for Blinking? maybe deal damage to self if stuck in enemy to discourage it


        public CollisionComponent(CollisionBehavior behavior = CollisionBehavior.Block, AABB collisionRectangle = new AABB(), Vector2 offset = new Vector2(), bool isWall = false, bool isPhysical = false)
        {
            Behavior = behavior;
            SetIsPhysical();
            CollisionRectangle = collisionRectangle;
            Offset             = offset;
            IsWall             = isWall;
            IsPhysical         = isPhysical;
        }
Ejemplo n.º 4
0
 public Entity(State _state, Texture2D _image, string _tag = "Entity [Default]",
               Vector2?_pos    = null, float _size          = 0.0f,
               float _rotation = 0f, ScrollBehavior _scroll = ScrollBehavior.Wrap,
               CollisionBehavior _collision = CollisionBehavior.Null,
               bool _enabled = false, bool _visible         = false,
               bool _drawGUI = false, ControlScheme _schema = null,
               ColorSet _set = null)
 {
     Initialize(_state, _image, _tag, _pos, _size, _rotation, _set, _scroll, _collision, _enabled, _visible, _drawGUI, _schema);
 }
Ejemplo n.º 5
0
        /// <summary>
        /// Determines if this entity has the specified collision behavior.
        /// </summary>
        /// <param name="behavior">Behavior to check for.</param>
        /// <returns>Returns true if behavior is included in collisionModes.</returns>
        public bool HasCollisionBehavior(CollisionBehavior behavior)
        {
            foreach (CollisionBehavior mode in collisionModes)
            {
                if (behavior == mode)
                {
                    return(true);
                }
            }

            return(false);
        }
Ejemplo n.º 6
0
        public void CanCheckForCollisions()
        {
            int             height = 1;
            float           radius = 1f;
            float3          start  = new float3(0.25f, 0, 0);
            AgentKinematics self   = new AgentKinematics()
            {
                position = float3.zero
            };
            SpatialMapData target = new SpatialMapData()
            {
                position = start, height = height
            };

            CollisionBehavior job = new CollisionBehavior()
            {
                minDistance = 0.01f,
                collision   = new AgentCollision()
                {
                    radius = radius, height = height
                }
            };

            /// test 2D circle intersection

            bool result;

            result = job.Collision(self, target);
            Assert.AreEqual(true, result);      // inside

            target.position += new float3(0.25f, 0, 0);
            result           = job.Collision(self, target);
            Assert.AreEqual(true, result);      // on the edge

            target.position += new float3(1f, 0, 0);
            result           = job.Collision(self, target);
            Assert.AreEqual(false, result);     // outside

            /// test height intersection

            target.position = new float3(0, 0.5f, 0);
            result          = job.Collision(self, target);
            Assert.AreEqual(true, result);      // inside (collision)

            target.position = new float3(0, 1f, 0);
            result          = job.Collision(self, target);
            Assert.AreEqual(false, result);      // above (no collision)

            target.position = new float3(0, -1f, 0);
            result          = job.Collision(self, target);
            Assert.AreEqual(false, result);      // below (no collision)
        }
Ejemplo n.º 7
0
    private void Awake()
    {
        if (Instance)
        {
            Destroy(this);
            return;
        }

        Instance = this;

        spawnPos      = transform.position;
        movement      = GetComponent <Movement>();
        gravity       = GetComponent <Gravity>();
        colBehavior   = GetComponent <CollisionBehavior>();
        col           = GetComponent <Collider2D>();
        rend          = GetComponent <SpriteRenderer>();
        trail         = GetComponent <TrailRenderer>();
        deadDetection = GetComponent <DeadDetection>();
    }
Ejemplo n.º 8
0
 protected void Initialize(State _state,
                           Texture2D _image, string _tag = "Entity [Default]",
                           Vector2?_pos                 = null, float _size = 0.0f,
                           float _rotation              = 0f, ColorSet _set = null,
                           ScrollBehavior _scroll       = ScrollBehavior.Wrap,
                           CollisionBehavior _collision = CollisionBehavior.Null,
                           bool _enabled                = false, bool _visible         = false,
                           bool _drawGUI                = false, ControlScheme _schema = null)
 {
     SetState(_state);              // Store the current state.
     SetImage(_image);              // File the image to draw with.
     SetTag(_tag);                  // Add a tag for the element.
     SetColorSet(_set);             // Set the colors we'd like to use.
     SetDimensions(_size);          // By default, base the size off of the image's picture.
     SetRotation(_rotation);        // By default this will be 0, but, we can customize on creation. Useful for spawning.
     SetScrollModes(_scroll);       // Wrap entity by default.
     SetCollisionModes(_collision); // Do not collide by default.
     SetFlags(_enabled, _visible);  // Set these flags up by default.
     CreateControlScheme(_schema);
 }
Ejemplo n.º 9
0
        public static List<ICommand> GetDiffCommands(string sourcePath, string targetPath, CollisionBehavior collisionBehavior = CollisionBehavior.Undefined)
        {
            var targetManager = Factory.Instance.GetSourceDataManager();
              var sourceManager = Factory.Instance.GetTargetDataManager();

              sourceManager.SerializationPath = sourcePath;
              targetManager.SerializationPath = targetPath;

              IDataIterator sourceDataIterator = sourceManager.ItemIterator;
              IDataIterator targetDataIterator = targetManager.ItemIterator;

              var engine = new DataEngine();

              var commands = new List<ICommand>();
              commands.AddRange(GenerateDiff(sourceDataIterator, targetDataIterator));
            //if an item is found to be deleted AND added, we can be sure it's a move
              var deleteCommands = commands.OfType<DeleteItemCommand>();
              var shouldBeUpdateCommands =
              commands.OfType<AddItemCommand>()
              .Select(a => new
              {
                  Added = a,
                  Deleted = deleteCommands.FirstOrDefault(d => d.ItemID == a.ItemID)
              }).Where(u => u.Deleted != null).ToList();
              foreach (var command in shouldBeUpdateCommands)
              {
              commands.AddRange(command.Deleted.GenerateUpdateCommand(command.Added));
              commands.Remove(command.Added);
              commands.Remove(command.Deleted);
              //now, this one is an assumption, but would go wrong without the assumption anyway: this assumption is in fact safer
              //if the itempath of a delete command starts with this delete command, it will be moved along to the new node, not deleted, just leave it alone
              commands.RemoveAll(c => c is DeleteItemCommand && ((DeleteItemCommand)c).ItemPath.StartsWith(command.Deleted.ItemPath));
              }

              commands.ForEach(_ => _.CollisionBehavior = collisionBehavior);

              engine.ProcessCommands(ref commands);
              return commands;
        }
Ejemplo n.º 10
0
 public VelocityModifier(Vector2 modifier, CollisionBehavior behavior, float parameter = 1.0f)
 {
     this.Modifier  = modifier;
     this.Behavior  = behavior;
     this.Parameter = parameter;
 }
Ejemplo n.º 11
0
        public static List <ICommand> GetDiffCommands(HashSet <string> targetItemIDs, CollisionBehavior collisionBehavior,
                                                      IDataIterator sourceDataIterator, IDataIterator targetDataIterator, DataEngine engine)
        {
            var commands = new List <ICommand>();

            commands.AddRange(GenerateDiff(sourceDataIterator, targetDataIterator));

            //if an item is found to be deleted AND added, we can be sure it's a move
            var deleteCommands         = commands.OfType <DeleteItemCommand>();
            var shouldBeUpdateCommands =
                commands.OfType <AddItemCommand>()
                .Select(a => new
            {
                Added   = a,
                Deleted = deleteCommands.FirstOrDefault(d => d.ItemID == a.ItemID)
            }).Where(u => u.Deleted != null).ToList();

            foreach (var command in shouldBeUpdateCommands)
            {
                commands.AddRange(command.Deleted.GenerateUpdateCommand(command.Added));
                commands.Remove(command.Added);
                commands.Remove(command.Deleted);

                //now, this one is an assumption, but would go wrong without the assumption anyway: this assumption is in fact safer
                //if the itempath of a delete command starts with this delete command, it will be moved along to the new node, not deleted, just leave it alone
                //but we will skip items which are not in the target folder
                commands.RemoveAll(c =>
                                   c is DeleteItemCommand &&
                                   ((DeleteItemCommand)c).ItemPath.StartsWith(command.Deleted.ItemPath) &&
                                   targetItemIDs.Contains(((DeleteItemCommand)c).ItemID));
            }

            commands.ForEach(_ => _.CollisionBehavior = collisionBehavior);
            return(commands);
        }
Ejemplo n.º 12
0
 public VelocityModifier(Vector2 modifier, CollisionBehavior behavior)
 {
     this.Modifier = modifier;
     this.Behavior = behavior;
 }
Ejemplo n.º 13
0
 public CollisionComponent()
 {
     _collisionBehavior = CollisionBehavior.None;
 }
Ejemplo n.º 14
0
        public static List <ICommand> GetDiffCommands(string sourcePath, string targetPath, CollisionBehavior collisionBehavior = CollisionBehavior.Undefined)
        {
            var targetManager = Factory.Instance.GetSourceDataManager();
            var sourceManager = Factory.Instance.GetTargetDataManager();

            sourceManager.SerializationPath = sourcePath;
            targetManager.SerializationPath = targetPath;

            IDataIterator sourceDataIterator = sourceManager.ItemIterator;
            IDataIterator targetDataIterator = targetManager.ItemIterator;

            var engine = new DataEngine();

            var commands = new List <ICommand>();

            commands.AddRange(GenerateDiff(sourceDataIterator, targetDataIterator));
            //if an item is found to be deleted AND added, we can be sure it's a move
            var deleteCommands         = commands.OfType <DeleteItemCommand>();
            var shouldBeUpdateCommands =
                commands.OfType <AddItemCommand>()
                .Select(a => new
            {
                Added   = a,
                Deleted = deleteCommands.FirstOrDefault(d => d.ItemID == a.ItemID)
            }).Where(u => u.Deleted != null).ToList();

            foreach (var command in shouldBeUpdateCommands)
            {
                commands.AddRange(command.Deleted.GenerateUpdateCommand(command.Added));
                commands.Remove(command.Added);
                commands.Remove(command.Deleted);
                //now, this one is an assumption, but would go wrong without the assumption anyway: this assumption is in fact safer
                //if the itempath of a delete command starts with this delete command, it will be moved along to the new node, not deleted, just leave it alone
                commands.RemoveAll(c => c is DeleteItemCommand && ((DeleteItemCommand)c).ItemPath.StartsWith(command.Deleted.ItemPath));
            }

            commands.ForEach(_ => _.CollisionBehavior = collisionBehavior);

            engine.ProcessCommands(ref commands);
            return(commands);
        }
Ejemplo n.º 15
0
        public static List <ICommand> GetDiffCommands(string sourcePath, string targetPath, bool includeSecurity, string version, CollisionBehavior collisionBehavior = CollisionBehavior.Undefined)
        {
            IncludeSecurity = includeSecurity;
            Version         = version;

            var sourceManager = Factory.Instance.GetSourceDataManager();
            var targetManager = Factory.Instance.GetTargetDataManager();

            sourceManager.SerializationPath = sourcePath;
            targetManager.SerializationPath = targetPath;

            IDataIterator sourceDataIterator = sourceManager.ItemIterator ?? new EmptyIterator();
            IDataIterator targetDataIterator = targetManager.ItemIterator;

            var commands = GetCommands(sourceDataIterator, targetDataIterator);
            var engine   = new DataEngine();

            engine.ProcessCommands(ref commands);
            return(commands);
        }
Ejemplo n.º 16
0
        public static List <ICommand> GetDiffCommands(string sourcePath, string targetPath, CollisionBehavior collisionBehavior = CollisionBehavior.Undefined)
        {
            var sourceManager = Factory.Instance.GetSourceDataManager();
            var targetManager = Factory.Instance.GetTargetDataManager();

            sourceManager.SerializationPath = sourcePath;
            targetManager.SerializationPath = targetPath;

            IDataIterator sourceDataIterator = sourceManager.ItemIterator ?? new EmptyIterator();
            IDataIterator targetDataIterator = targetManager.ItemIterator;

            var engine        = new DataEngine();
            var targetItemIDs = GetItemIDs(targetPath);
            var commands      = GetDiffCommands(targetItemIDs, collisionBehavior, sourceDataIterator, targetDataIterator, engine);

            engine.ProcessCommands(ref commands);
            return(commands);
        }
Ejemplo n.º 17
0
 public CollisionComponent()
 {
     _collisionBehavior = CollisionBehavior.None;
 }
Ejemplo n.º 18
0
 public VelocityModifier(Vector2 modifier, CollisionBehavior behavior)
 {
     this.Modifier = modifier;
     this.Behavior = behavior;
 }