| 1 | <pre style="text-align:left;color:#000000; background-color:#ffffff; border:solid black 1px; padding:0.5em 1em 0.5em 1em; overflow:auto;font-size:small; font-family:monospace; "><em><span style="color:#236e25;">// Code snippet to check if all bodies in the space are sleeping |
| 2 | </span></em> |
| 3 | <em><span style="color:#236e25;">// This function is called once for each body in the space. |
| 4 | </span></em><strong><span style="color:#881350;">static</span></strong> <strong><span style="color:#881350;">void</span></strong> <span style="color:#003369;">EachBody</span>(cpBody *body, cpBool *allSleeping){ |
| 5 | <strong><span style="color:#881350;">if</span></strong>(!<span style="color:#003369;">cpBodyIsSleeping</span>(body)) *allSleeping = cpFalse; |
| 6 | } |
| 7 | |
| 8 | <em><span style="color:#236e25;">// Then in your tick method, do this: |
| 9 | </span></em>cpBool allSleeping = true; |
| 10 | <span style="color:#003369;">cpSpaceEachBody</span>(space, (cpSpaceBodyIteratorFunc)EachBody, &allSleeping); |
| 11 | <span style="color:#003369;">printf</span>(<span style="color:#760f15;">"All are sleeping: %s\n"</span>, allSleeping ? <span style="color:#760f15;">"true"</span> : <span style="color:#760f15;">"false"</span>); |
| 12 | </pre> |