cleanup Main_enemy.cc
authorArvid Sjöblom <arvsj277@student.liu.se>
Mon, 11 Dec 2023 08:54:34 +0000 (09:54 +0100)
committerArvid Sjöblom <arvsj277@student.liu.se>
Mon, 11 Dec 2023 08:54:34 +0000 (09:54 +0100)
src/Main_enemy.cc

index b9481aabdab3f786126877f89946c23363c2581a..0f8532ce73914be99d8a95269f07f0bba939a3ea 100644 (file)
@@ -13,7 +13,6 @@ Main_enemy::Main_enemy(sf::Texture& txtr, json& params):
     tumbling{false},
     moving_to_bottle{false}
 {
-    //texture.loadFromFile("assets/6Ling_figur2.png");
     texture = txtr;
     sprite.setTexture(texture);
     position = {params["start_pos"][0], params["start_pos"][1]};
@@ -56,12 +55,14 @@ void Main_enemy::update(Context& context)
     else
     {
         
-        Game_state* game = static_cast<Game_state*>(context.current_state.get());
+        Game_state* game = 
+                    static_cast<Game_state*>(context.current_state.get());
         if ((game->bottles).size() != 0)
         {
             moving_to_bottle = true;
             direction = find_closest_bottle(game->bottles) - position;
-            float magnitude = sqrt(direction.x*direction.x + direction.y*direction.y);
+            float magnitude = sqrt(direction.x*direction.x + 
+                                    direction.y*direction.y);
             direction /= magnitude;
         move();
         }
@@ -80,15 +81,14 @@ void Main_enemy::move(bool forward)
 {
     if (moving_to_bottle)
     {
-        position += static_cast<float>(pow(-1, forward - 1)) * max_speed * direction;
+        position += static_cast<float>(pow(-1,forward-1))*max_speed*direction;
         sprite.setPosition(position);
     }
 }
 
-sf::Vector2f Main_enemy::find_closest_bottle(std::vector<std::unique_ptr<Bottle>> & bottles)
+sf::Vector2f Main_enemy::find_closest_bottle(
+        std::vector<std::unique_ptr<Bottle>> & bottles)
 {
-    //return {0,0};
-    
     unsigned int closest_bottle_index {0};
     float min_dist{100000};
     for (uint i {0}; i < bottles.size(); ++i)