Game Engine 2D Platformer
GraphicsComponent.hpp
Go to the documentation of this file.
1 /*
2  * @file GraphicsComponent.hpp
3  * @brief GraphicsComponent class interface
4  * @date 2021-03-12
5  ***********************************************/
6 #ifndef GRAPHICSCOMPONENT_HPP
7 #define GRAPHICSCOMPONENT_HPP
8 
9 #include "Component.hpp"
10 #include <map>
11 #include <math.h>
12 #include "ResourceManager.hpp"
13 #include <string>
14 #include <memory>
15 #include <iterator>
16 #include <SDL2_image/SDL_image.h>
17 
21 {
22 public:
26  GraphicsComponent(SDL_Renderer* ren);
32  void StartUp();
35  void ShutDown();
38  void Update(GameEntity& entity);
42  void Render(GameEntity& entity);
47  void LoadImage(std::string filepath, SDL_Renderer* ren);
48 
49 private:
50  SDL_Renderer* renderer;
51  SDL_Rect src, dest;
52  SDL_Surface* m_spritesheet;
53  SDL_Texture* m_texture;
54  std::map<int, std::vector<int>> map;
55 
56  int frameStart;
57  int frameEnd;
58  int frame = 0;
59  int widthImg, heightImg, row, col, tempWidth, tempHeight;
60  int tileHeight, tileWidth;
61  int startTime;
62  int animationRate;
63  int animationLength;
64  // SDL_RendererFlip flip=SDL_FLIP_NONE;
65 
66 
67 
68  // int frameStart;
69  // int frameEnd;
70  // int frame=0;
71  //Create a ResourceManager instance
73 };
74 
75 #endif
The interface class for different components to inherit.
Definition: Component.hpp:16
Represents an interactable entity in the game that includes Main Character, NPC, Tiles ,...
Definition: GameEntity.hpp:22
GraphicsComponent class used to flip through frames for a GameEntity.
Definition: GraphicsComponent.hpp:21
void ShutDown()
Constructor for GraphicsComponent.
Definition: GraphicsComponent.cpp:25
void LoadImage(std::string filepath, SDL_Renderer *ren)
Loads image to use for graphics.
Definition: GraphicsComponent.cpp:68
void StartUp()
Initializes attributes for GraphicsComponent.
Definition: GraphicsComponent.cpp:21
void Update(GameEntity &entity)
Selects graphic to render depending on frame.
Definition: GraphicsComponent.cpp:40
GraphicsComponent(SDL_Renderer *ren)
Constructor for GraphicsComponent.
Definition: GraphicsComponent.cpp:8
~GraphicsComponent()
Destructor for GraphicsComponent.
Definition: GraphicsComponent.cpp:17
void Render(GameEntity &entity)
Renders graphic.
Definition: GraphicsComponent.cpp:32
The resource manager is responsible for handling and managing resources regarding the game.
Definition: ResourceManager.hpp:23
static ResourceManager & getInstance()
Method used to get instance of ResourceManager class.
Definition: ResourceManager.cpp:8