fix scale lingare
authorstian853 <stian853@su15-112.ad.liu.se>
Mon, 20 Nov 2023 09:19:24 +0000 (10:19 +0100)
committerstian853 <stian853@su15-112.ad.liu.se>
Mon, 20 Nov 2023 09:19:24 +0000 (10:19 +0100)
assets/data.json
src/Main_enemy.cc
src/Main_enemy.h
src/States.cc
src/States.h

index f43f99e97a4d5912c8bde96ccf569422856e4108..f3899b2bc4e9f4ad49c0e998c7ccc5315e620b8d 100644 (file)
     "game_constants":
     {
         "bottles_per_second" : 2
+    },
+
+    "main_enemy":
+    {
+        "scale" : [0.35, 0.35]
     }
+
 }
\ No newline at end of file
index 8b5dafe165203e46b1008bd0c370e59f53b8d42a..3b3ae8367cf7cbbd8d43373a68b12664319f9e40 100644 (file)
@@ -5,12 +5,13 @@
 #include "States.h"
 #include "Context.h"
 
-Main_enemy::Main_enemy()
+Main_enemy::Main_enemy(sf::Texture& txtr, json& params)
 {
-    texture.loadFromFile("assets/6Ling_figur2.png");
+    //texture.loadFromFile("assets/6Ling_figur2.png");
+    texture = txtr;
     sprite.setTexture(texture);
 
-    sprite.setScale(0.7, 0.7);
+    sprite.setScale(params["scale"][0], params["scale"][1]);
     sf::FloatRect gb {sprite.getGlobalBounds()};
     sprite.setOrigin(gb.width / 2, gb.height / 2);
     sprite.setPosition(position);
index 4027848e327d1d33e30172a4fa62891e353ea4d1..fa1ecf49fc0c420dc9770a628cbe50569e3b836f 100644 (file)
@@ -8,10 +8,14 @@
 
 #include <vector>
 
+#include "json.hpp"
+
+using json = nlohmann::json;
+
 class Main_enemy : public Moving_object
 {
 public:
-    Main_enemy();
+    Main_enemy(sf::Texture& txtr, json& params);
     ~Main_enemy() = default;
     void collision(Object& other) override;
     void update(Context& context) override;
index ee4a815fdf116a133eb4adb73c62dc22b0813bca..53a6a87e9b68673937a00f3a90ad3ee8b71c638b 100644 (file)
@@ -14,7 +14,8 @@ Game_state::Game_state() :
     game_map{}, 
     pause_game{false},
     player{},
-    bottles{}, 
+    bottles{},
+    main_enemy_texture{}, 
     time_since_last_bottle{0.0f},
     bottle_texture {},
     data{},
@@ -23,11 +24,14 @@ Game_state::Game_state() :
     std::ifstream f("assets/data.json");
     data = json::parse(f);
 
+    main_enemy_texture.loadFromFile("assets/6Ling_figur2.png");
 
     player = std::make_unique<Player>(data["player"]);
     helper = std::make_unique<Helper>(data["helper"]);
+    enemy = std::make_unique<Main_enemy>(main_enemy_texture, data["main_enemy"]);
 
     bottle_texture.loadFromFile("assets/kir.png");
+    
 }
 
 void Game_state::update(Context &context)
@@ -62,7 +66,7 @@ void Game_state::update(Context &context)
     }
     for (unsigned int i {0}; i < bottles.size(); ++i)
     {
-        if (enemy.collides(*(bottles[i])))
+        if (enemy->collides(*(bottles[i])))
         {
             // std::cout <<"crash" << std::endl;
             bottles.erase(bottles.begin() + i);
@@ -80,14 +84,14 @@ void Game_state::update(Context &context)
     game_map.update(context);
     player->update(context);
     helper->update(context);
-    enemy.update(context);
+    enemy->update(context);
 }
 
 void Game_state::render(sf::RenderWindow &window) const
 {
     game_map.render(window);
     player->render(window);
-    enemy.render(window);
+    enemy->render(window);
     helper->render(window);
     for (int i{}; i < int(bottles.size()); ++i)
     {
index 52d0090128c58aa4f1814a1570a1e1a8b67b3376..5479aa800cd5187893cc821a9d08b375ab434a72 100644 (file)
@@ -45,9 +45,11 @@ private:
     Map game_map;
     std::unique_ptr<Player> player;
     std::unique_ptr<Helper> helper;
-    Main_enemy enemy;
+    std::unique_ptr<Main_enemy> enemy;
+
     bool pause_game;
     sf::Texture bottle_texture;
+    sf::Texture main_enemy_texture;
     json data;
 
 };