Exemple #1
0
        public static CollisionResult WithAtPos( string[] types, ICollider collider, float x, float y )
        {
            foreach (var type in types) {

                HashSet<ICollider> colliders;
                typeCache.TryGetValue(type, out colliders);

                if (colliders != null) {
                    foreach (var col in colliders) {
                        // @TODO check center distances for optimisation? or full quadtree?
                        if (col.isActive() && col != collider) {
                            var intersect = collider.Intersect(col, x, y);

                            if (intersect.Intersect && (intersect.MinimumTranslation.x != 0 || intersect.MinimumTranslation.y != 0) )
                            {
                                return intersect;
                            }
                        }
                    }
                }
            }

            return new CollisionResult() {
                Intersect = false
            };
        }
Exemple #2
0
        public override CollisionResult Intersect(ICollider col, float speedX, float speedY)
        {
            if (col is Hitbox) {
                var res = IntersectHitbox(col as Hitbox, speedX, speedY);

                return new CollisionResult() {
                    Intersect = res.Intersect,
                    MinimumTranslation = res.MinimumTranslation,
                    Collider = col,
                    CollisionObject = col.GetGameObject()
                };
            }

            if (col is Polybox) {
                var res = IntersectPolybox(col as Polybox, speedX, speedY);

                return new CollisionResult() {
                    Intersect = res.Intersect || res.WillIntersect,
                    MinimumTranslation = res.MinimumTranslation,
                    Collider = col,
                    CollisionObject = col.GetGameObject()
                };
            }

            Logging.Log("Collision type not supported for", this, col);

            return new CollisionResult() {
                Intersect = false
            };
        }
        public AGSCheckBox(string id, Resolver resolver) : base(id, resolver)
        {            
            _uIEvents = AddComponent<IUIEvents>();            
            _skinComponent = AddComponent<ISkinComponent>();            
            _hasRoom = AddComponent<IHasRoom>();            
            _animationContainer = AddComponent<IAnimationContainer>();            
            _inObjectTree = AddComponent<IInObjectTree>();            
            _collider = AddComponent<ICollider>();            
            _visibleComponent = AddComponent<IVisibleComponent>();            
            _enabledComponent = AddComponent<IEnabledComponent>();            
            _customProperties = AddComponent<ICustomPropertiesComponent>();            
            _drawableInfo = AddComponent<IDrawableInfo>();            
            _hotspotComponent = AddComponent<IHotspotComponent>();            
            _shaderComponent = AddComponent<IShaderComponent>();            
            _translateComponent = AddComponent<ITranslateComponent>();            
            _imageComponent = AddComponent<IImageComponent>();            
            _scaleComponent = AddComponent<IScaleComponent>();            
            _rotateComponent = AddComponent<IRotateComponent>();            
            _pixelPerfectComponent = AddComponent<IPixelPerfectComponent>();            
            _textComponent = AddComponent<ITextComponent>();            
            _checkboxComponent = AddComponent<ICheckboxComponent>();
			beforeInitComponents(resolver);            
			InitComponents();
            afterInitComponents(resolver);            
        }
        public AGSCharacter(string id, Resolver resolver, IOutfit outfit) : base(id, resolver)
        {            
            _hasRoom = AddComponent<IHasRoom>();            
            _animationContainer = AddComponent<IAnimationContainer>();            
            _inObjectTree = AddComponent<IInObjectTree>();            
            _collider = AddComponent<ICollider>();            
            _visibleComponent = AddComponent<IVisibleComponent>();            
            _enabledComponent = AddComponent<IEnabledComponent>();            
            _customProperties = AddComponent<ICustomPropertiesComponent>();            
            _drawableInfo = AddComponent<IDrawableInfo>();            
            _hotspotComponent = AddComponent<IHotspotComponent>();            
            _shaderComponent = AddComponent<IShaderComponent>();            
            _transformComponent = AddComponent<ITranslateComponent>();            
            _imageComponent = AddComponent<IImageComponent>();            
            _scaleComponent = AddComponent<IScaleComponent>();            
            _rotateComponent = AddComponent<IRotateComponent>();            
            _pixelPerfectComponent = AddComponent<IPixelPerfectComponent>();            
            _faceDirectionBehavior = AddComponent<IFaceDirectionBehavior>();            
            _hasOutfit = AddComponent<IHasOutfit>();            
            _hasInventory = AddComponent<IHasInventory>();            
            _followBehavior = AddComponent<IFollowBehavior>();
			beforeInitComponents(resolver, outfit);            
			InitComponents();
            afterInitComponents(resolver, outfit);            
        }
		public override void Init(IEntity entity)
		{
			base.Init(entity);
			_collider = entity.GetComponent<ICollider>();
			_drawableInfo = entity.GetComponent<IDrawableInfo>();
			_tree = entity.GetComponent<IInObjectTree>();
			_visible = entity.GetComponent<IVisibleComponent>();
			_enabled = entity.GetComponent<IEnabledComponent>();
			_gameEvents.OnRepeatedlyExecute.Subscribe(onRepeatedlyExecute);
		} 
