Ejemplo n.º 1
0
        /// <summary>
        /// Allows the game to perform any initialization it needs to before starting to run.
        /// This is where it can query for any required services and load any non-graphic
        /// related content.  Calling base.Initialize will enumerate through any components
        /// and initialize them as well.
        /// </summary>
        protected override void Initialize()
        {
            GameEntityFactory.GraphicsDevice = GraphicsDevice;

            frameCounterSystem = new FrameCounterSystem(true, this.Window);
            modelRenderSystem  = new ModelRenderSystem();
            modelRenderSystem.graphicsDevice = GraphicsDevice;
            playerInputSystem        = new PlayerInputSystem();
            cameraSystem             = new CameraSystem();
            uiSystem                 = new UIRenderSystem();
            collisionHandlingSystem  = new CollisionHandlingSystem();
            aiSystem                 = new AiSystem();
            collisionDetectionSystem = new CollisionDetectionSystem(false);
            frictionSystem           = new FrictionSystem();
            gravitySystem            = new GravitySystem();
            transformSystem          = new TransformSystem();


            SystemManager.Instance.AddToUpdateables(
                cameraSystem,
                collisionDetectionSystem,
                transformSystem,
                gravitySystem,
                frictionSystem,
                playerInputSystem,
                collisionHandlingSystem,
                aiSystem,
                frameCounterSystem
                );

            SystemManager.Instance.AddToDrawables(modelRenderSystem, frameCounterSystem, uiSystem);

            base.Initialize();
        }
Ejemplo n.º 2
0
        private void InitAi(ECSEngine engine)
        {
            _sm.RegisterSystem("Game", new AiSystem());

            var entity = EntityFactory.Instance.NewEntityWithTag("AiKart");
            var modelC = new ModelComponent(engine.LoadContent <Model>("Chopper"), true, false, false)
            {
                staticModel = false
            };

            ModelRenderSystem.AddMeshTransform(ref modelC, 1, Matrix.CreateRotationY(0.2f));
            ModelRenderSystem.AddMeshTransform(ref modelC, 3, Matrix.CreateRotationY(0.5f));
            ComponentManager.Instance.AddComponentToEntity(entity, modelC);

            //Create waypoints and add the AIComponent.
            var waypoints = CreateWaypoints();

            AiSystem.Waypoints = waypoints;
            var aiC = new AiComponent(waypoints[0], new CountdownState());

            ComponentManager.Instance.AddComponentToEntity(entity, aiC);

            ComponentManager.Instance.AddComponentToEntity(entity, new Collision3Dcomponent());

            var aiKartTransform = new TransformComponent {
                Position = new Vector3(0.0f, 5.0f, 0.0f)
            };

            aiKartTransform.Rotation = Quaternion.CreateFromAxisAngle(Vector3.UnitY, AiSystem.GetRotation(aiKartTransform.Position, aiC.Waypoint.TargetPosition));
            aiKartTransform.Scale    = new Vector3(2.5f, 2.5f, 2.5f);
            ComponentManager.Instance.AddComponentToEntity(entity, aiKartTransform);

            SceneManager.Instance.AddEntityToSceneOnLayer("Game", 3, entity);
            ComponentManager.Instance.AddComponentToEntity(entity, new PhysicsComponent()
            {
                Mass  = 5f,
                Force = new Vector3(15f, 250f, 0)
            });
            ComponentManager.Instance.AddComponentToEntity(entity, new GravityComponent());
            //ComponentManager.Instance.AddComponentToEntity(entity, new FrictionComponent());
            //ComponentManager.Instance.AddComponentToEntity(entity, new DragComponent());
            ComponentManager.Instance.AddComponentToEntity(entity, new KartComponent());
            ComponentManager.Instance.AddComponentToEntity(entity, new PlayerComponent());
            ComponentManager.Instance.AddComponentToEntity(entity, new LapComponent());
        }
Ejemplo n.º 3
0
        public void Update(GameTime gameTime)
        {
            var sceneEntities = SceneManager.Instance.GetActiveScene().GetAllEntities();
            var terrain       = ComponentManager.Instance.GetEntityWithTag("Terrain", sceneEntities);
            var terrainC      = ComponentManager.Instance.GetEntityComponent <TerrainMapComponent>(terrain);

            var winImage   = ComponentManager.Instance.GetEntityWithTag("MP_Join", sceneEntities);
            var kart       = ComponentManager.Instance.GetEntityWithTag("Kart", sceneEntities);
            var transformC = ComponentManager.Instance.GetEntityComponent <TransformComponent>(kart);
            var physComp   = ComponentManager.Instance.GetEntityComponent <PhysicsComponent>(kart);
            var kartModel  = ComponentManager.Instance.GetEntityComponent <ModelComponent>(kart);


            ModelRenderSystem.ResetMeshTransforms(ref kartModel);
            MoveKart(gameTime, sceneEntities, transformC, physComp);

            var aiKart      = ComponentManager.Instance.GetEntityWithTag("AiKart", sceneEntities);
            var transformC2 = ComponentManager.Instance.GetEntityComponent <TransformComponent>(aiKart);
        }