Advertisement
shout1232131

Untitled

Jul 8th, 2017
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.17 KB | None | 0 0
  1. #pragma once
  2. /*Written 2017 by Michał Przekota.
  3. To the extent possible under law, the author(s) have dedicated all copyright to men who want to help with the problem.
  4. */
  5. #include <vector>
  6. #include <string>
  7. #include <SDL.h>
  8.  
  9. #include "InputManager.h"
  10. #include "Animation.h"
  11. #include "FloatRect.h"
  12.  
  13. class Entity
  14. {
  15. public:
  16.     Entity();
  17.     ~Entity();
  18.  
  19.     virtual void LoadContent(std::vector<std::string> attributes, std::vector<std::string> contents, SDL_Renderer *renderer);
  20.     virtual void UnloadContent();
  21.     virtual void Update(InputManager input);
  22.     virtual void Draw(SDL_Renderer *renderer);
  23.     virtual void DrawSS(SDL_Renderer *renderer);
  24.     virtual void DrawR(SDL_Renderer *renderer, SDL_Rect rect);
  25.  
  26.     bool activeGravity;
  27.     FloatRect *rect, *prevRect;
  28.     float posX, posY, prevPosX, prevPosY;
  29.  
  30. protected:
  31.     Animation Anim;
  32.  
  33.     float velX, velY;
  34.     float Gravity;
  35.  
  36.     std::string image;
  37. };
  38.  
  39.  
  40. ////////////////////////////////////////////////////
  41.  
  42. #include "Entity.h"
  43.  
  44. /*Written 2017 by Michał Przekota.
  45. To the extent possible under law, the author(s) have dedicated all copyright to men who want to help with the problem.
  46. */
  47.  
  48.  
  49. Entity::Entity()
  50. {
  51. }
  52.  
  53.  
  54. Entity::~Entity()
  55. {
  56. }
  57.  
  58. void Entity::LoadContent(std::vector<std::string> attributes, std::vector<std::string> contents, SDL_Renderer *renderer)
  59. {
  60.     for (int i = 0; i < attributes.size(); i++)
  61.     {
  62.         std::string att = attributes[i];
  63.         std::string con = contents[i];
  64.         if (att == "Image")
  65.         {
  66.             image = con;
  67.         }
  68.         else if (att == "Position")
  69.         {
  70.             posX = atoi(con.substr(0, con.find(',')).c_str());
  71.             posY = atoi(con.substr(con.find(',') + 1).c_str());
  72.         }
  73.     }
  74.     Anim.LoadContent("", image, posX, posY, renderer);
  75.  
  76.     rect = new FloatRect(posX, posY, 41, 60);
  77.     prevRect = new FloatRect(posX, posY, 41, 60);
  78. }
  79. void Entity::UnloadContent()
  80. {
  81.     image = "";
  82.     Anim.UnloadContent();
  83. }
  84. void Entity::Update(InputManager input)
  85. {
  86.     prevPosX = posX;
  87.     prevPosY = posY;
  88. }
  89. void Entity::Draw(SDL_Renderer *renderer)
  90. {
  91.     Anim.Draw(renderer);
  92. }
  93. void Entity::DrawSS(SDL_Renderer *renderer)
  94. {
  95.     Anim.DrawSpriteSheet(renderer);
  96. }
  97. void Entity::DrawR(SDL_Renderer *renderer, SDL_Rect rect)
  98. {
  99.     Anim.Draw(renderer,rect);
  100. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement