| 967 | |
| 968 | |
| 969 | long CellEngine::DoPhysics() |
| 970 | { |
| 971 | long xx = x; |
| 972 | long yy = y; |
| 973 | long oldx = xx; |
| 974 | long oldy = yy; |
| 975 | long dxx = dx; |
| 976 | long dyy = dy; |
| 977 | long events = 0; |
| 978 | |
| 979 | if (tracking) { |
| 980 | dxx = dyy = 0; |
| 981 | } // if |
| 982 | |
| 983 | xx = xx + dxx; |
| 984 | if (xx < 0) { |
| 985 | xx = 0; |
| 986 | if (dxx < 0) dxx = -dxx; |
| 987 | events |= EVENT_BOUNCE_LEFT; |
| 988 | } else { |
| 989 | if ((xx + width) > screenWidth) { |
| 990 | xx = screenWidth - width; |
| 991 | if (xx < 0) xx = 0; |
| 992 | if (dxx > 0) dxx = -dxx; |
| 993 | events |= EVENT_BOUNCE_RIGHT; |
| 994 | } // if |
| 995 | } // if |
| 996 | |
| 997 | yy = yy + dyy; |
| 998 | if (yy < 0) { |
| 999 | yy = 0; |
| 1000 | if (dyy < 0) { |
| 1001 | dyy = -dyy; |
| 1002 | } // if |
| 1003 | events |= EVENT_BOUNCE_TOP; |
| 1004 | } else { |
| 1005 | if ((yy + height) > screenHeight) { |
| 1006 | yy = screenHeight - height; |
| 1007 | if (yy < 0) yy = 0; |
| 1008 | if (dyy > 0) { |
| 1009 | dyy = -dyy; |
| 1010 | } // if |
| 1011 | events |= EVENT_BOUNCE_BOTTOM; |
| 1012 | } // if |
| 1013 | } // if |
| 1014 | |
| 1015 | if ((!tracking) && events) { |
| 1016 | if (hubba) { |
| 1017 | frob += (Rand16() % ((2 * hubba) + 1)) - hubba; |
| 1018 | if (frob > hubba) frob = hubba; |
| 1019 | if (frob < -hubba) frob = -hubba; |
| 1020 | } // if |
| 1021 | if (rumble) { |
| 1022 | do { |
| 1023 | if (rumble > 0) { |
| 1024 | if (events & (EVENT_BOUNCE_LEFT | |
| 1025 | EVENT_BOUNCE_RIGHT | |
| 1026 | EVENT_BOUNCE_TOP | |