From: Arvid Sjöblom Date: Tue, 14 Nov 2023 13:51:53 +0000 (+0100) Subject: added a sack to player, arvid, stina X-Git-Url: https://gitweb.forssennils.se/?a=commitdiff_plain;h=4ebf78dd3d99379e09566c3b0ebf61d49d464023;p=TDDC76_proj.git added a sack to player, arvid, stina --- diff --git a/src/Player.cc b/src/Player.cc index 8f9a479..c7c6a99 100644 --- a/src/Player.cc +++ b/src/Player.cc @@ -16,6 +16,16 @@ Player::Player() : collected{0}, max_speed{10} sf::FloatRect gb {sprite.getGlobalBounds()}; sprite.setOrigin(gb.width / 2, gb.height / 2); sprite.setPosition(position); + + sack_texture.loadFromFile("assets/sack.png"); + sack.setTexture(sack_texture); + sack.setScale(0.5, 0.5); + + sf::FloatRect gb_s {sack.getGlobalBounds()}; + sack.setOrigin(gb_s.width / 2, gb_s.height / 2); + sack_offset = {gb.width/4, -gb.height/15}; + sack.setPosition(position + sack_offset); + } @@ -31,14 +41,16 @@ void Player::update(Context& context) Game_state* game = static_cast(context.current_state.get()); position += max_speed * direction; - + sprite.setPosition(position); + sack.setPosition(position + sack_offset); return; } void Player::render(sf::RenderWindow& window) const { window.draw(sprite); + window.draw(sack); } void Player::handle_input(sf::Event& event) diff --git a/src/Player.h b/src/Player.h index 849c7b7..cd1328d 100644 --- a/src/Player.h +++ b/src/Player.h @@ -21,6 +21,9 @@ protected: private: int collected; float max_speed; + sf::Sprite sack; + sf::Texture sack_texture; + sf::Vector2f sack_offset; //{20, -30}; }; #endif \ No newline at end of file