Exemple #6
0
        public static void UnassignFromType(ICollider col, string type)
        {
            HashSet<ICollider> colliders;

            typeCache.TryGetValue(type, out colliders);

            if (colliders == null) {
                    colliders = new HashSet<ICollider>();
                    typeCache.Add(type, colliders);
            }

            colliders.Remove(col);
        }
        /// <summary>
        /// Devuelve si hay o no colisión entre dos nodos del grafo de escena 
        /// que tengan un collider asociado
        /// </summary>
        /// <param name="vector">vector</param>
        /// <returns>longitud del vector</returns>
        public static bool Collision(ICollider lhs, ICollider rhs)
        {
            Collider colliderL = lhs.GetCollider();
            Collider colliderR = rhs.GetCollider();

            // los dos collider son rectangulos
            if (colliderL.IsCircle == false && colliderR.IsCircle ==  false)
                return ((ColliderRect)colliderL).Intersects(((ColliderRect)colliderR));
            // TODO: interseccion entre otros colliders
            //else if (colliderL.IsCircle && colliderR.IsCircle)    // los dos son círculos
            //    return colliderL.Circle.Intersects(colliderL.Circle);
            //else if (!colliderL.IsCircle && colliderR.IsCircle)
            //    return colliderR.Circle.Intersects(colliderL.Rectangle);
            //else
            //    return colliderL.Circle.Intersects(colliderR.Rectangle);

            return false;

        }
Exemple #8
0
        public RaycastHit(Vector3 point,
		                  Vector3 normal,
		                  Vector3 barycentricCoordinate,
		                  float distance,
		                  int triangleIndex,
		                  Vector2 textureCoord,
		                  Vector2 textureCoord2,
		                  Vector2 lightmapCoord,
		                  IGameObject hit,
		                  ICollider collider)
            : this()
        {
            this.point = point;
            this.normal = normal;
            this.barycentricCoordinate = barycentricCoordinate;
            this.distance = distance;
            this.triangleIndex = triangleIndex;
            this.textureCoord = textureCoord;
            this.textureCoord2 = textureCoord2;
            this.lightmapCoord = lightmapCoord;
            this.hit = hit;
            this.collider = collider;
        }
 /// <summary>
 /// Devuelve un par ordenado, es decir, el nodo con HashID más bajo delente
 /// </summary>
 /// <param name="lhs">Primer Collider</param>
 /// <param name="rhs">Segundo Collider</param>
 /// <returns>un objeto tipo pair de SceneNode ordenados</returns>
 public static Tuple<Scenes.SceneNode,Scenes.SceneNode> GetSortedPair(ICollider lhs, ICollider rhs) 
 {
     return (lhs.GetHashCode() > rhs.GetHashCode()) ? 
         new Tuple<Scenes.SceneNode, Scenes.SceneNode>((Scenes.SceneNode)rhs, (Scenes.SceneNode)lhs) : 
         new Tuple<Scenes.SceneNode, Scenes.SceneNode>((Scenes.SceneNode)lhs, (Scenes.SceneNode)rhs);
 }
Exemple #10
0
 public void BindCollider(ICollider collider)
 {
     _collider = collider;
 }
