Exemplo n.º 1
0
    void IECSSystem.Execute(ECSEngine engine, ECSEntity[] entities)
    {
        for (int i = 0; i < entities.Length; i++)
        {
            ECSEntity entity = entities[i];

            CollisionDataComponent cdc = engine.GetComponent <CollisionDataComponent>(entity);

            ECSEntity entity1 = cdc.Entity1;
            ECSEntity entity2 = cdc.Entity2;

            engine.DestroyEntity(entity);

            if (!this.entitiesToDestroy.Contains(entity1))
            {
                this.entitiesToDestroy.Add(entity1);
            }

            if (!this.entitiesToDestroy.Contains(entity2))
            {
                this.entitiesToDestroy.Add(entity2);
            }
        }

        this.entitiesToDestroy.Sort((x1, x2) => - x1.CompareTo(x2));

        for (int i = 0; i < this.entitiesToDestroy.Count; i++)
        {
            ECSEntity entity = this.entitiesToDestroy[i];
            engine.DestroyEntity(entity);
        }

        this.entitiesToDestroy.Clear();
    }
Exemplo n.º 2
0
        // system execution
        void IECSSystem.Execute(ECSEngine engine, ECSEntity[] entities)
        {
            for (int i = 0; i < entities.Length; i++)
            {
                //get entity
                ECSEntity entity = entities[i];

                // get data
                PositionComponent pc = engine.GetComponent <PositionComponent>(entity);
                VelocityComponent vc = engine.GetComponent <VelocityComponent>(entity);

                // manipulate data
                pc.Position += vc.Velocity * Time.DeltaTime;

                // set data
                engine.SetComponent(entity, pc);

                Debug.Log("Entity: " + entity + " - Pos: " + pc.Position, ConsoleColor.Green, entity);

                // other operations
                if (pc.Position.y < -10)
                {
                    Console.Clear();
                    Debug.Log("Destroyed: " + entity, ConsoleColor.Red, entity);

                    // destroy entities
                    engine.DestroyEntity(entity);
                }
            }
        }
Exemplo n.º 3
0
    void IECSSystem.Execute(ECSEngine engine, ECSEntity[] entities)
    {
        for (int i = 0; i < entities.Length; i++)
        {
            ECSEntity entity = entities[i];

            PositionComponent pc = engine.GetComponent <PositionComponent>(entity);
            VelocityComponent vc = engine.GetComponent <VelocityComponent>(entity);

            if (Input.IsKeyPressed(KeyCode.W))
            {
                pc.Position.Y -= vc.Velocity.Y * Time.DeltaTime;
            }

            if (Input.IsKeyPressed(KeyCode.S))
            {
                pc.Position.Y += vc.Velocity.Y * Time.DeltaTime;
            }

            if (Input.IsKeyPressed(KeyCode.A))
            {
                pc.Position.X -= vc.Velocity.X * Time.DeltaTime;
            }

            if (Input.IsKeyPressed(KeyCode.D))
            {
                pc.Position.X += vc.Velocity.X * Time.DeltaTime;
            }

            engine.SetComponent <PositionComponent>(entity, pc);
        }
    }
Exemplo n.º 4
0
        public InitGame(ECSEngine engine)
        {
            _sm.RegisterSystem("Game", new PhysicsSystem());
            _sm.RegisterSystem("Game", new TransformSystem());
            _sm.RegisterSystem("Game", new CalcModelSphereSystem());
            _sm.RegisterSystem("Game", new ModelRenderSystem(true));

            var modelCollisionSystem = new ModelCollisionSystem();

            _sm.RegisterSystem("Game", modelCollisionSystem);

            var meshToMeshCollisionSystem = new MeshToMeshCollision(modelCollisionSystem);

            _sm.RegisterSystem("Game", meshToMeshCollisionSystem);

            _sm.RegisterSystem("Game", new PowerupCollisionSystem(meshToMeshCollisionSystem));
            _sm.RegisterSystem("Game", new CheckIfInAirSystem());

            InitKeyboard();
            InitKart(engine);
            InitAi(engine);
            InitMap(engine);
            InitCamera(engine);
            InitTerrain(engine);
            InitSkybox(engine);
            InitParticles(engine);
            InitSound(engine);

            SceneManager.Instance.SetActiveScene("Game");
            SystemManager.Instance.Category = "Game";
        }
