Sand Physics
Posted: Sun Oct 23, 2011 11:56 pm
Found a nifty little thing about sand particles and decided to test it in GE. Fast for a few particles then drops the frame rate. Don't know why I always mess with stuff like this and water, wayyyy too many actors will get on the screen. Pretty cool to watch in action though! (looks coolest at 60fps)
- Code: Select all
int left = (getactor(x-1, y+1)->cloneindex != -1);
int under = (getactor(x, y+1)->cloneindex != -1);
int right = (getactor(x+1, y+1)->cloneindex != -1);
int bitfield = (left | (under << 1) | (right << 2));
int dir = rand(1);
switch(bitfield)
{
case 0: // ___
case 1: // x__
case 4: // __x
case 5: // x_x
y++;
break;
case 3: // xx_
y++;
x++;
break;
case 6: // _xx
y++;
x--;
break;
case 2: // _x_
y++;
x += ((dir << 1) - 1); // 'randomly' go right or left
break;
}