From bbee4f4c8ce3f19a22ca2ebd92b0edc66c1da351 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Arvid=20Sj=C3=B6blom?= Date: Mon, 11 Dec 2023 09:54:34 +0100 Subject: [PATCH] cleanup Main_enemy.cc --- src/Main_enemy.cc | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/Main_enemy.cc b/src/Main_enemy.cc index b9481aa..0f8532c 100644 --- a/src/Main_enemy.cc +++ b/src/Main_enemy.cc @@ -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(context.current_state.get()); + Game_state* game = + static_cast(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(pow(-1, forward - 1)) * max_speed * direction; + position += static_cast(pow(-1,forward-1))*max_speed*direction; sprite.setPosition(position); } } -sf::Vector2f Main_enemy::find_closest_bottle(std::vector> & bottles) +sf::Vector2f Main_enemy::find_closest_bottle( + std::vector> & bottles) { - //return {0,0}; - unsigned int closest_bottle_index {0}; float min_dist{100000}; for (uint i {0}; i < bottles.size(); ++i) -- 2.30.2