game programming, allegro, multiple objects

Hi there!

I'm currently working on a 2D game where the main character moves about in a room completing various tasks. To make the game more realistic I added furniture & stuff which the character bumps into and doesn't just walk right through. Code-wise these obstacles are squares and distance between their center and player is calculated as shown below.


1
2
3
4
5
6
if(ms.horz && ms.vert) { bob[1].cntindex++; }

ms.obdist_x[0]=abs( ms.x-bob[bob[1].cntindex].x ); 
ms.obdist_y[0]=abs( ms.y-bob[bob[1].cntindex].y );

if(bob[1].cntindex>=9) { bob[1].cntindex=0; }


Since there are multiple squares (bob[index].x, bob[index].y) I created a variable (bob[1].cntindex) which "runs" through every square in order to check the distance between it and the character (ms.x, ms.y). The problem is that, no matter how fast my variable checks every square, it's always a bit of delay and it kinda looks like that my character is stuck half inside a sofa. :P

So my question is: is there a better way to check all the squares simultaneously? :)
Topic archived. No new replies allowed.