Ejemplo n.º 1
0
        public void SetIfInAir(Entity e)
        {
            var physicsComp = ComponentManager.Instance.GetEntityComponent <PhysicsComponent>(e);
            var terEnt      = ComponentManager.Instance.GetFirstEntityOfType <TerrainMapComponent>();
            var terComp     = ComponentManager.Instance.GetEntityComponent <TerrainMapComponent>(terEnt);
            var trsComp     = ComponentManager.Instance.GetEntityComponent <TransformComponent>(e);
            var kartComp    = ComponentManager.Instance.GetEntityComponent <KartComponent>(e);

            var distanceToGround = -(TerrainMapRenderSystem.GetTerrainHeight(terComp, trsComp.Position.X, Math.Abs(trsComp.Position.Z)) -
                                     trsComp.Position.Y);

            //if the velocity is positive, the kart is going upwards
            if (trsComp.Velocity.Y > 0)
            {
                //set in air to true
                physicsComp.InAir = true;
            }

            if (distanceToGround <= kartComp.KartGroundOffset)
            {
                LockModelToHeight(terComp, trsComp, kartComp.KartGroundOffset);
                trsComp.Velocity.Y = 0;
                physicsComp.InAir  = false;
            }
        }
Ejemplo n.º 2
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);
        }
Ejemplo n.º 3
0
        public override void Initialise()
        {
            new InitMainMenu(this);
            new InitMultiplayerMenu(this);
            new InitGame(this);
            new InitHouses(this);
            new InitWinScreen(this);
            new InitYouLoose(this);

            //once all models entities have been loaded, add the static ones to the chunks they stand upon.
            //added static models will now rendered by the terrain map render system.
            TerrainMapRenderSystem.AddStaticModelsToChunks();
            SceneManager.Instance.SetActiveScene("MainMenu");
            SystemManager.Instance.Category = "MainMenu";
        }
Ejemplo n.º 4
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);
            }
        }
Ejemplo n.º 5
0
 public void LockModelToHeight(TerrainMapComponent terComp, TransformComponent trsComp, float offset)
 {
     trsComp.Position = new Vector3(trsComp.Position.X, offset + TerrainMapRenderSystem.GetTerrainHeight(terComp, trsComp.Position.X, Math.Abs(trsComp.Position.Z)), trsComp.Position.Z);
 }
Ejemplo n.º 6
0
 public void LockModelToHeight(TerrainMapComponent terComp, float offset)
 {
     Position = new Vector3(Position.X, offset + TerrainMapRenderSystem.GetTerrainHeight(terComp, Position.X, Math.Abs(Position.Z)), Position.Z);
 }