Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private void CheckCollisionX()
- {
- Debug.Print("Checking X Collision");
- foreach (Tile entity in entityManager.Entities.OfType<Tile>().Where(entity => entity.HitRect.Intersects(hitRect)))
- {
- if ((hitRect.Left > entity.HitRect.Left && hitRect.Left < entity.HitRect.Right) ||
- (hitRect.Right < entity.HitRect.Right && hitRect.Right > entity.HitRect.Left))
- {
- if (moveSpeed.X > 0)
- {
- position.X -= (position.X%entity.HitRect.Width);
- moveSpeed.X = 0;
- }
- else if (moveSpeed.X < 0)
- {
- position.X += (position.X%entity.HitRect.Width);
- moveSpeed.X = 0;
- }
- }
- }
- }
- private void CheckCollisionY()
- {
- Debug.Print("Checking Y Collision");
- foreach (Tile entity in entityManager.Entities.OfType<Tile>().Where(entity => entity.HitRect.Intersects(hitRect)))
- {
- if ((hitRect.Top > entity.HitRect.Top && hitRect.Top < entity.HitRect.Bottom) ||
- (hitRect.Bottom < entity.HitRect.Bottom && hitRect.Bottom > entity.HitRect.Top))
- {
- if (moveSpeed.Y > 0)
- {
- position.Y -= (position.Y%entity.HitRect.Height);
- moveSpeed.Y = 0;
- hasJumped = false;
- }
- else if (moveSpeed.Y < 0)
- {
- position.Y += (position.Y%entity.HitRect.Height);
- moveSpeed.Y = 0;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement