{
- "player" : {
+ "player" :
+ {
"start_pos": [200, 200],
"scale": [0.5, 0.5],
"max_speed": 5
"stop_top": 50,
"stop_bot": 500
},
- "bottle": {}
+ "bottle":
+ {
+ "scale": [0.5, 0.5]
+ },
+ "game_constants":
+ {
+ "bottles_per_second" : 2
+ }
}
\ No newline at end of file
#include "Bottle.h"
#include "constants.h"
#include "Context.h"
+#include "States.h"
#include <random>
-Bottle::Bottle(sf::Texture& txtr)
+Bottle::Bottle(sf::Texture& txtr, json& params)
{
texture = txtr;
sprite.setTexture(texture);
position ={rand()%(S_WIDTH*5/7 - S_WIDTH/5 +1) + S_WIDTH/5, rand()%S_HEIGHT+1}; //x-pixel WIDTH/5 - WIDTH*5/7
- sprite.setScale(S_SCALE_KOEFF, S_SCALE_KOEFF);
+ sprite.setScale(params["scale"][0], params["scale"][1]);
sf::FloatRect gb {sprite.getGlobalBounds()};
sprite.setOrigin(gb.width / 2, gb.height / 2);
sprite.setPosition(position);
#ifndef BOTTLE_H
#define BOTTLE_H
-#include "Static_object.h"
#include <SFML/Graphics.hpp>
+#include "Static_object.h"
+#include "json.hpp"
+
+using json = nlohmann::json;
+
class Bottle : public Static_object
{
public:
- Bottle(sf::Texture& txtr);
+ Bottle(sf::Texture& txtr, json& params);
+
void collision(Object& other) override;
void update(Context& context) override;
void render(sf::RenderWindow& window) const override;
#define HELPER_H
#include <SFML/Graphics.hpp>
+
#include "Autonomous_object.h"
#include "json.hpp"
#define _USE_MATH_DEFINES
#include <SFML/Graphics.hpp>
+
#include "Moving_object.h"
#include "json.hpp"
player{},
bottles{},
time_since_last_bottle{0.0f},
- bottle_texture {}
+ bottle_texture {},
+ data{}
{
std::ifstream f("assets/data.json");
- json data = json::parse(f);
+ data = json::parse(f);
player = std::make_unique<Player>(data["player"]);
helper = std::make_unique<Helper>(data["helper"]);
-
bottle_texture.loadFromFile("assets/kir.png");
-
-
}
void Game_state::update(Context &context)
}
time_since_last_bottle += context.time.asSeconds();
std::cout << std::fixed << std::setprecision(3) << time_since_last_bottle << std::endl;
- if (time_since_last_bottle >= 2)
+ if (time_since_last_bottle >= data["game_constants"]["bottles_per_second"])
{
- bottles.push_back(std::make_unique<Bottle>(bottle_texture));
+ bottles.push_back(std::make_unique<Bottle>(bottle_texture, data["bottle"]));
std::cout << "placed bottle"<< std::endl;
time_since_last_bottle = 0;
}
#include "Player.h"
#include "Helper.h"
#include "Bottle.h"
+#include "json.hpp"
+
+using json = nlohmann::json;
+
struct Context; //finns en strukt som säger att Context finns innan den är deklarerad
std::unique_ptr<Helper> helper;
bool pause_game;
sf::Texture bottle_texture;
+ json data;
};