protected override void Update(GameTime gameTime) { inputManager.Update(); #if DEBUG //if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape)) // Exit(); #endif GTime.Delta = (float)gameTime.ElapsedGameTime.TotalSeconds; GTime.UpdateTime((float)gameTime.ElapsedGameTime.TotalSeconds); // if we just changed scenes, init the scene SceneManager.InitCurrentScene(); SceneManager.UpdateCurrentScene(); CollisionManager.Update(); base.Update(gameTime); }
public Collider(bool isStatic) { m_others = new List <Collider>(); CollisionManager.Register(this); m_isStatic = isStatic; }
public Collider() { m_others = new List <Collider>(); CollisionManager.Register(this); m_isStatic = false; }
public void Split(List <Collider> colliders) { if (colliders.Count >= 2) { List <Collider> containedColliders = new List <Collider>(); if (m_children == null) { int halfWidth = m_bounds.Width / 2; int halfHeight = m_bounds.Height / 2; if (halfHeight < CollisionManager.GetMinQuadSize() || halfWidth < CollisionManager.GetMinQuadSize()) { return; } m_children = new QuadTree[4]; // TL m_children[0] = new QuadTree(new Rectangle(m_bounds.X, m_bounds.Y, halfWidth, halfHeight)); // TR m_children[1] = new QuadTree(new Rectangle(m_bounds.X + halfWidth, m_bounds.Y, halfWidth, halfHeight)); // BL m_children[2] = new QuadTree(new Rectangle(m_bounds.X, m_bounds.Y + halfHeight, halfWidth, halfHeight)); // BR m_children[3] = new QuadTree(new Rectangle(m_bounds.X + halfWidth, m_bounds.Y + halfHeight, halfWidth, halfHeight)); int numStatic = 0; int numDynamic = 0; for (int k = 0; k < colliders.Count; k++) { if (m_bounds.Intersects(colliders[k].m_bounds)) { containedColliders.Add(colliders[k]); if (colliders[k].IsStatic()) { numStatic++; } else { numDynamic++; } } } if (numDynamic == 0 || (numDynamic == 1 && numStatic == 0)) { m_children = null; } else { int numContained = 0; for (int i = 0; i < 4; i++) { m_children[i].m_parent = this; m_children[i].Split(containedColliders); numContained++; } } } if (containedColliders.Count < 2) { m_col = Color.MonoGameOrange; } else { m_col = Color.LawnGreen; HandleOverlap(containedColliders); } } } // Split end