\documentclass{article}
\usepackage{common}

\begin{document}
\begin{framed}

\pagehead{Sprite collision detection}

For games, it is often very important to know when sprites overlap.  Because it is often quite
time-consuming to perform this overlap test, 
the Gameduino has a special memory area that you can use to detect when
sprites touch.  As it draws the image, Gameduino keeps track of which pixels cover others,
and writes the results into the collision RAM.  The game can read this collision RAM at the
end of the frame to find overlapping sprites.

Each byte in the collision RAM corresponds to the same numbered sprite.
If the sprite does not cover any other then the byte's value is 0xff.  But if
the sprite covers any part of another sprite, then the value is the number
of the other sprite.

For example, if sprites 00-03 are arranged like this:

\begin{tikzpicture}
\draw (0,0) node(3) [circle, draw=orange!90, fill=orange!30, minimum width=2cm] {\textbf{00}};
\draw (1.5,0) node [circle, draw=green!90, fill=green!30, minimum width=2cm] {\textbf{01}};
\draw (5.5,0) node [circle, draw=blue!90, fill=blue!30, minimum width=2cm] {\textbf{02}};
\draw (4,0) node(3) [circle, draw=red!90, fill=red!30, minimum width=2cm] {\textbf{03}};
\end{tikzpicture}

then the first four bytes of collision RAM will be:

\begin{tabular}{|c|c|l|}
\hline
\textbf{address} & \textbf{value} & \textbf{meaning} \\
\hline
2900 & FF & sprite 00 did not cover up any other sprite \\
\hline
2901 & 00 & sprite 01 covered some pixels from sprite 00 \\
\hline
2902 & FF & sprite 02 did not cover up any other sprite \\
\hline
2903 & 02 & sprite 03 covered some pixels from sprite 02 \\
\hline
\end{tabular}

\sample{collision}

\end{framed}
\end{document}
