Question: Hello. I am having a very hard time with this. Could you please help me to understand this code with an emphasis on the collision

Hello. I am having a very hard time with this. Could you please help me to understand this code with an emphasis on the collision part of it. Please and thank you. Your AnimatedObject class should be a child of the Object class and should exhibit the following features.
AnimatedObject should overload the following constructors:
AnimatedObject()= delete; AnimatedObject(std::string animationFile, Vector2D position, Type name, const GUI& gui);
AnimatedObject should maintain the following protected members:
const int walkSpeed{12}; const int jumpStrength{35}; Vector2D velocity{0,0}; static const float deltaT;
{0.5f}
static const Vector2D gravity;
{0.0f,10.0f}
int currentSprite{0}; int currentAnimation{0}; State state{ State::stillRight }; std::map> sprites;
AnimatedObject should have the following public accessor methods (i.e., getters/setters):
getCurrentSprite();
AnimatedObject should have the following enums:
enum class State { stillLeft, stillRight, walkLeft, walkRight, crouchLeft, crouchRight, upLeft, upRight, jumpLeft, jumpRight };
AnimatedObject should have the following protected methods:
doPhysics();
applies gravity checks for collision with blocks and sets y position accordingly. ONLY The following blocks should be collided with:
bridge_center
bridge_end
bridge_start
top_block
water_top
applyGravity();
updates velocity and position based on gravity and deltaT
collision();
returns true if the object is collided with, otherwise false. Note:: In order for the player to be colliding with a block the following would have to be true:
The players left OR right side would have to be between the blocks left AND right side.
The players top OR bottom would have to be between the blocks top AND bottom side.
Because the player is taller than a block, it is possible that neither his top or bottom is in a block, so, in that case you would need to check that the blocks top (could do bottom, doesnt matter) is between the players top AND bottom.
Note2::there are other ways to do collision and you are welcome to use those.
updateSprite();
The AnimatedObject class has a sprites map that maps the state the player is in (walk_left, crouch_left, jump_left, etc) with the series of animations the player goes through in that state. the currentSprite member keeps track of the sprite being displayed. the currentAnimation member keeps track of the index for the animation in the maps list we are currently on. This method increments currentAnimation, making sure not to go off the end of the list and updates currentSprite with the value stored at that index.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!