added a sack to player, arvid, stina
authorArvid Sjöblom <arvsj277@student.liu.se>
Tue, 14 Nov 2023 13:51:53 +0000 (14:51 +0100)
committerArvid Sjöblom <arvsj277@student.liu.se>
Tue, 14 Nov 2023 13:51:53 +0000 (14:51 +0100)
src/Player.cc
src/Player.h

index 8f9a479f80b2926bca0647cdde33e9c41dba6489..c7c6a99f466fa4310628b4e2b7897c9232fbe040 100644 (file)
@@ -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<Game_state*>(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)
index 849c7b70203347360bf9b87ceade3d3b7b20df37..cd1328df4f4bd44ad39d224ea429f697fa0c0e3e 100644 (file)
@@ -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