Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <SFML/Graphics.hpp>
- #include "Character.h"
- #include <iostream>
- //Loading & setting character attributes
- Character::Character()
- {
- chTexture.loadFromFile("tiles/char.png");
- chSprite = sf::Sprite(chTexture);
- chSprite.setTextureRect(sf::IntRect(0, 0, 32, 32));
- chSprite.setPosition(300.0, 300.0);
- chSprite.setScale(2, 2);
- }
- //Movement
- void Character::Move(int Direction, int animation)
- {
- std::cout << animation;
- sf::Vector2f offset;
- switch (Direction)
- {
- case 0:
- offset.x = 0;
- offset.y = 10;
- break;
- case 1:
- offset.x = -10;
- offset.y = 0;
- break;
- case 2:
- offset.x = 10;
- offset.y = 0;
- break;
- case 3:
- offset.x = 0;
- offset.y = -10;
- break;
- }
- chSprite.move(offset);
- chSprite.setTextureRect(sf::IntRect(animation * 32, Direction * 32, 32, 32));
- animation++;
- if (animation >= 3)
- {
- animation = 0;
- }
- }
- //Drawing character
- void Character::Draw(sf::RenderWindow &window)
- {
- window.draw(chSprite);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement