/// <summary> /// Checking whether an actor is within bounds for culling purposes. /// </summary> public bool isInBounds(Actor a) { if (view.Contains(a.getBufferedRectangleBounds(0))) return true; return false; }
private bool isOffScreen(Actor a) { Rectangle aBounds = a.getBufferedRectangleBounds(0); return !camera.View.Contains(aBounds) && !camera.View.Intersects(aBounds); }
private void keepInBounds(Actor a) { Rectangle aBounds = a.getBufferedRectangleBounds(0); if (!gameplayBoundaries.Contains(aBounds)) { // 1.) determine the wall(s) with which we are colliding // 3.) ensure position within bounds // 2.) zero velocity and acceleration along those axes if (aBounds.Left < gameplayBoundaries.Left) { a.move((float)Math.Abs(gameplayBoundaries.Left - aBounds.Left) + EPSILON, 0.0f); if (a.velocity.X < 0.0f) a.velocity.X = 0.0f; //if (a.acceleration.X < 0.0f) // a.acceleration.X = 0.0f; a.acceleration.X = -(a.acceleration.X); } if (aBounds.Right > gameplayBoundaries.Right) { a.move(-((float)Math.Abs(gameplayBoundaries.Right - aBounds.Right) + EPSILON), 0.0f); if (a.velocity.X > 0.0f) a.velocity.X = 0.0f; //if (a.acceleration.X > 0.0f) // a.acceleration.X = 0.0f; a.acceleration.X = -(a.acceleration.X); } if (aBounds.Top < gameplayBoundaries.Top) { a.move(0.0f, (float)Math.Abs(gameplayBoundaries.Top - aBounds.Top) + EPSILON); if (a.velocity.Y < 0.0f) a.velocity.Y = 0.0f; //if (a.acceleration.Y < 0.0f) // a.acceleration.Y = 0.0f; a.acceleration.Y = -(a.acceleration.Y); } if (aBounds.Bottom > gameplayBoundaries.Bottom) { a.move(0.0f, -((float)Math.Abs(gameplayBoundaries.Bottom - aBounds.Bottom) + EPSILON)); if (a.velocity.Y > 0.0f) a.velocity.Y = 0.0f; //if (a.acceleration.Y > 0.0f) // a.acceleration.Y = 0.0f; a.acceleration.Y = -(a.acceleration.Y); } } }
private void wrapAround(Actor a) { Rectangle aBounds = a.getBufferedRectangleBounds(0); if (!gameplayBoundaries.Contains(aBounds)) { // 1.) determine the wall(s) with which we are colliding // 2.) if we are completely outside on that wall, then // reflect to the other side of the stage. // off the right side if (aBounds.Left >= gameplayBoundaries.Right) { a.move(-(float)(gameplayBoundaries.Width + (aBounds.Left - gameplayBoundaries.Right)), 0.0f); } // off the left side if (aBounds.Right <= gameplayBoundaries.Left) { a.move((float)(gameplayBoundaries.Width + (gameplayBoundaries.Left - aBounds.Right)), 0.0f); } // off the bottom side if (aBounds.Top >= gameplayBoundaries.Bottom) { a.move(0.0f, -(float)((aBounds.Top - gameplayBoundaries.Bottom) + gameplayBoundaries.Height)); } // off the top side if (aBounds.Bottom <= gameplayBoundaries.Top) { a.move(0.0f, (float)((gameplayBoundaries.Top - aBounds.Bottom) + gameplayBoundaries.Height)); } } }