Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #pragma once
- /*Written 2017 by Michał Przekota.
- To the extent possible under law, the author(s) have dedicated all copyright to men who want to help with the problem.
- */
- #include <vector>
- #include <string>
- #include <SDL.h>
- #include "InputManager.h"
- #include "Animation.h"
- #include "FloatRect.h"
- class Entity
- {
- public:
- Entity();
- ~Entity();
- virtual void LoadContent(std::vector<std::string> attributes, std::vector<std::string> contents, SDL_Renderer *renderer);
- virtual void UnloadContent();
- virtual void Update(InputManager input);
- virtual void Draw(SDL_Renderer *renderer);
- virtual void DrawSS(SDL_Renderer *renderer);
- virtual void DrawR(SDL_Renderer *renderer, SDL_Rect rect);
- bool activeGravity;
- FloatRect *rect, *prevRect;
- float posX, posY, prevPosX, prevPosY;
- protected:
- Animation Anim;
- float velX, velY;
- float Gravity;
- std::string image;
- };
- ////////////////////////////////////////////////////
- #include "Entity.h"
- /*Written 2017 by Michał Przekota.
- To the extent possible under law, the author(s) have dedicated all copyright to men who want to help with the problem.
- */
- Entity::Entity()
- {
- }
- Entity::~Entity()
- {
- }
- void Entity::LoadContent(std::vector<std::string> attributes, std::vector<std::string> contents, SDL_Renderer *renderer)
- {
- for (int i = 0; i < attributes.size(); i++)
- {
- std::string att = attributes[i];
- std::string con = contents[i];
- if (att == "Image")
- {
- image = con;
- }
- else if (att == "Position")
- {
- posX = atoi(con.substr(0, con.find(',')).c_str());
- posY = atoi(con.substr(con.find(',') + 1).c_str());
- }
- }
- Anim.LoadContent("", image, posX, posY, renderer);
- rect = new FloatRect(posX, posY, 41, 60);
- prevRect = new FloatRect(posX, posY, 41, 60);
- }
- void Entity::UnloadContent()
- {
- image = "";
- Anim.UnloadContent();
- }
- void Entity::Update(InputManager input)
- {
- prevPosX = posX;
- prevPosY = posY;
- }
- void Entity::Draw(SDL_Renderer *renderer)
- {
- Anim.Draw(renderer);
- }
- void Entity::DrawSS(SDL_Renderer *renderer)
- {
- Anim.DrawSpriteSheet(renderer);
- }
- void Entity::DrawR(SDL_Renderer *renderer, SDL_Rect rect)
- {
- Anim.Draw(renderer,rect);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement