From aa86093f469de9ed225d09a3da2d2f90b48be586 Mon Sep 17 00:00:00 2001 From: stian853 Date: Mon, 20 Nov 2023 10:19:24 +0100 Subject: [PATCH] fix scale lingare --- assets/data.json | 6 ++++++ src/Main_enemy.cc | 7 ++++--- src/Main_enemy.h | 6 +++++- src/States.cc | 12 ++++++++---- src/States.h | 4 +++- 5 files changed, 26 insertions(+), 9 deletions(-) diff --git a/assets/data.json b/assets/data.json index f43f99e..f3899b2 100644 --- a/assets/data.json +++ b/assets/data.json @@ -21,5 +21,11 @@ "game_constants": { "bottles_per_second" : 2 + }, + + "main_enemy": + { + "scale" : [0.35, 0.35] } + } \ No newline at end of file diff --git a/src/Main_enemy.cc b/src/Main_enemy.cc index 8b5dafe..3b3ae83 100644 --- a/src/Main_enemy.cc +++ b/src/Main_enemy.cc @@ -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); diff --git a/src/Main_enemy.h b/src/Main_enemy.h index 4027848..fa1ecf4 100644 --- a/src/Main_enemy.h +++ b/src/Main_enemy.h @@ -8,10 +8,14 @@ #include +#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; diff --git a/src/States.cc b/src/States.cc index ee4a815..53a6a87 100644 --- a/src/States.cc +++ b/src/States.cc @@ -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(data["player"]); helper = std::make_unique(data["helper"]); + enemy = std::make_unique(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) { diff --git a/src/States.h b/src/States.h index 52d0090..5479aa8 100644 --- a/src/States.h +++ b/src/States.h @@ -45,9 +45,11 @@ private: Map game_map; std::unique_ptr player; std::unique_ptr helper; - Main_enemy enemy; + std::unique_ptr enemy; + bool pause_game; sf::Texture bottle_texture; + sf::Texture main_enemy_texture; json data; }; -- 2.30.2