Using Images

Like the existing use of the physics body (created in love.load) and the drawing (in love.draw) added in the last part, images are also broken up into the same parts: the first, initial load and the later drawing call as part of a larger loop.

Similar to the move away from a player.x and player.y through using the physics body as the base measurement for movement and drawing, the introduction of an image allows for removing the player.width and player.height key-value pairs. Instead of hard-coding those measurements, the width and height of the physics body will be dictated by the width and height of the image itself.

Now, the physics shape is based on the image itself. By changing it, all other measurements adjust accordingly.

Of course, like with the move into using a physics body, the drawing calls needs to also change. However, instead of using love.graphics.rectangle, this time the function used will be love.graphics.draw.