From 4ebf78dd3d99379e09566c3b0ebf61d49d464023 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Arvid=20Sj=C3=B6blom?= Date: Tue, 14 Nov 2023 14:51:53 +0100 Subject: [PATCH] added a sack to player, arvid, stina --- src/Player.cc | 14 +++++++++++++- src/Player.h | 3 +++ 2 files changed, 16 insertions(+), 1 deletion(-) 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 -- 2.30.2