Aeona

Aeona

Monday, February 27, 2012

Collision checks

Today I continued working on cleaning up the project and remaking some of the main classes. I worked on the Base Character class and the new Player class. I also changed a little bit my friend Bern's Animation Engine so that is returns more data when animations are loaded. While before we had to kind of figure out where the animations were on his array, now the function returns the index of the first and the last animations loaded as output parameters, so you can store that and use it in a much more flexible way.
I also spent some time working on my collision-related user stories. The way we had collision working before, for every time the player pressed one of the movement keys, a copy of the player would be created with the new position, collision would be checked against that copy, and if it returned false (which means it didn't collide with anything in the world), only then we would move the actual player. That was working and it's all right, but can you imagine the waste of memory it is to create a whole new player every frame? What about when we actually created lots of enemies, NPCs and other physic game objects? Would we be creating copies of them at every frame too? Yes, and that could affect our frame rate considerably. At least I think.
So, I decided to change that approach to a better one, I'd move the player first no matter what, check if it collided with the world, and if it did I'd return him to the old position. That is not ideal, but definitely better, and it should work fine. Well, that's what I thought, but it didn't. Since the collision rectangles of the character change as the animation frame changes, eventually the player would still be able to move a little bit towards a collidable object and get stuck there forever.

I'm still trying to figure out what is the best way to handle that.
And I'll be working until late night today.
But I'll do it.

No comments:

Post a Comment