Exemplo n.º 5
0
    void IECSSystem.Execute(ECSEngine engine, ECSEntity[] entities)
    {
        for (int i = 0; i < entities.Length; i++)
        {
            ECSEntity entity = entities[i];

            TimeComponent tc = engine.GetComponent <TimeComponent>(entity);

            tc.CurrentTime -= Time.DeltaTime;

            if (tc.CurrentTime <= 0f)
            {
                tc.CurrentTime += tc.Time;

                SpawnPointComponent pc = engine.GetComponent <SpawnPointComponent>(entity);

                var enemy = engine.CreateEntity();

                engine.AddComponent <NameComponent>(enemy,
                                                    new NameComponent()
                {
                    Name = "ENEMY"
                });

                engine.AddComponent <PositionComponent>(enemy,
                                                        new PositionComponent()
                {
                    Position = pc.SpawnPoint
                });

                engine.AddComponent <VelocityComponent>(enemy,
                                                        new VelocityComponent()
                {
                    Velocity = new Vector2(0f, 5f)
                });

                engine.AddComponent(enemy, new BoxColliderComponent()
                {
                    Size = new Vector2(1f, 1f)
                });

                engine.AddComponent <SpriteRendererComponent>(enemy,
                                                              new SpriteRendererComponent()
                {
                    RenderOffset = RenderOffset.Player,
                    Texture      = TextureManager.GetTexture("EnemyBlack2"),
                    Sprite       = new Sprite(1f, 1f)
                    {
                        pivot = Vector2.One * 0.5f
                    }
                });

                engine.AddComponent <AIComponent>(enemy, new AIComponent());
            }

            engine.SetComponent <TimeComponent>(entity, tc);
        }
    }
Exemplo n.º 6
0
        private void InitTerrain(ECSEngine engine)
        {
            _sm.RegisterSystem("Game", new TerrainMapRenderSystem());

            var terrainTex = engine.LoadContent <Texture2D>("Canyon");
            var defaultTex = engine.LoadContent <Texture2D>("grasstile");

            var terrain = EntityFactory.Instance.NewEntityWithTag("Terrain");
            var t       = new TerrainMapComponent(engine.GetGraphicsDevice(), terrainTex, defaultTex, 10);
            var tf      = new TransformComponent();

            TerrainMapRenderSystem.LoadHeightMap(ref t, terrainTex, defaultTex, engine.GetGraphicsDevice());

            t.SetTextureToChunk(0, engine.LoadContent <Texture2D>("LTCornerroad"));
            t.SetTextureToChunk(1, engine.LoadContent <Texture2D>("verticalroad"));
            t.SetTextureToChunk(2, engine.LoadContent <Texture2D>("verticalroad"));
            t.SetTextureToChunk(3, engine.LoadContent <Texture2D>("verticalroad"));
            t.SetTextureToChunk(4, engine.LoadContent <Texture2D>("verticalroad"));
            t.SetTextureToChunk(5, engine.LoadContent <Texture2D>("verticalroad"));
            t.SetTextureToChunk(6, engine.LoadContent <Texture2D>("verticalroad"));
            t.SetTextureToChunk(7, engine.LoadContent <Texture2D>("verticalroad"));
            t.SetTextureToChunk(8, engine.LoadContent <Texture2D>("verticalroad"));
            t.SetTextureToChunk(9, engine.LoadContent <Texture2D>("LBCornerroad"));
            t.SetTextureToChunk(10, engine.LoadContent <Texture2D>("horizontalroad"));
            t.SetTextureToChunk(19, engine.LoadContent <Texture2D>("horizontalroad"));
            t.SetTextureToChunk(20, engine.LoadContent <Texture2D>("horizontalroad"));
            t.SetTextureToChunk(29, engine.LoadContent <Texture2D>("horizontalroad"));
            t.SetTextureToChunk(30, engine.LoadContent <Texture2D>("horizontalroad"));
            t.SetTextureToChunk(39, engine.LoadContent <Texture2D>("horizontalroad"));
            t.SetTextureToChunk(40, engine.LoadContent <Texture2D>("horizontalroad"));
            t.SetTextureToChunk(49, engine.LoadContent <Texture2D>("horizontalroad"));
            t.SetTextureToChunk(50, engine.LoadContent <Texture2D>("horizontalroad"));
            t.SetTextureToChunk(59, engine.LoadContent <Texture2D>("horizontalroad"));
            t.SetTextureToChunk(60, engine.LoadContent <Texture2D>("horizontalroad"));
            t.SetTextureToChunk(69, engine.LoadContent <Texture2D>("horizontalroad"));
            t.SetTextureToChunk(70, engine.LoadContent <Texture2D>("horizontalroad"));
            t.SetTextureToChunk(79, engine.LoadContent <Texture2D>("horizontalroad"));
            t.SetTextureToChunk(80, engine.LoadContent <Texture2D>("horizontalroad"));
            t.SetTextureToChunk(89, engine.LoadContent <Texture2D>("horizontalroad"));
            t.SetTextureToChunk(90, engine.LoadContent <Texture2D>("RTCornerroad"));
            t.SetTextureToChunk(99, engine.LoadContent <Texture2D>("RBCornerroad"));
            t.SetTextureToChunk(98, engine.LoadContent <Texture2D>("verticalroad"));
            t.SetTextureToChunk(97, engine.LoadContent <Texture2D>("verticalroad"));
            t.SetTextureToChunk(96, engine.LoadContent <Texture2D>("verticalroad"));
            t.SetTextureToChunk(95, engine.LoadContent <Texture2D>("verticalroad"));
            t.SetTextureToChunk(94, engine.LoadContent <Texture2D>("verticalroad"));
            t.SetTextureToChunk(93, engine.LoadContent <Texture2D>("verticalroad"));
            t.SetTextureToChunk(92, engine.LoadContent <Texture2D>("verticalroad"));
            t.SetTextureToChunk(91, engine.LoadContent <Texture2D>("verticalroad"));

            tf.World    = Matrix.CreateTranslation(0, 0, 0);
            tf.Position = Vector3.Zero;
            ComponentManager.Instance.AddComponentToEntity(terrain, t);
            ComponentManager.Instance.AddComponentToEntity(terrain, tf);

            SceneManager.Instance.AddEntityToSceneOnLayer("Game", 2, terrain);
        }
