One process telling another that it's collided with something.

Started by Sslaxx, June 28, 2011, 03:53:28 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Sslaxx

I haven't seen anything about this in the documentation, so I thought I'd ask here.

I'm, at the moment, using the concept of collision sensors (1x1 pixels) positioned at the top, bottom and sides of a sprite and used to tell what it's colliding with. At the moment, these are discrete processes themselves.

Is there a (relatively) easy way for one of these processes (say it's called Coll_Bottom) to tell another process (say Player) that it's collided with something (Platform_Floor)?
Stuart "Sslaxx" Moore.

handsource-dyko

Process identification codes. The collision() function returns a value, wich is the unique instance id of the process.
These sub processes (the collision sensors) should be called by the player process. These now become the child (son) process
of the player wich is the parent (father) process. son and father processes can access each others data.

Let's say that this is the structure:



PROCESS player(x,y,etc,etc,etc);


PRIVATE

int topleft, topright, bottomleft, bottomright;
int collided=false;

BEGIN

    // create the collision sensors, store id-code in variables
   topleft=sensor(x,y);
   topright=sensor(x,y);
   bottomleft=sensor(x,y);
   bottomright=sensor(x,y);

     LOOP
         FRAME;
         etc etc etc etc
     END
END



PROCESS sensor(x,y);

PRIVATE

BEGIN

     LOOP

         IF (collision(TYPE platform_floor))
             father.collided=true;
         END
         FRAME;
     END
END



Although this example is a bit rough, it just show that father and son proceses can mess witch each others data.

Sslaxx

Thanks very much for that, handsource. Yet another thing I'd probably not have realised for ages unless it was pointed out first!

If I understand this correctly, something like this being done to the code might also work?

Process Player
Private
int collided = 0;
...
Begin
...
if (collided == topleft)
...
End

Process Sensor ()
...
if (collision (type platform_floor)
father.collided = id;
end
...
End
Stuart "Sslaxx" Moore.

SplinterGU

if (collided == topleft)

instead of

if (collided = topleft)
Download Lastest BennuGD Release: http://www.bennugd.org/node/2