public void Update(IBlockObstacle block) { foreach (IConsumableItem item in consumableItems) { Rectangle objectA = block.Collider; Rectangle objectB = item.Collider; Rectangle overlap = Rectangle.Intersect(objectA, objectB); if (overlap.Width > overlap.Height) { if (objectA.Location.Y > objectB.Location.Y) { item.Bump(0, -overlap.Height); } if (objectA.Location.Y < objectB.Location.Y) { item.Bump(0, overlap.Height); } } if (overlap.Width < overlap.Height) { if (objectA.Location.X > objectB.Location.X) { item.Bump(-overlap.Width, 0); } if (objectA.Location.X < objectB.Location.X) { item.Bump(overlap.Width, 0); } } } }
public void Update(IBlockObstacle block) { foreach (IEnemy enemy in enemies) { Rectangle objectA = block.Collider; Rectangle objectB = enemy.Collider; Rectangle overlap = Rectangle.Intersect(objectA, objectB); if (overlap.Width > overlap.Height) { if (objectA.Location.Y > objectB.Location.Y) { enemy.Bump(0,-overlap.Height); } if (objectA.Location.Y < objectB.Location.Y) { enemy.Bump(0,overlap.Height); } } if (overlap.Width < overlap.Height) { if (objectA.Location.X > objectB.Location.X) { enemy.Bump(-overlap.Width,0); } if (objectA.Location.X < objectB.Location.X) { enemy.Bump(overlap.Width,0); } } } }
public void Update(IBlockObstacle block) { foreach (IProjectile projectile in marioProjectiles) { Rectangle objectA = block.Collider; Rectangle objectB = projectile.Collider; Rectangle overlap = Rectangle.Intersect(objectA, objectB); if (overlap.Width > overlap.Height) { if (objectA.Location.Y > objectB.Location.Y) { projectile.Bump(0, -overlap.Height); } if (objectA.Location.Y < objectB.Location.Y) { projectile.Bump(0, overlap.Height); } } if (overlap.Width < overlap.Height) { if (objectA.Location.X > objectB.Location.X) { projectile.Bump(-overlap.Width, 0); projectile.Explode(); } if (objectA.Location.X < objectB.Location.X) { projectile.Bump(overlap.Width, 0); projectile.Explode(); } } } }