Exemplo n.º 7
0
        public InitMainMenu(ECSEngine engine)
        {
            SystemManager.Instance.RegisterSystem("MainMenu", new SpriteRenderSystem());

            sm.RegisterSystem("MainMenu", new KeyBoardSystem());
            InitKeyboard();
            AddMenuAndOptions(engine);

            SystemManager.Instance.RegisterSystem("MainMenu", new MainMenuSystem(engine));
        }
        public MultiPlayerMenuSystem(ECSEngine engine)
        {
            this.engine = engine;
            List <Entity> sceneEntities = SceneManager.Instance.GetActiveScene().GetAllEntities();

            join     = ComponentManager.Instance.GetEntityWithTag("MP_Join", sceneEntities);
            host     = ComponentManager.Instance.GetEntityWithTag("MP_Host", sceneEntities);
            back     = ComponentManager.Instance.GetEntityWithTag("MP_Back", sceneEntities);
            keyboard = ComponentManager.Instance.GetEntityWithTag("MP_Keyboard", sceneEntities);
            kbComp   = ComponentManager.Instance.GetEntityComponent <KeyBoardComponent>(keyboard);
        }
Exemplo n.º 9
0
        private void AddMenuAndOptions(ECSEngine engine)
        {
            Entity winScreen = EntityFactory.Instance.NewEntityWithTag("LooseScreenImage");

            Render2DComponent   Comp = new Render2DComponent(engine.LoadContent <Texture2D>("youloose"));
            Position2DComponent Pos  = new Position2DComponent(new Vector2(400, 210));

            ComponentManager.Instance.AddComponentToEntity(winScreen, Comp);
            ComponentManager.Instance.AddComponentToEntity(winScreen, Pos);
            SceneManager.Instance.AddEntityToSceneOnLayer("LooseScreen", 0, winScreen);
        }
Exemplo n.º 10
0
        public WinScreenSystem(ECSEngine engine)
        {
            SceneManager.Instance.SetActiveScene("WinScreen");
            SystemManager.Instance.Category = "WinScreen";
            this.engine = engine;
            List <Entity> sceneEntities = SceneManager.Instance.GetActiveScene().GetAllEntities();

            winScreen = ComponentManager.Instance.GetEntityWithTag("WinScreenImage", sceneEntities);
            keyboard  = ComponentManager.Instance.GetEntityWithTag("WinScreenKeyboard", sceneEntities);
            kbComp    = ComponentManager.Instance.GetEntityComponent <KeyBoardComponent>(keyboard);
        }
