public override void Initialise(GraphicsDevice device, ContentManager content) { level = new Q3BSPLevel(@"C:\GitHub\Monogame-tools\LibraryDemos\LibraryDemos\Data\Q3\", @"Q3\basicQ3Effect", ".jpg"); level.LoadFromFile(@"maps\13tokay.bsp"); level.InitializeLevel(Game1.Instance.GraphicsDevice, Game1.Instance.Content); camera = new QuatCamera(Game1.Instance.GraphicsDevice.Viewport); }
public void initialize(ScrapHeap game, GameSettings settings, List <Entity> entities, Q3BSPLevel level) { m_game = game; m_settings = settings; m_entities = entities; m_level = level; }
// initialize the entity system with a new level public void initialize(Q3BSPLevel level) { m_level = level; if (m_level == null) { m_entities = null; return; } loadEntities(); }
public override void handleCollision(Q3BSPLevel level, GameTime gameTime) { if (!active) { return; } //Simple collision detection against level Q3BSPCollisionData collision = level.TraceBox(position, newPosition, minPoint, maxPoint); position = collision.collisionPoint; }
public Level3D(SceneContainer scene, Vector3 pos, Matrix rotation, Vector3 scale, bool renderSkybox) : base(scene, pos, rotation, scale) { level = new Q3BSPLevel(Q3BSPRenderType.BSPCulling); //Q3BSPRenderType.BSPCulling level.BasePath = "q3dm1"; string t = scene.Game.Content.RootDirectory; if (level.LoadFromFile(level.BasePath + ".bsp")) { levelLoaded = level.InitializeLevel(GraphicsDevice, scene.Game.Content, @"q3\scripts\", @"q3\"); } this.renderSkybox = renderSkybox; setObject(pos.X, pos.Y, pos.Z); }
public override void handleCollision(Q3BSPLevel level, GameTime gameTime) { // if noclipping is enabled, do not check for collisions if (!m_settings.clipping) { position = newPosition; } // otherwise, check for collisions else { Q3BSPCollisionData collision = level.TraceBox(position, newPosition, minPoint, maxPoint); Vector3 point = collision.collisionPoint; if (collision.collisionPoint != collision.endPosition) { Vector3 start = collision.startPosition; Vector3 col = collision.collisionPoint; Vector3 end = collision.endPosition; //Wall Detection: Not Working //point = slopeCollision(level, start, col, end, m_left, 75); //Ramp Detection point = slopeCollision(level, start, col, end, new Vector3(0, 0.5f, 0), maxClimb); } position = point; //Gravity //Check if on floor collision = level.TraceBox(position, position - new Vector3(0, 1, 0), minPoint, maxPoint); if (collision.collisionPoint == collision.endPosition || isJumping) { //Not on floor so check gravity updateGravity(gameTime); collision = level.TraceBox(position, newPosition, minPoint, maxPoint); if (collision.collisionPoint != collision.endPosition) { resetGravity(); } position = collision.collisionPoint; } else { //On floor don't do gravity, but reset it resetGravity(); } } }
private Vector3 slopeCollision(Q3BSPLevel level, Vector3 start, Vector3 collision, Vector3 end, Vector3 offset, float angle) { start += offset; end += offset; // check the slope of a collision face Q3BSPCollisionData slopetest = level.TraceBox(start, end, minPoint, maxPoint); // get the angle of the collision face, and check to see that it is not too steep for the player to climb, then return the appropriate collision point if (slopetest.collisionPoint != collision + offset) { float opp = offset.Length(); float adj = (end - start).Length(); float theta = MathHelper.ToDegrees((float)Math.Atan(opp / adj)); if (theta < angle) { return(slopetest.collisionPoint); } } return(collision); }
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))); } } }
public override void Unload() { level = null; }
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); }
public virtual void handleCollision(Q3BSPLevel level, GameTime gameTime) { //No Collision with Basic Entities return; }