The physics branch

The physics branch

Pompei2's picture

So, as BartK asked me, I added my physics code into a new branch. It's there now. It's only the very very basics that are in and not awesome code at all, as I really don't intend to keep working on this project (I got my own project and really don't like this one's code (though I admit it's good for 48h where you have not much time to think)). It's basically what I had done during the jam's 1st day, just ported to the current codebase.

So, what's there? Only actor <-> tile collision. No actor movement. No actor <-> actor interaction. That's still a lot of work which I don't want to do, it would require me a lot of refactoring.

What you want to know:

1. chipmunk has it's 0,0 on the bottom left, y points up, x to the right. I added csys conversion methods to the Map class.

2. chipmunk uses the "body"'s centre as its position, while you used the actor's feet centre as position. Conversion happens in AnimatedActor.

3. Currently, the "body" is just a proxy, which has its own position (p) attribute which gets update by chipmunk. In AnimatedActor::update, I copy over the body's p into the actor's p. You may want to completely get rid of the actor's p and only use the body's one. Note that you need NOT to change it, you should only add forces and/or velocities to the body. See chipmunk's "player.c" demo.

4. I had to give the position of an actor on construction and use this for the physics starting position in order not to abuse setPos. Chipmunk doesn't like it when you change the position by hand. (you can "teleport" an object, but not every frame). If you do it well, I think you'll be able to remove TONS of code, especially from your multi-page methods.

5. I do not plan to develop it further. But if you have any questions, feel free to ask me (best in IRC). I'm no chipmunk expert, but I may have had the same questions.