Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #pragma once
- #include <SDL.h>
- #include <iostream>
- #include "Texture.h"
- #include "Animation.h"
- #include "Player.h"
- class Tile
- {
- public:
- Tile();
- ~Tile();
- static enum State {Solid, Passive};
- void SetContent(std::string image,State state, float posX,float posY, SDL_Renderer *renderer);
- void UnloadContent();
- void Update(Player &e);
- void Draw(SDL_Renderer *renderer, SDL_Rect tRect);
- private:
- Texture tTexture;
- State state;
- float posX, posY;
- };
- Tile.cpp
- #include "Tile.h"
- Tile::Tile()
- {
- }
- Tile::~Tile()
- {
- }
- void Tile::SetContent(std::string image, State state, float posX, float posY, SDL_Renderer *renderer)
- {
- this->posX = posX;
- this->posY = posY;
- this->tTexture.loadFromFile(image, renderer);
- }
- void Tile::UnloadContent()
- {
- tTexture.free();
- }
- void Tile::Update(Player &e)
- {
- FloatRect tileRect(posX,posY,32,32);
- if (e.rect->Collision(tileRect) && state == State::Solid)
- {
- if (e.rect->Right >= tileRect.Left && e.prevRect->Right <= tileRect.Left)
- {
- e.posX = tileRect.Left-32;
- }
- else if (e.rect->Left <= tileRect.Right && e.prevRect->Left >= tileRect.Right)
- {
- e.posX = tileRect.Right;
- }
- else if (e.rect->Bottom >= tileRect.Top && e.prevRect->Bottom<= tileRect.Top)
- {
- e.posY = tileRect.Top - 32;
- }
- else if (e.rect->Top <= tileRect.Bottom && e.prevRect->Top >= tileRect.Bottom)
- {
- e.posY = tileRect.Bottom;
- }
- }
- }
- void Tile::Draw(SDL_Renderer *renderer, SDL_Rect tRect)
- {
- tTexture.render(posX, posY, renderer, &tRect);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement