public static void EnemyBlockCollision(IEnemy enemy, Block block, Vector2 direction) { if (block.BlockState is KillBlockState) { enemy.Remove(); return; } direction.Normalize(); Vector2 newPosition = new Vector2(); if (direction.X < Utility.ZERO) { newPosition = new Vector2(block.Position.X + block.Bounds.Width + 1, enemy.Position.Y); } else if (direction.X > Utility.ZERO) { newPosition = new Vector2(block.Position.X - enemy.Bounds.Width - 1, enemy.Position.Y); } else if (direction.Y < Utility.ZERO) { newPosition = new Vector2(enemy.Position.X, block.Position.Y - enemy.Bounds.Height); } else if (direction.Y > Utility.ZERO) { newPosition = new Vector2(enemy.Position.X, block.Position.Y + block.Bounds.Height); } if (Vector2.Subtract(enemy.Position, newPosition).Length() > block.Bounds.Width / Utility.CAMERA_SCALE) return; enemy.Position = newPosition; //falling behavior if (direction.Y < Utility.ZERO) { enemy.OnGround = true; enemy.Velocity *= Vector2.UnitX; } //turnaround behavior if (Math.Abs(direction.X) > Utility.ZERO) { enemy.Velocity *= new Vector2(-Utility.ONE, Utility.ONE); } }