Collision pointer

Posted By: Silence_

Collision pointer - 03/19/10 19:10

Lately I’ve been thinking it would be really useful to have a pointer that handles collisions in 2d games. I'm still a beginner in programming so I don't know how to make one.
This is what it looks like now.

Code:
//collision.h
#ifndef collision_h
#define collision_h

#define STOP (1<<0)
#define BOUNCE (1<<1)
#define CUSTOME (1<<2)

typedef struct COLLISION
{
	long flags;
} COLLISION;

#endif



This is how I want it to look like when someone wants to use it.
Code:
COLLISION* test =
{
	Flags = STOP | BOUNCE | CUSTOM;
	Panel 1 = ?;
	Panel 2 = ?;
	Function  = action();
}



BOUNCE makes the panel bounce when it collides with another panel.
STOP makes the panel stop when it collides with another panel.
CUSTOM makes the panel do what the function attached to it says to do when it collides with another panel.

So can anyone help me make this work, because I have know idea where to go from here.
When its finished and working I’ll put it in the download section.
Posted By: Xarthor

Re: Collision pointer - 03/20/10 09:42

Sorry if the following response is of no help to you:

Before thinking about how to implement it, you should rather think about the whole process.
I mean, how to you link a panel to that struct?
Panel collision can just be done by checking one panels position and size again other panels (or is there a new feature I'm unaware of?)
Now, how do you find out which struct to "use"?

<edit>
Another problem: afaik you cannot use "function pointers". Thus saving a link to a function in some property is not possible. But I might be wrong.
</edit>

I'm not quite sure if the way you want to go is the best way for this kind of problem.
Posted By: Silence_

Re: Collision pointer - 03/21/10 02:45

Thats too bad. I guess I'll just have to write out the code myself. thanks for the help.
Posted By: flits

Re: Collision pointer - 03/21/10 10:10

maby you can get some algoritmes from this one

http://www.opserver.de/coni_users/web_users/pirvu/au/demo/zips/collisiondetectionwithprojections.zip
© 2024 lite-C Forums