Start by calculating the distance between the player and the object. If considering both the X and Y axis:
- Distance between player X and object X: abs(player.x - this.x)
- Distance between player Y and object Y: abs(player.y - this.y)
From that you can determine the actual distance between the player and the object (perhaps using the
Euclidean distance formula). Once you have some number that represents the distance, you can then calculate your zoom.
(The use of
abs in the examples above transforms a possibly negative number into a positive "absolute" number. This is because you might get a negative value depending on if the player is to the left or right or above or below the object X and Y coordinates you specify.
Details on abs here.)