Hi,
I'm trying to make a game similar to the ones at fallingsandgame.com, but with more realistic physics using vectors. I have the vectors working but there is a problem with collisions... they aren't working. The particles will hit the walls but will run right over each other. This is my physics (actually just vector movement and collisions now) code:
if(p[x][y][2] > 0 && p[x][y][3] > 0)
{
for(vx = 0; vx < p[x][y][2]; vx++)
{
for(vy = 0; vy < p[x][y][3]; vy++)
{
if(!pexists(x + vx, y + vy))
{
tmpvx = vx;
tmpvy = vy;
}
}
}
}
if(p[x][y][2] < 0 && p[x][y][3] > 0)
{
for(vx = p[x][y][2]; vx < 0; vx++)
{
for(vy = 0; vy < p[x][y][3]; vy++)
{
if(!pexists(x + vx, y + vy))
{
tmpvx = vx;
tmpvy = vy;
}
}
}
}
if(p[x][y][2] > 0 && p[x][y][3] < 0)
{
for(vx = 0; vx < p[x][y][2]; vx++)
{
for(vy = p[x][y][3]; vy < 0; vy++)
{
if(!pexists(x + vx, y + vy))
{
tmpvx = vx;
tmpvy = vy;
}
}
}
}
if(p[x][y][2] < 0 && p[x][y][3] < 0)
{
for(vx = p[x][y][2]; vx < 0; vx++)
{
for(vy = p[x][y][3]; vy < 0; vy++)
{
if(!pexists(x + vx, y + vy))
{
tmpvx = vx;
tmpvy = vy;
}
}
}
}
pexists():
int pexists(int x, int y)
{
if(x < 0 || x >= w - 10 || y < 0 || y >= h)
return 1;
else if(p[x][y][0] == 1)
return 1;
else
return 0;
}
moveParticle():
void moveParticle(int x, int y, int x2, int y2)
{
if((pexists(x, y)) && (!pexists(x2, y2)))
{
if(x2 < w && x2 >= 0)
{
p[x2][y2][0] = 1;
p[x2][y2][1] = p[x][y][1];
p[x2][y2][2] = p[x][y][2];
p[x2][y2][3] = p[x][y][3];
p[x2][y2][5] = p[x][y][5];
p[x2][y2][6] = p[x][y][6];
p[x2][y2][7] = p[x][y][7];
p[x2][y2][4] = 0;
p[x][y][0] = 0;
p[x][y][2] = 0;
p[x][y][3] = 0;
p[x][y][4] = 0;
}
}
}
Thanks for any help :)
Edit: Sorry about the messed up tabs... I hadn't figured out how to turn off Dev-C++'s "Smart Tabs" feature when I wrote this, and the forum made it worse...