Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*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.
- */
- #pragma once
- #include "SpriteSheetAnimation.h"
- #include "Entity.h"
- class Player: public Entity
- {
- public:
- Player();
- ~Player();
- void LoadContent(std::vector<std::string> attributes, std::vector<std::string> contents, SDL_Renderer *renderer);
- void UnloadContent();
- void Draw(SDL_Renderer *renderer);
- void Update(SDL_Renderer *renderer, InputManager input);
- void UpdateEvent(SDL_Event &event);
- private:
- enum Direction
- {
- Right,
- Left
- };
- Direction direction;
- SpriteSheetAnimation ssAnim;
- float moveSpeed;
- float grav;
- };
- ///////////////////////////////////////////////////////////////////////////////////////////
- /*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 "Player.h"
- Player::Player()
- {
- }
- Player::~Player()
- {
- }
- void Player::LoadContent(std::vector<std::string> attributes, std::vector<std::string> contents, SDL_Renderer *renderer)
- {
- Entity::LoadContent(attributes, contents, renderer);
- moveSpeed = 0.5f;
- direction = Direction::Right;
- }
- void Player::UnloadContent()
- {
- Entity::UnloadContent();
- ssAnim.UnloadContent();
- Anim.UnloadContent();
- }
- void Player::Draw(SDL_Renderer *renderer)
- {
- Entity::DrawR(renderer,Anim.GetSourceRect());
- }
- void Player::Update(SDL_Renderer *renderer, InputManager input)
- {
- Entity::Update(input);
- Anim.getActive() = true;
- if (input.KeyDown(SDLK_LEFT))
- {
- direction = Direction::Left;
- posX -= moveSpeed;
- }
- else if (input.KeyDown(SDLK_RIGHT))
- {
- direction = Direction::Right;
- posX += moveSpeed;
- }
- else if (input.KeyDown(SDLK_UP))
- {
- posY -= moveSpeed;
- }
- else if (input.KeyDown(SDLK_DOWN))
- {
- posY += moveSpeed;
- }
- else
- {
- Anim.getActive() = false;
- }
- Anim.CurrentFrame().second = direction;
- Anim.getPositionX() = posX;
- Anim.getPositionY() = posY;
- ssAnim.Update(Anim);
- delete rect;
- delete prevRect;
- rect = new FloatRect(posX, posY, 41, 60);
- prevRect = new FloatRect(prevPosX, prevPosY, 41, 60);
- }
- void Player::UpdateEvent(SDL_Event &event)
- {
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement