Question: Add this functionality to my code: Add a health meter ( simon ) and take damage when you run into an enemy ( spearknight )
Add this functionality to my code: Add a health metersimon and take damage when you run into an enemyspearknight
Simon.h
#ifndef SamusH
#define SamusH
#include
#include
#include "AnimatedObject.h
class Simon: public AnimatedObject
public:
Simon delete;
Simonstd::string animationFile, VectorD position, int speed, GUI& gui;
void updateconst std::vector& objects override;
VectorD getPosition const override;
private:
Helper functions
void moveLeft;
void moveRight;
void moveDown;
void moveJump;
void moveAttack;
void noAction;
void walk;
int calculateTranslationconst std::vector& objects;
void sideScrollingconst std::vector& objects;
void attackXAdjustment;
const int scrollColumn;
int xAdjustment; used to adjust the x position of the samus sprite when attacking
bool jumpReleased true ;
bool canJump true ;
;
#endif SamusH
AnimatedObject.h
#ifndef ANIMATEDOBJECTH
#define ANIMATEDOBJECTH
#include
#include
#include
#include "Object.h
class AnimatedObject : public Object
public:
AnimatedObject delete;
AnimatedObjectstd::string animationFile, VectorD position, Type name, int speed, GUI& gui;
enum class Direction left right ;
enum class State still, walk, jump, attack, crouch;
int getSpriteIndex const final;
bool facingLeft const final;
protected:
bool doPhysicsconst std::vector& objects;
void updateSprite;
const int walkSpeed;
const int jumpStrength walkSpeed ;
VectorD velocity;
Direction direction Direction::right ;
State state State::still ;
int currentSprite;
private:
static const float deltaT;f
static const VectorD gravity;
int currentAnimation;
std::unorderedmap sprites;
void loadSpritesstd::string animationFile;
void applyGravity;
bool collisionconst std::uniqueptr
#include "Object.h
class Block:public Object
public:
enum class Type
none,
groundblock,
water,
belowground
wall
belowground
wall
stump,
dirt,
evergreen,
smalltree,
bigtree,
mountain
mountain
sky
blank
;
Block delete;
BlockVectorD position, Type name, GUI& gui;
void updateconst std::vector& objects override
int getSpriteIndex const override;
bool collideable const override;
private:
Type name Type::groundblock;
;
#endif BLOCKH
SpearKnight.h
#ifndef SPEARKNIGHTH
#define SPEARKNIGHTH
#include "AnimatedObject.h
#include "VectorDh
class SpearKnight : public AnimatedObject, public Position
public:
SpearKnight delete;
SpearKnightstd::string animationFile, VectorD position, int speed, GUI& gui;
void updateconst std::vector& objects override;
private:
VectorD playerPosition;
;
#endif SPEARKNIGHTH
Block.h
#ifndef BLOCKH
#define BLOCKH
#include
#include "Object.h
class Block:public Object
public:
enum class Type
none,
groundblock,
water,
belowground
wall
belowground
wall
stump,
dirt,
evergreen,
smalltree,
bigtree,
mountain
mountain
sky
blank
;
Block delete;
BlockVectorD position, Type name, GUI& gui;
void updateconst std::vector& objects override
int getSpriteIndex const override;
bool collideable const override;
private:
Type name Type::groundblock;
;
#endif BLOCKH
SpearKnight.cpp
#include "SpearKnight.h
#include "GUI.h
SpearKnight::SpearKnightstd::string animationFile, VectorD position, int speed, GUI& gui
: AnimatedObjectanimationFile position, Object::Type::enemy, speed, gui
state State::walk;
direction Direction::left;
velocity.x walkSpeed;
updateSprite;
void SpearKnight::updateconst std::vector& objects
if doPhysicsobjects
ifdirection Direction::left
directionDirection::right;
else
direction Direction::left;
velocity.x velocity.x;
updateSprite;
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
