Question: Could you help me to understand how to create this with an emphasis on the collision aspect? AnimatedObject should have the following public accessor methods

Could you help me to understand how to create this with an emphasis on the collision aspect? 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.
Your Player class is a child of the AnimatedObject class and should exhibit the following features.
Player must implement the following constructors:
Player()= delete; Player(std::string animationFile, Vector2D position, const GUI& gui);
Player should have NO private members
Player may (students choice) maintain the following private methods. Each are based on the Command variable and should check the players state, and possibly adjust to a different state based on the current Command. Adjustment to the players x position may also be necessary.
moveDown(); moveLeft(); moveRight(); noAction(); moveUp();
Change the player's state from stillLeft and stillRight to upLeft and upRight respectively.
moveJump();
If the player is changed to a jump state, subtract jumpStrength from the players y velocity. NOTE:: the jump state is only exited upon collision with a block, and this is done in the AnimatedObjects doPhysics method.
Player should override the following virtual method:
update();
Switch on the passed in command variable and call the appropriate helper function. Call the doPhysics method grab the players current height via:
gui.getDimensions(*this).y call updateSprite() method check new height, adjust height if necessary.
Your Enemy class is a child of the AnimatedObject class and should exhibit the following features.
Enemy must implement the following constructors:
Enemy()= delete; Enemy(std::string animationFile, Vector2D columnRow, const GUI& gui);
Enemy should have NO private members
Enemy should override the following virtual method:
update();
Compare enemy position to players position (< operator overloaded for Vector2D struct) switch between stillLeft and stillRight states.

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!