コード例 #1
0
        protected override void CreateScene()
        {
            // Create a 2D camera
            var camera2D = new FixedCamera2D("Camera2D")
            {
                BackgroundColor = Color.CornflowerBlue
            };

            EntityManager.Add(camera2D);

            // Scene creation
            Entity Wheel1 = this.CreateWheel("Wheel1", 150, 300);

            EntityManager.Add(Wheel1);

            Entity Pin1 = this.CreatePin("Pin1", 200, 200);

            EntityManager.Add(Pin1);

            Pin1.AddComponent(new JointMap2D().AddJoint("joint1", new DistanceJoint2D(Wheel1, Vector2.Zero, Vector2.Zero)));

            Entity Wheel2 = this.CreateWheel("Wheel2", 550, 300);

            EntityManager.Add(Wheel2);

            Entity Pin2 = this.CreatePin("Pin2", 600, 200);

            EntityManager.Add(Pin2);

            Pin2.AddComponent(new JointMap2D().AddJoint("joint2", new DistanceJoint2D(Wheel2, Vector2.Zero, Vector2.Zero)));

            // ANGLE JOINT between wheels
            Wheel2.AddComponent(new JointMap2D().AddJoint("joint3", new AngleJoint2D(Wheel1)));

            // Create Ground
            Entity ground = this.CreateGround("ground", 400, 500);

            EntityManager.Add(ground);

            Entity ground2 = this.CreateGround("ground2", 950, 400);

            EntityManager.Add(ground2);

            // Falling Crates controller
            WaveServices.TimerFactory.CreateTimer("CrateFallingTimer", TimeSpan.FromSeconds(2f), () =>
            {
                this.CreateFallingCrate(255);

                if (this.repeats == 10)
                {
                    JointMap2D pinJointMap = Pin2.FindComponent <JointMap2D>();

                    pinJointMap.RemoveJoint("joint2");
                }
            });
        }
コード例 #2
0
ファイル: PlayerController.cs プロジェクト: maral/Eyed
        public Entity DetachEye()
        {
            JointMap2D jointMap = eye.FindComponent <JointMap2D>();

            jointMap.ClearJoints();
            Entity lostEye = eye;

            animState = EyeAnimationState.None;
            eye       = null;
            lostEye.FindComponent <EyeController>().Detach();
            return(lostEye);
        }
コード例 #3
0
        /// <summary>
        /// Update Method
        /// </summary>
        /// <param name="gameTime">Current Game Time</param>
        protected override void Update(TimeSpan gameTime)
        {
            this.input = WaveServices.Input;

            if (this.input.TouchPanelState.IsConnected)
            {
                this.touchState = this.input.TouchPanelState;

                // Checks Mouse Left Button Click and anyone entity linked
                if (this.touchState.Count > 0 && this.mouseJoint == null)
                {
                    // Udpates Mouse Position
                    this.touchPosition = this.touchState[0].Position;

                    foreach (Entity entity in this.Scene.EntityManager.EntityGraph)
                    {
                        Collider2D collider = entity.FindComponent <Collider2D>(false);
                        if (collider != null)
                        {
                            // Collider Test
                            if (collider.Contain(touchPosition))
                            {
                                RigidBody2D rigidBody = entity.FindComponent <RigidBody2D>();
                                if (rigidBody != null)
                                {
                                    // Forbiden Mouse Joint of Kinematic Bodies
                                    if (rigidBody.PhysicBodyType != PhysicBodyType.Kinematic)
                                    {
                                        this.connectedEntity = entity;

                                        // Create Mouse Joint
                                        this.mouseJoint = new FixedMouseJoint2D(this.touchPosition);
                                        JointMap2D jointMap = this.connectedEntity.FindComponent <JointMap2D>();
                                        jointMap.AddJoint("mouseJoint", this.mouseJoint);

                                        // We can break after collider test when true, but we'll miss overlapped entities if Physic entity is
                                        // under a non Physic entity. We are breaking here just for sample.
                                        break;
                                    }
                                }
                            }
                        }
                    }
                }

                // Checks Mouse Left Button Release
                if (this.touchState.Count == 0 && this.mouseJoint != null)
                {
                    if (!this.connectedEntity.IsDisposed)
                    {
                        // Remove Fixed Joint
                        JointMap2D jointMap2D = this.connectedEntity.FindComponent <JointMap2D>();
                        jointMap2D.RemoveJoint("mouseJoint");
                    }

                    this.mouseJoint = null;
                }

                // If joint exists then update joint anchor position
                if (this.mouseJoint != null)
                {
                    this.touchPosition          = this.touchState[0].Position;
                    this.mouseJoint.WorldAnchor = this.touchPosition;
                }
            }
        }