Exemple #1
0
        protected override void CreateScene()
        {
            FixedCamera2D camera = new FixedCamera2D("camera")
            {
                ClearFlags = WaveEngine.Common.Graphics.ClearFlags.DepthAndStencil
            };

            this.EntityManager.Add(camera);

            var vm = this.VirtualScreenManager;
            float width = vm.RightEdge - vm.LeftEdge;
            float halfWidth = width / 2;
            float height = vm.BottomEdge - vm.TopEdge;

            this.Joystick = new Joystick("joystick", new RectangleF(vm.LeftEdge, vm.TopEdge, halfWidth, height));
            this.EntityManager.Add(this.Joystick);

            this.JumpButton = new JumpButton("jumpButton", new RectangleF(vm.LeftEdge + (halfWidth), vm.TopEdge, halfWidth, height));
            this.EntityManager.Add(this.JumpButton);
        }
        private void HandleJoystick()
        {
            if (this.joystick == null)
            {
                var joystickScene = WaveServices.ScreenContextManager.CurrentContext.FindScene<JoystickScene>();
                if (joystickScene != null)
                {
                    this.joystick = joystickScene.Joystick;
                    this.jumpButton = joystickScene.JumpButton;
                }
            }
            else
            {
                if (this.OnFloor && (joystick.Direction.X != 0))
                {
                    this.RigidBody.ApplyLinearImpulse(Vector2.UnitX * SideImpulse * joystick.Direction.X, this.RigidBody.Transform2D.Position);
                }

                if (this.jumpButton.IsShooting)
                {
                    this.Jump();
                    this.controller = ControllerType.JoystickController;
                    this.isJump = true;
                }
                else
                {
                    if (this.controller == ControllerType.JoystickController)
                    {
                        this.isJump = false;
                    }
                }
            }
        }