"game_constants":
{
"bottles_per_second" : 2
+ },
+
+ "main_enemy":
+ {
+ "scale" : [0.35, 0.35]
}
+
}
\ No newline at end of file
#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);
#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;
game_map{},
pause_game{false},
player{},
- bottles{},
+ bottles{},
+ main_enemy_texture{},
time_since_last_bottle{0.0f},
bottle_texture {},
data{},
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)
}
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);
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)
{
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;
};