Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Map.CPP:
- #include <SFML/Graphics.hpp>
- #include "../Entities/Entity.h"
- class TileMap: public sf::Drawable, public sf::Transformable {
- private:
- std::vector<Entity> entities;
- public:
- Entity* addEntity(Entity player) {
- entities.push_back(player);
- return &entities[entities.size() - 1];
- }
- void update(){
- for (int i = 0; i < entities.size(); i++){
- entities[i].update();
- }
- }
- virtual void draw(sf::RenderTarget& target, sf::RenderStates states) const {
- for (int i = 0; i < entities.size(); i++){
- target.draw(entities[i]);
- }
- }
- };
- DrawableEntity.h
- /*
- * DrawableEntity.h
- *
- * Created on: Jun 25, 2016
- * Author: gaming
- */
- #ifndef SRC_ENTITIES_DRAWABLEENTITY_H_
- #define SRC_ENTITIES_DRAWABLEENTITY_H_
- #include <SFML/Graphics/Drawable.hpp>
- #include "Entity.h"
- class DrawableEntity: public Entity, public sf::Drawable {
- public:
- DrawableEntity();
- virtual void update() override;
- void draw(sf::RenderTarget& target, sf::RenderStates states) const override;
- sf::Vector2f getLocation();
- virtual ~DrawableEntity();
- };
- #endif /* SRC_ENTITIES_DRAWABLEENTITY_H_ */
- DrawableEntity.cpp
- /*
- * DrawableEntity.cpp
- *
- * Created on: Jun 25, 2016
- * Author: gaming
- */
- #include "DrawableEntity.h"
- DrawableEntity::DrawableEntity() {
- // TODO Auto-generated constructor stub
- }
- void DrawableEntity::update(){
- }
- sf::Vector2f DrawableEntity::getLocation() {
- sf::Vector2f vec(x, y);
- return vec;
- }
- void DrawableEntity::draw(sf::RenderTarget& target, sf::RenderStates states) const {
- }
- DrawableEntity::~DrawableEntity() {
- }
- Player.h
- #ifndef SRC_ENTITIES_PLAYER_H_
- #define SRC_ENTITIES_PLAYER_H_
- #include <SFML/Graphics.hpp>
- #include "../graphics/AnimatedSprite.h"
- #include "DrawableEntity.h"
- using namespace sf;
- class Player: public DrawableEntity {
- protected:
- float moveSpeed;
- int dir;
- int lastDir;
- AnimatedSprite up, down, left, right, idle;
- AnimatedSprite *currentAnim;
- public:
- Texture texture;
- Player(int x, int y);
- void update() override;
- virtual ~Player();
- virtual void draw(sf::RenderTarget& target, sf::RenderStates states) const override;
- };
- #endif /* SRC_ENTITIES_PLAYER_H_ */
- Player.cpp
- /*
- * Player.cpp
- *
- * Created on: Jun 24, 2016
- * Author: gaming
- */
- #include "Player.h"
- Player::Player(int x, int y) {
- Player::x = x;
- Player::y = y;
- Player::moveSpeed = .5f;
- Player::dir = 4;
- Player::lastDir = 4;
- Player::currentAnim = &idle;
- if (!texture.loadFromFile("res/player.png")) {
- }
- AnimatedSprite upNew(96, &texture); //Any shorter way of doing these two lines without haveing to create a new instance like this?
- up = upNew;
- Player::height = 96;
- Player::width = 96;
- }
- void Player::update() {
- float xChange, yChange;
- xChange = 0;
- yChange = 0;
- //handle input and direction changing of sprites
- currentAnim->update();
- currentAnim->setLocation(x, y);
- }
- void Player::draw(sf::RenderTarget& target, sf::RenderStates states) const {
- currentAnim->draw(target, states);
- }
- Player::~Player() {
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement