Exemplo n.º 1
0
        public override void Resolve(GameActorPosition target, IAtlas atlas)
        {
            ICanPickGameObject picker    = Sender as ICanPickGameObject;
            ICharacter         character = Sender as ICharacter;

            if (picker == null || character == null)
            {
                return;
            }
            Vector2 positionInFrontOf = target.Position;

            // solving case when positions where character should place tile collides with character's position
            if (target.Actor is Tile)
            {
                Tile            tile               = (target.Actor as Tile);
                IPhysicalEntity physicalEntity     = tile.GetPhysicalEntity(new Vector2I(positionInFrontOf));
                bool            collidesWithSource = physicalEntity.CollidesWith(character.PhysicalEntity);
                if (collidesWithSource)
                {
                    /*  <- change to //* to switch
                     * // to the center of current tile
                     * character.Position = Vector2.Floor(character.Position) + Vector2.One/2;
                     *
                     * /*/
                    // back WRT his direction
                    do
                    {
                        character.Position = Physics.Utils.Move(character.Position, character.Direction, -0.01f);
                    } while (physicalEntity.CollidesWith(character.PhysicalEntity));
                    // */
                }
            }

            GameActorPosition toLayDown = new GameActorPosition(target.Actor, positionInFrontOf, target.Layer);

            bool added = atlas.Add(toLayDown, true);

            if (added)
            {
                picker.RemoveFromInventory();
            }
        }
Exemplo n.º 2
0
        public static List <Tuple <IPhysicalEntity, IPhysicalEntity> > CollidingCouples(List <IPhysicalEntity> physicalEntities)
        {
            List <Tuple <IPhysicalEntity, IPhysicalEntity> > collidingCouples = new List <Tuple <IPhysicalEntity, IPhysicalEntity> >();

            for (int i = 0; i < physicalEntities.Count - 1; i++)
            {
                IPhysicalEntity firstEntity = physicalEntities[i];
                for (int j = i + 1; j < physicalEntities.Count; j++)
                {
                    IPhysicalEntity secondEntity = physicalEntities[j];
                    if (firstEntity.CollidesWith(secondEntity))
                    {
                        collidingCouples.Add(new Tuple <IPhysicalEntity, IPhysicalEntity>(firstEntity, secondEntity));
                    }
                }
            }
            return(collidingCouples);
        }