示例#1
0
        /// <summary>
        /// See return value. Fills hitSquaresForFunctionThatChecksCollisions with blocks hit
        /// </summary>
        /// <param name="box">Box for which to check collisions</param>
        /// <param name="property">Property to check for</param>
        /// <param name="pushAway">Solve collisions</param>
        /// <returns>True if a solid block is hit</returns>
        private bool CollisionWithTiles_RealTime(CollisionBox box, string property, bool pushAway = false)
        {
            hitSquares_RealTime = new List <MapSquare>(); // hitSquares: those touching
            box.SetParent(this);
            CheckEnvironment(hitSquares_RealTime, box, pushAway);

            return(CheckIfOneTileHitContainProperty_RealTime(property));
        }
        public override void LoadXml(XElement xml)
        {
            foreach (XElement boxnode in xml.Elements("Hitbox"))
            {
                CollisionBox box = new CollisionBox(boxnode);
                box.SetParent(this);
                AddBox(box);
            }

            Enabled = xml.TryAttribute <bool>("Enabled");
        }
示例#3
0
        internal void Loadinfo(CollisionComponentInfo info)
        {
            Enabled = info.Enabled;

            foreach (var box in info.HitBoxes)
            {
                var coll = new CollisionBox(box);
                coll.SetParent(this);
                AddBox(coll);
            }
        }
示例#4
0
        /// <summary>
        /// See return value. Fills hitBlockEntities with all/solid (see param solidOnly) entities hit
        /// </summary>
        /// <param name="box">Box for which to check collisions</param>
        /// <param name="property">Property to check for</param>
        /// <param name="solidOnly">Only checks for solid entities</param>
        /// <param name="pushAway">Solve collisions</param>
        /// <returns>True if an entity solid/not (see param solidOnly) is hit</returns>
        private bool CollisionWithAllEntities_RealTime(CollisionBox box, string property, bool solidOnly = true, bool pushAway = false)
        {
            box.SetParent(this);

            Rectangle boundbox = box.BoxAt(PositionSrc.Position); //calculate boundbox absolute coordinate

            hitBlockEntities_RealTime = new List <Collision>();

            boundbox = CheckEntityCollisions(hitBlockEntities_RealTime, box, boundbox, pushAway, solidOnly);

            return(CheckIfOneEntityHitContainProperty_RealTime(property));
        }
示例#5
0
        private void ReactForHitbox(List <MapSquare> hitSquares, HashSet <TileProperties> hitTypes, CollisionBox hitbox)
        {
            hitbox.SetParent(this);

            var boundBox = hitbox.BoxAt(PositionSrc.Position);

            if (hitbox.Environment)
            {
                foreach (MapSquare tile in hitSquares)
                {
                    var  tileBox  = tile.BlockBox;
                    bool downonly = (!Parent.Container.IsGravityFlipped && tile.Tile.Properties.Climbable);
                    bool uponly   = (Parent.Container.IsGravityFlipped && tile.Tile.Properties.Climbable);

                    bool hit = (tile.BlockBox != Rectangle.Empty) ? BlockByIntersection(boundBox, tileBox, uponly, downonly) : boundBox.IntersectsWith(tile.BoundBox);

                    if (hitbox.PushAway && (hit || boundBox.IntersectsWith(tile.BoundBox)))    // the environment touched me!
                    {
                        hitTypes.Add(tile.Tile.Properties);
                    }
                }
            }

            // but for entities, we can go ahead and be active aggressors -
            // inflict our effects on the target entity, not the other way around
            foreach (var entity in Parent.Entities.GetAll())
            {
                if (entity == Parent)
                {
                    continue;
                }
                CollisionComponent coll = entity.GetComponent <CollisionComponent>();
                if (coll == null)
                {
                    continue;
                }

                foreach (CollisionBox targetBox in coll.TargetBoxes(hitbox))
                {
                    boundBox = CheckTargetBox(hitbox, boundBox, entity, coll, targetBox);
                }
            }
        }
