Example #1
0
        private void loadEntities()
        {
            if (m_level == null)
            {
                return;
            }

            // parse through all of the entities in the level
            for (int i = 0; i < m_level.NumberOfEntities(); i++)
            {
                Q3BSPEntity entity = m_level.GetEntity(i);
                float       rotation;
                try {
                    rotation = float.Parse((string)entity.Entries["angle"]);
                }
                catch {
                    rotation = 0;
                }

                // initialize the entities based on their class name at their appropriate location in XNA co-ordinates
                // also, offset the position based on the center (6) of the entity placeholder from the level
                // then offset it by an additional -0.001 so that the entities do not fall through the map
                if (entity.GetClassName().Equals("enemy_robot1", StringComparison.OrdinalIgnoreCase))
                {
                    m_entities.Add((Entity) new Ricket(Q3BSPLevel.GetXNAPosition(entity) - new Vector3(0, 5.999f, 0), new Vector3(0, rotation, 0)));
                }
                else if (entity.GetClassName().Equals("enemy_robot2", StringComparison.OrdinalIgnoreCase))
                {
                    m_entities.Add((Entity) new Quadrotor(Q3BSPLevel.GetXNAPosition(entity) - new Vector3(0, 5.999f, 0), new Vector3(0, rotation, 0)));
                }
                else if (entity.GetClassName().Equals("enemy_robot3", StringComparison.OrdinalIgnoreCase))
                {
                    m_entities.Add((Entity) new Destrotron(Q3BSPLevel.GetXNAPosition(entity) - new Vector3(0, 5.999f, 0), new Vector3(0, rotation, 0)));
                }
            }
        }
Example #2
0
        public bool loadLevel(string levelName)
        {
            if (levelName == null)
            {
                return(false);
            }

            levelName = levelName.Trim();

            // initialize a new level
            Q3BSPLevel newLevel = new Q3BSPLevel(Q3BSPRenderType.StaticBuffer);

            newLevel.BasePath = levelName;

            // check if the filename ends with .bsp
            bool addBsp = !levelName.ToLower().EndsWith(".bsp");

            // attempt to load and initialize the level
            try {
                if (newLevel.LoadFromFile(Content.RootDirectory + "/maps/" + newLevel.BasePath + (addBsp ? ".bsp" : "")))
                {
                    if (!newLevel.InitializeLevel(GraphicsDevice, Content, @"Shaders\"))
                    {
                        return(false);
                    }
                }
            }
            catch (Exception) {
                return(false);
            }

            // set the active level to the new level and reset all game systems, parse all entities from level
            level = newLevel;
            collisionSystem.level = level;
            entitySystem.reset();
            entitySystem.initialize(level);

            player.reset();

            // create entity objects from entity list
            List <Entity> entities = new List <Entity>();

            entities.Clear();
            entities.Add((Entity)player);
            entities.AddRange(entitySystem.entities);

            // initialize the collision system
            collisionSystem.initialize(this, settings, entities, level);

            // check for a spawn point
            Q3BSPEntity spawn = level.GetEntity("info_player_start");

            if (spawn != null)
            {
                // convert the spawn's BSP co-ordinates to XNA co-ordinates
                Vector3 position = Q3BSPLevel.GetXNAPosition(spawn);

                // offset spawn position to bottom-center of entity
                position.Y -= 6.0f;

                // assign the spawn position to the player's position
                player.position = position;
            }

            // add 0.001 to prevent falling through level
            player.position += new Vector3(0, 0.001f, 0);

            // set model lighting based on map lighting (temporarily hard-coded)
            Vector3 lighting = Vector3.One;

            if (levelName.Equals("core", StringComparison.OrdinalIgnoreCase) ||
                levelName.Equals("core.bsp", StringComparison.OrdinalIgnoreCase))
            {
                lighting = new Vector3(0.5f, 0.6f, 0.7f);
            }
            else if (levelName.Equals("foundry", StringComparison.OrdinalIgnoreCase) ||
                     levelName.Equals("foundry.bsp", StringComparison.OrdinalIgnoreCase))
            {
                lighting = new Vector3(0.9f, 0.8f, 0.3f);
            }
            player.setLighting(lighting);
            entitySystem.setLighting(lighting);

            return(true);
        }