Exemple #1
0
        protected override void Initialize()
        {
            SetupWindow();
            SetupGameCommandManager();
            SetupInput();


            var mainScene = Scene.createWithDefaultRenderer();

            //Create component that will represent who owns the entity
            var playerIndexComponent = new PlayerIndexComponent(PlayerIndex.One);

            //Create Action Set Component to hold link between binding device and binded action
            var actionSetComponent = new PlayerActionSetComponent();

            actionSetComponent.PlayerActionSet = new PlayerActionSet();
            actionSetComponent.PlayerActionSet.SetupDefaultBindings();
            actionSetComponent.PlayerActionSet.SetupDefaultKeebBindings();

            //Create controller profile component to hold behavior of actions
            var controlProfileComponent = new ControllerProfileComponent();

            var movementComponent = new MovementComponent();

            //create service to
            var matcher = new Matcher().all(typeof(PlayerActionSetComponent), typeof(ControllerProfileComponent));
            var playerActionSetToControllerProfileSystem = new PlayerActionSetToControllerProfileSystem(matcher);


            matcher = new Matcher().all(typeof(PlayerActionSetComponent));
            var playerActionUpdateSystem = new PlayerActionUpdateSystem(matcher);

            matcher = new Matcher().all(typeof(PlayerIndexComponent), typeof(PlayerActionSetComponent));
            var playerDeviceToActionSet = new PlayerDeviceToActionSetSystem(matcher);


            var entityHero = mainScene.createEntity("Hero");

            entityHero.addComponent(playerIndexComponent);
            entityHero.addComponent(actionSetComponent);
            entityHero.addComponent(controlProfileComponent);
            entityHero.addComponent(movementComponent);

            mainScene.addEntityProcessor(playerDeviceToActionSet);
            mainScene.addEntityProcessor(playerActionSetToControllerProfileSystem);
            mainScene.addEntityProcessor(playerActionUpdateSystem);

            entityHero.getComponent <ControllerProfileComponent>().ControllerProfile = new RoamProfile(entityHero);

            scene = mainScene;

            base.Initialize();
        }
Exemple #2
0
        protected override void Initialize()
        {
            base.Initialize();

            BuildEngines();
            var input = SetupInput();


            List <IImplementor> testEntityImplementors = new List <IImplementor>();

            world = new World(Vector2.Zero);

            var floor = BodyFactory.CreateBody(world);

            var body = BodyFactory.CreateRectangle(world, ConvertUnits.ToSimUnits(64f), ConvertUnits.ToSimUnits(64f), 1f, Vector2.One, bodyType: BodyType.Dynamic);

            body.Mass = 1f;
            body.SetTransform(Vector2.Zero, 0f);


            var rigidBodyComponent = new RigidBodyComponentImplementor(body);
            var forceComponent     = new PhysicsForceComponent();
            var impulseComponent   = new PhysicsImpulseComponent();
            var torqueComponent    = new PhysicsTorqueComponent();

            testEntityImplementors.Add(rigidBodyComponent);
            testEntityImplementors.Add(forceComponent);
            testEntityImplementors.Add(impulseComponent);
            testEntityImplementors.Add(torqueComponent);

            //add movement driver, the vector value inside
            var movementDriverComponent = new MovementDriverComponent();

            var playerActionSetContext   = new PlayerActionContextComponent();
            var playerActionSetComponent = new PlayerActionSetComponent(input.playerActionSetOne);

            var playerActionLeftStickComponent  = new PlayerTwoAxisActionComponent(input.playerActionSetOne.LeftStick);
            var playerActionRightStickComponent = new PlayerTwoAxisActionComponent(input.playerActionSetOne.RightStick);
            var playerActionOneComponent        = new PlayerActionComponent(input.playerActionSetOne.Action1);
            var playerActionTwoComponent        = new PlayerActionComponent(input.playerActionSetOne.Action2);

            testEntityImplementors.Add(movementDriverComponent);
            testEntityImplementors.Add(playerActionOneComponent);
            testEntityImplementors.Add(playerActionTwoComponent);
            testEntityImplementors.Add(playerActionSetComponent);
            testEntityImplementors.Add(playerActionLeftStickComponent);
            testEntityImplementors.Add(playerActionRightStickComponent);
            testEntityImplementors.Add(playerActionSetContext);


            var Joint = JointFactory.CreateFrictionJoint(world, floor, body);

            Joint.MaxForce  = 80f;
            Joint.MaxTorque = 80f;

            var playerActionLeftStickSequencer = new Sequencer();

            var playerActionLeftStickUpdateEngine = new PlayerActionLeftStickUpdateEngine(playerActionLeftStickSequencer);
            var basicMoveEngine             = new BasicMoveEngine();
            var physicsForceEngine          = new PhysicsForceEngine();
            var movementDriverEngine        = new MovementDriverEngine();
            var playerActionSetUpdateEngine = new PlayerActionSetUpdateEngine();

            var testEngine = new TestEngine();

            playerActionLeftStickSequencer.SetSequence(
                new Steps
            {
                {
                    playerActionLeftStickUpdateEngine,
                    new To
                    {
                        { PlayerActionContext.Roam, new IStep[] { basicMoveEngine } },
                        { PlayerActionContext.UI, new IStep[] { basicMoveEngine } },
                    }
                },
                {
                    basicMoveEngine,
                    new To
                    {
                        new IStep[] { testEngine }
//                            {PlayerActionContext.Roam, new IStep[] {basicMoveEngine}},
//                            {PlayerActionContext.UI, new IStep[] {basicMoveEngine}},
                    }
                }
            }

                );


            gameEnginesRoot.AddEngine(testEngine);
            gameEnginesRoot.AddEngine(basicMoveEngine);
            gameEnginesRoot.AddEngine(physicsForceEngine);

            gameEnginesRoot.AddEngine(movementDriverEngine);
            gameEnginesRoot.AddEngine(playerActionSetUpdateEngine);
            gameEnginesRoot.AddEngine(playerActionLeftStickUpdateEngine);

            gameEngineEntityFactory.BuildEntity <TestEntityDescriptor>(1, testEntityImplementors.ToArray());
        }