Some simple 2d game-related maths questionsby skx (Parson)
|on Aug 27, 2008 at 20:43 UTC||Need Help??|
skx has asked for the
wisdom of the Perl Monks concerning the following question:
The game itself was a a lot of fun to write, and wasn't too difficult. But I'm having a couple problem with it, and whilst they are not entirely Perl problems I suspect there is a module which could help me. I've searched CPAN for collision detection and gaming modules and come up short.
My problem is soley related to maths. My main (circular) sprite has an X,Y position, and each "tick" of the game this is updated:
Here dx and dy are integer values which control the speed/angle of movement.
Now for my problem:
Currently my line structure is represented by a pair of coordinates "startx,starty" + "endx,endy". So my collision detection comes down to testng:
This should be easy, but my code is brittle and seems to fail at times.
Similarly for the bounce I know that I need to take into account the angle of the line, but right now I just invert the dx + dy components and hope for the best.