示例#6
0
        private void ReactForHitbox(List<MapSquare> hitSquares, HashSet<TileProperties> hitTypes, CollisionBox hitbox)
        {
            hitbox.SetParent(this);

            RectangleF boundBox = hitbox.BoxAt(PositionSrc.Position);

            if (hitbox.Environment)
            {
                foreach (MapSquare tile in hitSquares)
                {
                    RectangleF tileBox = tile.BlockBox;
                    bool downonly = (!Parent.Container.IsGravityFlipped && tile.Tile.Properties.Climbable);
                    bool uponly = (Parent.Container.IsGravityFlipped && tile.Tile.Properties.Climbable);

                    bool hit = (tile.BlockBox != RectangleF.Empty) ? BlockByIntersection(boundBox, tileBox, uponly, downonly) : boundBox.IntersectsWith(tile.BoundBox);

                    if (hitbox.PushAway && (hit || boundBox.IntersectsWith(tile.BoundBox)))    // the environment touched me!
                    {
                        hitTypes.Add(tile.Tile.Properties);
                    }
                }
            }

            // but for entities, we can go ahead and be active aggressors -
            // inflict our effects on the target entity, not the other way around
            foreach (var entity in Parent.Entities.GetAll())
            {
                if (entity == Parent) continue;
                CollisionComponent coll = entity.GetComponent<CollisionComponent>();
                if (coll == null) continue;

                foreach (CollisionBox targetBox in coll.TargetBoxes(hitbox))
                {
                    boundBox = CheckTargetBox(hitbox, boundBox, entity, coll, targetBox);
                }
            }
        }
示例#7
0
        public override void LoadXml(XElement xml)
        {
            foreach (XElement boxnode in xml.Elements("Hitbox"))
            {
                CollisionBox box = new CollisionBox(boxnode);
                box.SetParent(this);
                AddBox(box);
            }

            Enabled = xml.TryAttribute<bool>("Enabled");
        }
        /// <summary>
        /// See return value. Fills hitSquaresForFunctionThatChecksCollisions with blocks hit
        /// </summary>
        /// <param name="box">Box for which to check collisions</param>
        /// <param name="property">Property to check for</param>
        /// <param name="pushAway">Solve collisions</param>
        /// <returns>True if a solid block is hit</returns>
        private bool CollisionWithTiles_RealTime(CollisionBox box, string property, bool pushAway = false)
        {
            hitSquares_RealTime = new List<MapSquare>(); // hitSquares: those touching
            box.SetParent(this);
            CheckEnvironment(hitSquares_RealTime, box, pushAway);

            return CheckIfOneTileHitContainProperty_RealTime(property);
        }
        /// <summary>
        /// See return value. Fills hitBlockEntities with all/solid (see param solidOnly) entities hit
        /// </summary>
        /// <param name="box">Box for which to check collisions</param>
        /// <param name="property">Property to check for</param>
        /// <param name="solidOnly">Only checks for solid entities</param>
        /// <param name="pushAway">Solve collisions</param>
        /// <returns>True if an entity solid/not (see param solidOnly) is hit</returns>
        private bool CollisionWithAllEntities_RealTime(CollisionBox box, string property, bool solidOnly = true, bool pushAway = false)
        {
            box.SetParent(this);

            RectangleF boundbox = box.BoxAt(PositionSrc.Position); //calculate boundbox absolute coordinate
            hitBlockEntities_RealTime = new List<Collision>();

            boundbox = CheckEntityCollisions(hitBlockEntities_RealTime, box, boundbox, pushAway, solidOnly);

            return CheckIfOneEntityHitContainProperty_RealTime(property);
        }
        internal void Loadinfo(CollisionComponentInfo info)
        {
            Enabled = info.Enabled;

            foreach (var box in info.HitBoxes)
            {
                var coll = new CollisionBox(box);
                coll.SetParent(this);
                AddBox(coll);
            }
        }