Drawing the game field according to Pythagoras

We must find the right vertical distance among rows to let the game field render properly.

The idea: We'll use Pythagorean Theorem to determine the vertical distance.

The distance between two circles must always be 2*R, but circles placed on odd rows are shifted to the right by R pixels. So what's the vertical distance?

In the following picture you will see the desired result:

Drawing the game field according to Pythagoras

If we build a right triangle whose hypotenuse is the distance between two circles (cyan line) and the legs are respectively the amount of pixel odd rows circles are shifted to the right (green line), the other leg (yellow line) ...

Get Flash Game Development by Example now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.