Exemplo n.º 11
0
        public MainMenuSystem(ECSEngine engine)
        {
            this.engine = engine;
            List <Entity> sceneEntities = SceneManager.Instance.GetActiveScene().GetAllEntities();

            single   = ComponentManager.Instance.GetEntityWithTag("MM_SinglePlayerOption", sceneEntities);
            multi    = ComponentManager.Instance.GetEntityWithTag("MM_MultiPlayerOption", sceneEntities);
            exit     = ComponentManager.Instance.GetEntityWithTag("MM_ExitOption", sceneEntities);
            keyboard = ComponentManager.Instance.GetEntityWithTag("mainMenuKeyboard", sceneEntities);
            kbComp   = ComponentManager.Instance.GetEntityComponent <KeyBoardComponent>(keyboard);
        }
Exemplo n.º 12
0
        public InitMultiplayerMenu(ECSEngine engine)
        {
            SystemManager.Instance.RegisterSystem("MultiPlayerMenu", new SpriteRenderSystem());
            SystemManager.Instance.RegisterSystem("MultiPlayerMenu", new NetworkServerRecieveMessage());


            sm.RegisterSystem("MultiPlayerMenu", new KeyBoardSystem());
            InitKeyboard();
            AddMenuAndOptions(engine);
            SceneManager.Instance.SetActiveScene("MultiPlayerMenu");
            SystemManager.Instance.RegisterSystem("MultiPlayerMenu", new MultiPlayerMenuSystem(engine));
        }
Exemplo n.º 13
0
        public void InitMap(ECSEngine engine)
        {
            var entity = EntityFactory.Instance.NewEntityWithTag("GameSettings");

            ComponentManager.Instance.AddComponentToEntity(entity, new GameSettingsComponent()
            {
                Waypoints = CreateWaypoints()
            });

            _sm.RegisterSystem("Game", new CheckIfPlayerWonSystem());
            _sm.RegisterSystem("Game", new CountLapsSystem());
        }
Exemplo n.º 14
0
        private void InitSound(ECSEngine engine)
        {
            SoundManager.Instance.SetMusicVolume(0.0f);
            var song = engine.LoadContent <Song>("Sounds/song");

            SoundManager.Instance.AddSong("song", song);
            SoundManager.Instance.PlaySong("song");

            var jump = engine.LoadContent <SoundEffect>("Sounds/jump");

            SoundManager.Instance.AddSoundEffect("jump", jump);
        }
Exemplo n.º 15
0
        private void InitSkybox(ECSEngine engine)
        {
            _sm.RegisterSystem("Game", new SkyboxRenderSystem());

            Entity          skyboxEnt  = EntityFactory.Instance.NewEntityWithTag("Skybox");
            SkyboxComponent skyboxComp = new SkyboxComponent(engine.LoadContent <Model>("skyboxes/cube"),
                                                             engine.LoadContent <TextureCube>("skyboxes/Sunset"),
                                                             engine.LoadContent <Effect>("skyboxes/skybox"), 570);

            ComponentManager.Instance.AddComponentToEntity(skyboxEnt, skyboxComp);
            SceneManager.Instance.AddEntityToSceneOnLayer("Game", 0, skyboxEnt);
        }
Exemplo n.º 16
0
        public InitYouLoose(ECSEngine engine)
        {
            SystemManager.Instance.RegisterSystem("LooseScreen", new SpriteRenderSystem());

            sm.RegisterSystem("LooseScreen", new KeyBoardSystem());
            InitKeyboard();
            AddMenuAndOptions(engine);

            SystemManager.Instance.RegisterSystem("LooseScreen", new YouLooseSystem(engine));
            SceneManager.Instance.SetActiveScene("LooseScreen");
            SystemManager.Instance.Category = "LooseScreen";
        }
Exemplo n.º 17
0
        private void InitParticles(ECSEngine engine)
        {
            SystemManager.Instance.RegisterSystem("Game", new ParticleRenderSystem(engine.GetGraphicsDevice()));
            SystemManager.Instance.RegisterSystem("Game", new ParticleUpdateSystem());
            Entity SmokehParticle        = EntityFactory.Instance.NewEntityWithTag("smokeh");
            SmokeParticleComponent pComp = new SmokeParticleComponent();

            ComponentManager.Instance.AddComponentToEntity(SmokehParticle, pComp);
            ParticleRenderSystem.LoadParticleEffect(engine.GetGraphicsDevice(), engine.LoadContent <Effect>("Effects/ParticleEffect"), engine.LoadContent <Texture2D>("smoke"), ref pComp);
            ParticleRenderSystem.setParticleOffsetPosition(ref pComp, new Vector3(0, 0, 10f));
            SceneManager.Instance.AddEntityToSceneOnLayer("Game", 2, SmokehParticle);
        }
Exemplo n.º 18
0
    void IECSSystem.Execute(ECSEngine engine, ECSEntity[] entities)
    {
        for (int i = 0; i < entities.Length; i++)
        {
            ECSEntity entity = entities[i];

            if (Input.IsKeyDown(KeyCode.Space))
            {
                WeaponComponent   wc = engine.GetComponent <WeaponComponent>(entity);
                PositionComponent pc = engine.GetComponent <PositionComponent>(entity);

                ECSEntity bullet = engine.CreateEntity();

                engine.AddComponent <NameComponent>(bullet,
                                                    new NameComponent()
                {
                    Name = "BULLET"
                });

                engine.AddComponent <PositionComponent>(bullet,
                                                        new PositionComponent()
                {
                    Position = pc.Position + wc.BulletSpawnOffset
                });

                engine.AddComponent <VelocityComponent>(bullet,
                                                        new VelocityComponent()
                {
                    Velocity = new Vector2(0f, -10f)
                });

                engine.AddComponent(bullet, new BoxColliderComponent()
                {
                    Size = new Vector2(1f, 1f)
                });

                engine.AddComponent <SpriteRendererComponent>(bullet,
                                                              new SpriteRendererComponent()
                {
                    RenderOffset = RenderOffset.Player,
                    Texture      = TextureManager.GetTexture("LaserRed01"),
                    Sprite       = new Sprite(0.1f, 1f)
                    {
                        pivot = new Vector2(0.1f, 0.5f)
                    }
                });

                engine.AddComponent <AIComponent>(bullet, new AIComponent());
            }
        }
    }
Exemplo n.º 19
0
    void IECSSystem.Execute(ECSEngine engine, ECSEntity[] entities)
    {
        for (int i = 0; i < entities.Length; i++)
        {
            ECSEntity entity = entities[i];

            PositionComponent pc = engine.GetComponent <PositionComponent>(entity);

            if (this.IsOutOfScreen(pc.Position))
            {
                engine.DestroyEntity(entity);
            }
        }
    }
Exemplo n.º 20
0
    void IECSSystem.Execute(ECSEngine engine, ECSEntity[] entities)
    {
        for (int i = 0; i < entities.Length; i++)
        {
            ECSEntity entity = entities[i];

            PositionComponent pc = engine.GetComponent <PositionComponent>(entity);
            VelocityComponent vc = engine.GetComponent <VelocityComponent>(entity);

            pc.Position += vc.Velocity * Time.DeltaTime;

            engine.SetComponent <PositionComponent>(entity, pc);
        }
    }
Exemplo n.º 21
0
    void IECSSystem.Execute(ECSEngine engine, ECSEntity[] entities)
    {
        for (int i = 0; i < entities.Length; i++)
        {
            ECSEntity entity = entities[i];

            PositionComponent       pc  = engine.GetComponent <PositionComponent>(entity);
            SpriteRendererComponent src = engine.GetComponent <SpriteRendererComponent>(entity);

            src.Sprite.position = pc.Position;
            engine.SetComponent <SpriteRendererComponent>(entity, src);

            src.Sprite.DrawTexture(src.Texture);
        }
    }
Exemplo n.º 22
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());
        }
Exemplo n.º 23
0
        private void InitKart(ECSEngine engine)
        {
            _sm.RegisterSystem("Game", new KartControlSystem(engine));

            var kart      = EntityFactory.Instance.NewEntityWithTag("Kart");
            var modelComp = new ModelComponent(engine.LoadContent <Model>("kart"), true, false, false);

            modelComp.staticModel = false;
            //ModelRenderSystem.AddMeshTransform(ref modelComp, 1, Matrix.CreateRotationY(0.2f));
            //ModelRenderSystem.AddMeshTransform(ref modelComp, 3, Matrix.CreateRotationY(0.5f));
            ComponentManager.Instance.AddComponentToEntity(kart, modelComp);
            ComponentManager.Instance.AddComponentToEntity(kart, new NetworkShareComponent());

            ComponentManager.Instance.AddComponentToEntity(kart, new Collision3Dcomponent());
            ComponentManager.Instance.AddComponentToEntity(kart, new PowerupComponent());
            ComponentManager.Instance.AddComponentToEntity(kart, new LocalPlayerComponent());

            // Create player comp
            ComponentManager.Instance.AddComponentToEntity(kart, new PlayerComponent {
                Name = "Player", Id = 1
            });

            ComponentManager.Instance.AddComponentToEntity(kart, new PhysicsComponent()
            {
                Mass  = 5f,
                Force = new Vector3(15f, 250f, 0)
            });
            ComponentManager.Instance.AddComponentToEntity(kart, new TransformComponent
            {
                Position     = new Vector3(0.0f, 0.0f, 0.0f),
                Scale        = new Vector3(2.5f, 2.5f, 2.5f),
                Acceleration = new Vector3(5f, 75f, 0)
            });
            ComponentManager.Instance.AddComponentToEntity(kart, new GravityComponent());
            ComponentManager.Instance.AddComponentToEntity(kart, new FrictionComponent());
            ComponentManager.Instance.AddComponentToEntity(kart, new DragComponent());
            ComponentManager.Instance.AddComponentToEntity(kart, new KartComponent());
            ComponentManager.Instance.AddComponentToEntity(kart, new LapComponent());
            ComponentManager.Instance.AddComponentToEntity(kart, new LocalPlayerComponent());


            SceneManager.Instance.AddEntityToSceneOnLayer("Game", 3, kart);
        }