Exemple #11
0
 public virtual CollisionResult Intersect(ICollider col, float speedX, float speedY)
 {
     return new CollisionResult() {
         Intersect = false
     };
 }
        /// <summary>
        /// Checks two objects to see if a collision has occured
        /// </summary>
        /// <param name="obj1">First ICollider object</param>
        /// <param name="obj2">Second ICollider object</param>
        /// <returns>True if a collision has occured, false otherwise</returns>
        public bool CheckCollision(ICollider obj1, ICollider obj2)
        {
            //If either object is not collidable return false
            if (!(obj1.IsColliable && obj2.IsColliable))
                return false;

            if (obj1.CollideType == ColliderType.Circle)
            {
                if (obj2.CollideType == ColliderType.Circle)
                {
                    //A collision occurs if the distance between the two centers is less than
                    //the sum of their radii
                    return (Vector2.Distance(obj1.Center, obj2.Center) < (obj1.Norm + obj2.Norm));
                }
            }

            //Default value
            return false;
        }
 /// <summary>
 /// Checks two objects to see if a collision has occured
 /// </summary>
 /// <param name="obj1">First ICollider object</param>
 /// <param name="obj2">Second ICollider object</param>
 /// <returns>True if a collision has occured, false otherwise</returns>
 bool ICollisionService.CheckCollision(ICollider obj1, ICollider obj2)
 {
     return this.CheckCollision(obj1, obj2);
 }
Exemple #14
0
 public static CollisionResult WithAtPos( string type, ICollider collider, float x, float y )
 {
     return WithAtPos (new string[] {type}, collider, x, y);
 }
Exemple #15
0
 public static CollisionResult With(string[] types, ICollider collider )
 {
     return WithAtPos (types, collider, collider.GetPosition().x, collider.GetPosition().y);
 }
Exemple #16
0
        private bool DiscreteCD(ICollider[] obj1Colliders,Vector3 obj1Pos, ICollider obj2Collider, Vector3 obj2Pos)
        {
            bool collision = false;
            //Get obj2 colliders center pos in world cords not objectCord
            Vector3 obj2colliderPos = obj2Collider.m_Centre.ReturnAddVector(obj2Pos);

            foreach (ICollider obj1Collider in obj1Colliders)
            {
                //Get obj1 colliders center pos in world cords not objectCord
                Vector3 obj1colliderPos = obj1Collider.m_Centre.ReturnAddVector(obj1Pos);

                if (obj1Collider.m_Size!=null)
                {
                    //two boxes
                    if (obj2Collider.m_Size!=null)
                    {
                        return BoxBoxCollision(obj1colliderPos, obj1Collider.m_Size, obj2colliderPos, obj2Collider.m_Size);
                    }

                    // box and sphere
                    else if (obj2Collider.m_Radius.HasValue)
                    {
                        return SphereBoxCollision(obj1colliderPos, obj2Collider.m_Radius.Value, obj1colliderPos, obj2Collider.m_Size);
                    }
                }

                else if (obj1Collider.m_Radius.HasValue)
                {
                    //sphere and box
                    if (obj2Collider.m_Size!=null)
                    {
                        return SphereBoxCollision(obj1colliderPos, obj1Collider.m_Radius.Value, obj2colliderPos, obj2Collider.m_Size);
                    }
                    //Two spheres
                    else if (obj2Collider.m_Radius.HasValue)
                    {
                        return SphereSphereCollision(obj1colliderPos, obj1Collider.m_Radius.Value, obj2colliderPos, obj2Collider.m_Radius.Value);
                    }
                }

            }
            return collision;
        }
Exemple #17
0
        public override CollisionResult Intersect(ICollider col, float speedX, float speedY)
        {
            if (col is Hitbox) {
                return IntersectHitbox(col as Hitbox, speedX, speedY);
            }

            if (col is Polybox) {
                return IntersectPolybox(col as Polybox, speedX, speedY);
            }

            Logging.Log("Collision type not supported for", this, col);

            return new CollisionResult() {
                Intersect = false
            };
        }
 /// <summary>
 /// Removes a collider from the list of registered colliders.
 /// </summary>
 /// <param name="collider">The collider to remove</param>
 void ICollisionService.DeregisterCollider(ICollider collider)
 {
     _allColliders.Remove(collider);
 }
 /// <summary>
 /// Registers a new collider with the component.  Will check to be
 /// sure the collider isn't already on the list.
 /// </summary>
 /// <param name="collider">The collider to add</param>
 void ICollisionService.RegisterCollider(ICollider collider)
 {
     //Check if the collider has been previously registered
     if (!(_allColliders.Contains(collider)))
         _allColliders.Add(collider);
 }
Exemple #20
0
 public static CollisionResult With(string type, ICollider collider )
 {
     return WithAtPos (new string[] {type}, collider, collider.GetPosition().x, collider.GetPosition().y);
 }
Exemple #21
0
        private bool ContinuousCD(ICollider[] obj1Colliders, Vector3 obj1Pos, ICollider obj2Collider, Vector3 obj2Pos)
        {
            bool collision = false;

            return collision;
        }