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 translate(Vector2D amount);
slides (translates) the object by adding the passed in amount to the objects position.
Object.h
#ifndef OBJECT_H
#define OBJECT_H
#include
#include
class GUI;
#include "Vector2D.h"
class Object
{
public:
enum class Command { up, down, left, right, attack, jump, NA };
enum class Type
{
block,
player,
enemy,
numTypes
};
Object()= delete;
Object(Vector2D position, Object::Type name, GUI& gui);
virtual void update(const std::vector>& objects)=0;
virtual bool collideable() const;
virtual bool facingLeft() const;
bool onScreen() const;
void translate(Vector2D amount);
Type getName() const;
Vector2D getDimensions() const;
int getZOrder() const;
virtual Vector2D getPosition() const;
virtual int getSpriteIndex() const =0;
int bottom() const;
int top() const;
int left() const;
int right() const;
protected:
Vector2D bottomRight() const;
Type name{ Type::block };
Vector2D position{0,0};
GUI& gui;
int zOrder{0};
};
#endif
Object.cpp
#include
#include "Object.h"
#include "Block.h"
#include "Simon.h"
#include "GUI.h"
Object::Object(Vector2D position, Object::Type name, GUI& gui)
:position(position), name(name), gui(gui), zOrder((int)name)
{
}
bool Object::collideable() const
{
return true;
}
bool Object::facingLeft() const
{
return false;
}
bool Object::onScreen() const
{
return position.x + getDimensions().x >0 && position.x < GUI::screenDimensions.x;
}
void Object::translate(Vector2D amount)
{
position += amount;
}
Vector2D Object::getPosition() const
{
return position;
}
Vector2D Object::getDimensions() const
{
return gui.getDimensions(*this);
}
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 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!