Exemplo n.º 24
0
        private void InitCamera(ECSEngine engine)
        {
            _sm.RegisterSystem("Game", new CameraSystem());

            var camera = EntityFactory.Instance.NewEntityWithTag("3DCamera");
            var cc     = new CameraComponent(engine.GetGraphicsDeviceManager())
            {
                position         = new Vector3(0, 20, 60),
                camChasePosition = new Vector3(0f, 30f, 70f)
            };

            ComponentManager.Instance.AddComponentToEntity(camera, cc);
            ComponentManager.Instance.AddComponentToEntity(camera, new TransformComponent());
            ComponentManager.Instance.AddComponentToEntity(camera, new PlayerComponent());
            ComponentManager.Instance.RemoveComponentFromEntity <PlayerComponent>(camera);

            CameraSystem.SetTargetEntity("Kart");
            SceneManager.Instance.AddEntityToSceneOnLayer("Game", 6, camera);
            CameraSystem.SetCameraFrustrum();
            CameraSystem.SetFarClipPlane(1000);
        }
Exemplo n.º 25
0
        private void AddMenuAndOptions(ECSEngine engine)
        {
            Entity Background = EntityFactory.Instance.NewEntity();
            Entity Join       = EntityFactory.Instance.NewEntityWithTag("MP_Join");
            Entity Host       = EntityFactory.Instance.NewEntityWithTag("MP_Host");
            Entity Back       = EntityFactory.Instance.NewEntityWithTag("MP_Back");

            Render2DComponent   MenuBgComp = new Render2DComponent(engine.LoadContent <Texture2D>("Menu/MultiPlayerMenu"));
            Position2DComponent MenuBgPos  = new Position2DComponent(new Vector2(0, 0));

            ComponentManager.Instance.AddComponentToEntity(Background, MenuBgComp);
            ComponentManager.Instance.AddComponentToEntity(Background, MenuBgPos);
            SceneManager.Instance.AddEntityToSceneOnLayer("MultiPlayerMenu", 0, Background);

            Render2DComponent   joinPlayerOption    = new Render2DComponent(engine.LoadContent <Texture2D>("Menu/MPJoinGame"));
            Position2DComponent joinPlayerOptionPos = new Position2DComponent(new Vector2(381, 221));

            ComponentManager.Instance.AddComponentToEntity(Join, joinPlayerOption);
            ComponentManager.Instance.AddComponentToEntity(Join, joinPlayerOptionPos);
            SceneManager.Instance.AddEntityToSceneOnLayer("MultiPlayerMenu", 1, Join);
            Join.Visible = true;

            Render2DComponent   hostOption    = new Render2DComponent(engine.LoadContent <Texture2D>("Menu/MPHostGame"));
            Position2DComponent hostOptionPos = new Position2DComponent(new Vector2(367, 376));

            ComponentManager.Instance.AddComponentToEntity(Host, hostOption);
            ComponentManager.Instance.AddComponentToEntity(Host, hostOptionPos);
            SceneManager.Instance.AddEntityToSceneOnLayer("MultiPlayerMenu", 1, Host);
            Host.Visible = false;

            Render2DComponent   backOption    = new Render2DComponent(engine.LoadContent <Texture2D>("Menu/back"));
            Position2DComponent backOptionPos = new Position2DComponent(new Vector2(494, 527));

            ComponentManager.Instance.AddComponentToEntity(Back, backOption);
            ComponentManager.Instance.AddComponentToEntity(Back, backOptionPos);
            SceneManager.Instance.AddEntityToSceneOnLayer("MultiPlayerMenu", 1, Back);
            Back.Visible = false;
        }
