Ejemplo n.º 1
0
        private Joint AddJoint(Segment entityA, Segment entityB, Scrap.GameElements.Entities.Direction direction, Vector2 anchorOffset)
        {
            Joint joint;

            joint = JointFactory.CreateWeldJoint(game.world, entityA.GetJointAnchor(direction), entityB.GetJointAnchor(direction), new Vector2(0, 0), anchorOffset);
            joints.Add(joint);
            return(joint);
        }
Ejemplo n.º 2
0
        public void JoinEntities(Segment entityA, Segment entityB, Scrap.GameElements.Entities.Direction direction)
        {
            entities.Add(entityB);
            Point   gridOffset = entityA.constructElement.offSet;
            Vector2 anchorOffset;
            Joint   joint;

            switch (direction)
            {
            case Direction.Right:
                gridOffset  += new Point(1, 0);
                anchorOffset = new Vector2(-1.2f, 0);

                break;

            case Direction.Left:
                gridOffset  += new Point(-1, 0);
                anchorOffset = new Vector2(1.2f, 0);
                break;

            case Direction.Up:
                gridOffset  += new Point(0, 1);
                anchorOffset = new Vector2(0, 1.2f);
                break;

            case Direction.Down:    //ToDo: possible bug
                gridOffset  += new Point(0, -1);
                anchorOffset = new Vector2(0, -1.2f);
                break;

            default:
                gridOffset  += new Point(0, 1);
                anchorOffset = new Vector2(0, -1.2f);
                break;
            }
            if (!buildElements.ContainsKey(gridOffset))
            {
                joint = AddJoint(entityA, entityB, direction, anchorOffset);
                entityB.constructElement = new ConstructElement(this.game, entityB, this, gridOffset, joint);
                entityA.constructElement.branchJoints.Add(joint);
                buildElements.Add(gridOffset, entityB.constructElement);
                entityB.AddSensors();
            }
        }
Ejemplo n.º 3
0
        public static Vector2 GetSensorOffset(Scrap.GameElements.Entities.Direction direction)
        {
            Vector2 offset = Vector2.Zero;

            if (direction == Direction.Right)
            {
                offset = Vector2.UnitX * OFFSET;
            }
            if (direction == Direction.Left)
            {
                offset = Vector2.UnitX * -OFFSET;
            }
            if (direction == Direction.Down)
            {
                offset = Vector2.UnitY * OFFSET;
            }
            if (direction == Direction.Up)
            {
                offset = Vector2.UnitY * -OFFSET;
            }
            return(offset);
        }