Kovak / CBL_SECRET_PROTOTYPE_RUNNING_GAME

0 stars 0 forks source link

Enemy Collision Code Refactor #45

Open Kovak opened 11 years ago

Kovak commented 11 years ago

Right now, for every enemy on screen we actually perform a collision detection 2 times per frame.

I think we could optimize this particular algorithm to only perform one collision detection routine

In addition I believe the use of player_character.collide_widget is slightly off.

The player character is defined from an x,y position in the bottom left corner and the size essentially gives the top right corner.

The enemy character is defined from an x,y position in the center of the enemy and half the size gives the width and height on either side of that center

This is also true of the world_objects as well.

The actual algorithm is checking with the assumption that x,y gives the bottom left corner, and than the top and right side of the widget is checked. We currently do correctly assign the top and right variables for the enemy and world_object objects, however, when we are using collide widget we are also testing the x and y values of these objects, which are limiting the actual test to a smaller area of the widget. We could improve accuracy of the initial test for collision by fixing this particular issue.

We also do not currently update the top and right values based on the correct size of the enemy object.