Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "Character.h"
- Character::Character(float xPos, float yPos, float width, float height, sf::Color color)
- :movable(true)
- {
- this->rectShape.setPosition(xPos, yPos);
- this->rectShape.setSize(sf::Vector2f(width, height));
- this->rectShape.setFillColor(color);
- }
- float Character::getXUpperLeftCorner()
- {
- return this->rectShape.getPosition().x;
- }
- float Character::getYUpperLeftCorner()
- {
- return this->rectShape.getPosition().y;
- }
- float Character::getWidth()
- {
- return this->rectShape.getGlobalBounds().width;
- }
- float Character::getHeight()
- {
- return this->rectShape.getGlobalBounds().height;
- }
- void Character::setMovable(bool moveable)
- {
- this->movable = movable;
- }
- void Character::move()
- {
- if (this->movable)
- {
- if (sf::Keyboard::isKeyPressed(sf::Keyboard::A))
- {
- if (rectShape.getPosition().x > 0)
- this->rectShape.move(-10.f, 0.f);
- }
- else if (sf::Keyboard::isKeyPressed(sf::Keyboard::D))
- {
- if (rectShape.getPosition().x < 720)
- this->rectShape.move(10.f, 0.f);
- }
- else if (sf::Keyboard::isKeyPressed(sf::Keyboard::W))
- {
- if (rectShape.getPosition().y > 0)
- this->rectShape.move(0.f, -10.f);
- }
- else if (sf::Keyboard::isKeyPressed(sf::Keyboard::S))
- {
- if (rectShape.getPosition().y < 480)
- this->rectShape.move(0.f, 10.f);
- }
- }
- }
- void Character::draw(sf::RenderTarget& target, sf::RenderStates states) const
- {
- target.draw(this->rectShape);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement