Question: Update the Object.h and Object.cpp code according to the specification provided along with the base code below: Specification: Object Class The update method now takes
Update the Object.h and Object.cpp code according to the specification provided along with the base code below:
Specification:
Object Class
The update method now takes a parameter for use in collision detection:
const std::vector& objects
The object class has added three new methods to help with the new functionality:
virtual bool collideable const;
This is not purely virtual because it has a default functionality of returning true. It only returns false for the block class, and only for background objects. This is used in the collision method for the AnimatedObject class.
bool onScreen const;
Returns true if the objects x values put it fully on screen. It is not concerned with the y values.
void translateVectorD amount;
slides translates the object by adding the passed in amount to the objects position.
Object.h
#ifndef OBJECTH
#define OBJECTH
#include
#include
class GUI;
#include "VectorDh
class Object
public:
enum class Command up down, left, right, attack, jump, NA ;
enum class Type
block,
player,
enemy,
numTypes
;
Object delete;
ObjectVectorD position, Object::Type name, GUI& gui;
virtual void updateconst std::vector& objects;
virtual bool collideable const;
virtual bool facingLeft const;
bool onScreen const;
void translateVectorD amount;
Type getName const;
VectorD getDimensions const;
int getZOrder const;
virtual VectorD getPosition const;
virtual int getSpriteIndex const ;
int bottom const;
int top const;
int left const;
int right const;
protected:
VectorD bottomRight const;
Type name Type::block ;
VectorD position;
GUI& gui;
int zOrder;
;
#endif
Object.cpp
#include
#include "Object.h
#include "Block.h
#include "Simon.h
#include "GUI.h
Object::ObjectVectorD position, Object::Type name, GUI& gui
:positionposition namename guigui zOrderintname
bool Object::collideable const
return true;
bool Object::facingLeft const
return false;
bool Object::onScreen const
return position.x getDimensionsx && position.x GUI::screenDimensions.x;
void Object::translateVectorD amount
position amount;
VectorD Object::getPosition const
return position;
VectorD Object::getDimensions const
return gui.getDimensionsthis;
int Object::getZOrder const
return zOrder;
Object::Type Object::getName const
return name;
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
