Question: Could you help me understand how to complete this assignment in c + + . The header files are posted below. I need help with
Could you help me understand how to complete this assignment in c The header files are posted below. I need help with cpp files. Thank you. Continuing with our development of our game, in this Quest you will be adding side scrolling to the game as well as victory and loss conditions..
Player Class:
Starting with the changes to the player class there is a new bool isDead false ; private member that keeps track of if the player has collided with an enemy or if the player has gone off the bottom of the screen. Either of these conditions would turn the member to true. A getter will also be needed for this member.
The main changes to the class are the update method. You still need to check that the player doesnt go off the left side of the screen. However, moving right is different.
First, I created a nonmember, helper function with the following declaration:
bool lastBlockOnScreenconst std::vector& objects
This loops over the objects vector and finds the object with the largest x value being sure not to check the player It returns true if that value is less than or equal to GUI::screenDimensions.x otherwise false.
The next addition to the players update method is side scrolling.
If the players x position is greater than half the screens width and the last block is not on the screen, then
you should subtract the difference between the players x position and screenDimensions.x from EVERY object in the game.
This will have the effect of sliding everything but the player to the left and it will appear that the player is walking to the right.
A minor change to the moveRight and moveLeft methods. The respective jumping states need to also adjust the position by the walkSpeed. So if the player is in the jumpRight state, pressing the right key will make the player move right. For this to be effective, the user would need to tap the jump button, then quickly press and hold the right key.
If you did not add jumping to the previous quest, you can use my solution to have jumping available.
AnimatedObject Class:
The only change to the AnimatedObject class is the collision method, it has a new declaration:
bool collisionconst Object object, bool full false;
NOTE:: you can pass by & instead of raw pointers if you like.
The motivation for this change is to allow the player to be on different levels of blocks and not automatically bumped to the top of a block that he collides with. This image will help:
The red box indicates where we want to detect collisions. The simple fix is that the blocks height will just be considered the same as the value of gravity.y This way, when gravity is applied, the player will be popped back on top of the block.
I also removed checking to see if the players top was within the collision area. That way a jump will not bump the player more than a gravity hit.
So checking for block collision should pass in false for full, but checking for collision with an enemy, we want to pass in true If full is true then it uses the previous collision detection.
ifndef PLAYERH
#define PLAYERH
#include
#include
#include "AnimatedObject.h
class GUI;
class Block;
class Player: public AnimatedObject
public:
Player delete;
Playerstd::string animationFile, VectorD columnRow, const std::uniqueptr& gui;
void updateObject::Command command, std::vector& objects override;
Object copyMe override;
bool getIsDead;
private:
Helper functions
void moveDown;
void moveLeft;
void moveRight;
void moveUp;
void moveJump;
void noAction;
bool isDead false ;
;
#endif PLAYERH
LevelQuest.Assignment
#include
#include
#include "Object.h
class AnimatedObject : public Object
public:
AnimatedObject delete;
AnimatedObjectstd::string animationFile, VectorD columnRow, Type name, const std::uniqueptr& gui;
int getCurrentSprite const;
enum class State stillLeft, stillRight, walkLeft, walkRight, crouchLeft, crouchRight, upLeft, upRight, jumpLeft, jum
protected:
void doPhysicsconst std::vector& objects;
void applyGravity;
bool collisionconst std::uniqueptr sprites;
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