Exemplo n.º 26
0
        private void AddMenuAndOptions(ECSEngine engine)
        {
            Entity MenuBackground = EntityFactory.Instance.NewEntityWithTag("MainMenuBackground");
            Entity SinglePlayer   = EntityFactory.Instance.NewEntityWithTag("MM_SinglePlayerOption");
            Entity Multiplayer    = EntityFactory.Instance.NewEntityWithTag("MM_MultiPlayerOption");
            Entity Exit           = EntityFactory.Instance.NewEntityWithTag("MM_ExitOption");

            Render2DComponent   MenuBgComp = new Render2DComponent(engine.LoadContent <Texture2D>("Menu/MainMenu"));
            Position2DComponent MenuBgPos  = new Position2DComponent(new Vector2(0, 0));

            ComponentManager.Instance.AddComponentToEntity(MenuBackground, MenuBgComp);
            ComponentManager.Instance.AddComponentToEntity(MenuBackground, MenuBgPos);
            SceneManager.Instance.AddEntityToSceneOnLayer("MainMenu", 0, MenuBackground);

            Render2DComponent   SinglePlayerOption    = new Render2DComponent(engine.LoadContent <Texture2D>("Menu/SinglePlayerSelected"));
            Position2DComponent SinglePlayerOptionPos = new Position2DComponent(new Vector2(351, 278));

            ComponentManager.Instance.AddComponentToEntity(SinglePlayer, SinglePlayerOption);
            ComponentManager.Instance.AddComponentToEntity(SinglePlayer, SinglePlayerOptionPos);
            SceneManager.Instance.AddEntityToSceneOnLayer("MainMenu", 1, SinglePlayer);
            SinglePlayer.Visible = true;

            Render2DComponent   MultiPlayerOption    = new Render2DComponent(engine.LoadContent <Texture2D>("Menu/MultiPlayerSelected"));
            Position2DComponent MultiPlayerOptionPos = new Position2DComponent(new Vector2(371, 395));

            ComponentManager.Instance.AddComponentToEntity(Multiplayer, MultiPlayerOption);
            ComponentManager.Instance.AddComponentToEntity(Multiplayer, MultiPlayerOptionPos);
            SceneManager.Instance.AddEntityToSceneOnLayer("MainMenu", 1, Multiplayer);
            Multiplayer.Visible = false;

            Render2DComponent   ExitOption    = new Render2DComponent(engine.LoadContent <Texture2D>("Menu/ExitSelected"));
            Position2DComponent ExitOptionPos = new Position2DComponent(new Vector2(506, 515));

            ComponentManager.Instance.AddComponentToEntity(Exit, ExitOption);
            ComponentManager.Instance.AddComponentToEntity(Exit, ExitOptionPos);
            SceneManager.Instance.AddEntityToSceneOnLayer("MainMenu", 1, Exit);
            Exit.Visible = false;
        }
Exemplo n.º 27
0
    void IECSSystem.Execute(ECSEngine engine, ECSEntity[] entities)
    {
        for (int i = 0; i < entities.Length - 1; i++)
        {
            ECSEntity entity1 = entities[i];

            for (int j = i + 1; j < entities.Length; j++)
            {
                ECSEntity entity2 = entities[j];

                if (entity1 != entity2)
                {
                    PositionComponent    pc1  = engine.GetComponent <PositionComponent>(entity1);
                    BoxColliderComponent box1 = engine.GetComponent <BoxColliderComponent>(entity1);

                    Vector2 box1ExtentMin = this.GetExtentMin(pc1, box1);
                    Vector2 box1ExtentMax = this.GetExtentMax(pc1, box1);

                    PositionComponent    pc2  = engine.GetComponent <PositionComponent>(entity2);
                    BoxColliderComponent box2 = engine.GetComponent <BoxColliderComponent>(entity2);

                    Vector2 box2ExtentMin = this.GetExtentMin(pc2, box2);
                    Vector2 box2ExtentMax = this.GetExtentMax(pc2, box2);

                    if (this.Intersect(box1ExtentMin, box1ExtentMax, box2ExtentMin, box2ExtentMax))
                    {
                        ECSEntity collisionDataEntity = engine.CreateEntity();

                        engine.AddComponent(collisionDataEntity, new CollisionDataComponent()
                        {
                            Entity1 = entity1, Entity2 = entity2
                        });
                    }
                }
            }
        }
    }
