Although earthquakes are complex phenomena and many factors determine how seismic waves propagate and affect buildings, some general patterns can help us understand them.
The location of an earthquake's hypocenter influences the area it affects. A flashlight offers a useful analogy.

Figure 1. Analogy of a shallow earthquake.
If a flashlight is placed close to a table, its light is intense but illuminates a small area. Similarly, earthquakes with hypocenters close to the surface tend to produce very strong local shaking (sometimes causing severe damage), but their effects are relatively localized.
A clear example is the seismic swarm that affected Santiago de Puriscal in 1990. For months, hundreds of small earthquakes shook the area, severely damaging its Catholic church, which eventually had to be closed. Many events were commonly felt in San José and Heredia, but rarely in more distant places such as Turrialba or Puntarenas.

Figure 2. Analogy of a deep earthquake.
Continuing with the flashlight analogy, moving it farther away produces dimmer light over a wider area. Deep earthquakes can be felt across a larger region, but the shaking is usually weaker and often causes less severe damage.
The March 7, 1992, Naranjo earthquake had a magnitude of 5.6 but occurred at a depth of 87 km and was felt across most of Costa Rica. Because of its considerable depth, people perceived a mild, rolling motion.