|
This week i have added a collision manager class to the game, it has been the largest artifact I’ve done and is therefore the subject of this week’s Artifact post.
This Collision manager alters slightly from the original one which had to be replaced as the implementation and function was changed after Oliver’s advice. The original manager (mentioned in the previous post) was to be used in the Level.update method and handled not only the detection of collisions but also the effects of them. Oliver explained to me tonight that the collision detection should only do that and then call on function within the objects themselves to deal with the collision properly. So here is what i have as of now, this is of course subject to change as the project continues and will probably be added onto before the end of tonight. 
This manager is placed in the Engine.cpp file between the functions for updating objects and for drawing objects.(Yet another pointer from Oliver.) The vector is filled using the objects in the gameobjectmanager. The function goes through every object once and checks if any of them are a playerobject and once if finds one it goes through all the objects again and for every object that is NOT a player it checks whether it collides with the player. If an object does collide with the player the first objects is casted back to the playerobject it is and from it the Handlecollision function is called which allows it to react depending on the type of object it is colliding with.
This function will later be able to distinguish between different objects which will allow it to only loop through certain types in order to be more optimized when more objects gets added to the game.

This picture shows the player’s method of handling collisions. So far in my version of the project the only relevant object is the hiding cabinets so there is no need to have alternate functionality yet. I will add that once we merge our projects and get the objectTypes properly working i will make it react to colliding with guards as well. The function takes out the position and size of the player and the colliding object and since it wouldn’t have been called if they were not colliding all that needs to be done is compare the positions of the objects to determine from which direction the player is colliding. This will not be the case with for example guards where it doesn’t matter which direction the player collides from.
Another flaw with this system is that it assumes that the first object(the player in most cases) has it’s origin at it’s center and the second object(Wall or similar) has it’s origin at the top left corner. This should be easy to adjust fro different objects, maybe even give the objects a bool to tell where their orgin is located. Or maybe just use getorigin. It’s not decided yet.

|