Exemplo n.º 28
0
        static void Main(string[] args)
        {
            // create engine
            ECSEngine engine = new ECSEngine();

            // register components (NO MORE NEEDED)
            //engine.RegisterComponent<PositionComponent>();
            //engine.RegisterComponent<VelocityComponent>();

            // add systems
            MoveSystem moveSystem = new MoveSystem();

            engine.AddSystem(moveSystem);

            for (int i = 0; i < 5; i++)
            {
                // create entities
                ECSEntity entity = engine.CreateEntity();

                // add components
                engine.AddComponent(entity, new PositionComponent());
                engine.AddComponent(entity, new VelocityComponent()
                {
                    Velocity = new Vector3(0f, -1f * (i + 1), 0f)
                });
            }

            // init engine
            engine.Init();

            while (true)
            {
                // run engine
                engine.Run();
                System.Threading.Thread.Sleep((int)(Time.DeltaTime * 1000));
            }
        }
 public NetworkClientRecieveMessage(ECSEngine engine)
 {
     _engine = engine;
 }
Exemplo n.º 30
0
        public InitHouses(ECSEngine engine)
        {
            Random              rnd           = new Random();
            ModelComponent      house         = new ModelComponent(engine.LoadContent <Model>("basichouse"), true, true, true);
            ModelComponent      house2        = new ModelComponent(engine.LoadContent <Model>("basichouse"), true, true, true);
            ModelComponent      powerupModel  = new ModelComponent(engine.LoadContent <Model>("basichouse"), true, true, false);
            List <Entity>       sceneEntities = SceneManager.Instance.GetActiveScene().GetAllEntities();
            Entity              terrain       = ComponentManager.Instance.GetEntityWithTag("Terrain", sceneEntities);
            TerrainMapComponent tcomp         = ComponentManager.Instance.GetEntityComponent <TerrainMapComponent>(terrain);

            // Init test-powerup

            Entity entity = EntityFactory.Instance.NewEntity();

            powerupModel.SetTexture(engine.LoadContent <Texture2D>("basichouse_texture1"));
            powerupModel.textured = true;
            ComponentManager.Instance.AddComponentToEntity(entity, powerupModel);

            TransformComponent tt = new TransformComponent();
            float hh = (float)rnd.Next(8, 12) / 100;

            tt.Position = new Vector3(500, 35, -50);
            tt.Scale    = new Vector3(0.08f, hh, 0.08f);
            ComponentManager.Instance.AddComponentToEntity(entity, tt);

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

            SceneManager.Instance.AddEntityToSceneOnLayer("Game", 1, entity);

            // Init houses
            for (int i = 0; i < 1; ++i)
            {
                Entity e = EntityFactory.Instance.NewEntity();

                if (i < 50)
                {
                    house.SetTexture(engine.LoadContent <Texture2D>("basichouse_texture1"));
                    house.textured = true;
                    ComponentManager.Instance.AddComponentToEntity(e, house);
                }
                else
                {
                    house2.SetTexture(engine.LoadContent <Texture2D>("basichouse_texture2"));
                    house2.textured = true;
                    ComponentManager.Instance.AddComponentToEntity(e, house2);
                }

                TransformComponent t = new TransformComponent();
                float minx           = rnd.Next(128, 900);
                float minz           = rnd.Next(128, 900);
                float houseHeight    = (float)rnd.Next(8, 12) / 100;
                t.Position = new Vector3(minx, 0.0f, -minz);
                t.Position = new Vector3(t.Position.X, TerrainMapRenderSystem.GetTerrainHeight(tcomp, t.Position.X, Math.Abs(t.Position.Z)), t.Position.Z);
                t.Scale    = new Vector3(0.08f, houseHeight, 0.08f);
                t.World    = Matrix.CreateTranslation(t.Position);

                //house and house2 are identical, so it's ok to use either of them
                ModelBoundingSphereComponent sphereComp = new ModelBoundingSphereComponent(house, t.Position);

                ComponentManager.Instance.AddComponentToEntity(e, t);
                ComponentManager.Instance.AddComponentToEntity(e, sphereComp);
                ComponentManager.Instance.AddComponentToEntity(e, new Collision3Dcomponent());

                SceneManager.Instance.AddEntityToSceneOnLayer("Game", 1, e);
            }
        }