player{},
bottles{},
time_since_last_bottle{0.0f},
+ time_since_last_yf{0.0f},
bottle_texture {},
+ YF_texture {},
+ yf{},
data{},
enemy{}
+
{
std::ifstream f("assets/data.json");
data = json::parse(f);
helper = std::make_unique<Helper>(data["helper"]);
bottle_texture.loadFromFile("assets/kir.png");
+ YF_texture.loadFromFile("assets/YF.png");
}
void Game_state::update(Context &context)
}
}
time_since_last_bottle += context.time.asSeconds();
+ time_since_last_yf += context.time.asSeconds();
//std::cout << std::fixed << std::setprecision(3) << time_since_last_bottle << std::endl;
if (time_since_last_bottle >= data["game_constants"]["bottles_per_second"])
{
bottles.push_back(std::make_unique<Bottle>(bottle_texture, data["bottle"]));
- std::cout << "placed bottle"<< std::endl;
+ //std::cout << "placed bottle"<< std::endl;
time_since_last_bottle = 0;
}
+ if (time_since_last_yf >= 5)
+ {
+ yf.push_back(std::make_unique<YF>(YF_texture));
+ std::cout << "yf spawned"<< std::endl;
+ time_since_last_yf = 0;
+ }
game_map.update(context);
player->update(context);
helper->update(context);
enemy.update(context);
+ if (yf.size()>0)
+ {
+ for(unsigned int i {0}; i < yf.size(); ++i)
+ {
+ yf[i]->update(context);
+ }
+ }
+
}
void Game_state::render(sf::RenderWindow &window) const
player->render(window);
enemy.render(window);
helper->render(window);
+
+
+ for(unsigned int i {0}; i < yf.size(); ++i)
+ {
+ yf[i]->render(window);
+ }
+
for (int i{}; i < int(bottles.size()); ++i)
{
bottles[i]->render(window);
#include "Main_enemy.h"
#include "Helper.h"
#include "Bottle.h"
+#include "YF.h"
#include "json.hpp"
using json = nlohmann::json;
protected:
private:
float time_since_last_bottle;
+ float time_since_last_yf;
Map game_map;
std::unique_ptr<Player> player;
Main_enemy enemy;
bool pause_game;
sf::Texture bottle_texture;
+ sf::Texture YF_texture;
+ std::vector<std::unique_ptr<YF>> yf;
+
json data;
};
+++ /dev/null
-#ifndef VOI_ENEMY_H
-#define VOI_ENEMY_H
-
-#include <SFML/Graphics.hpp>
-
-class Voi_enemy
-{
-public:
- bool collides(Object &other) override;
- void collision(Object &other) override;
- void update() override;
- void render(sf::RenderWindow &window) override;
-
-private:
- void move(Time) override;
-
-protected:
- double x_pos;
- double y_pos;
- sf::Sprite sprite;
-};
-
-#endif
\ No newline at end of file
--- /dev/null
+#include "YF.h"
+#include "constants.h"
+#include "Context.h"
+#include "States.h"
+#include <random>
+
+
+YF::YF(sf::Texture& txtr)//, json& params)
+{
+ texture = txtr;
+ sprite.setTexture(texture);
+ //position = {500, 500};
+ position ={rand()%(S_WIDTH*5/7 - S_WIDTH/5 +1) + S_WIDTH/5, S_HEIGHT}; //x-pixel WIDTH/5 - WIDTH*5/7
+ //sprite.setScale(params["scale"][0], params["scale"][1]);
+ sprite.setScale(1, 1);
+ sf::FloatRect gb {sprite.getGlobalBounds()};
+ sprite.setOrigin(gb.width / 2, gb.height / 2);
+ sprite.setPosition(position);
+
+}
+
+
+void YF::collision(Object &other)
+{
+
+}
+void YF::update(Context& context)
+{
+ Game_state* game = static_cast<Game_state*>(context.current_state.get());
+ direction = {0, -1};
+ position += direction*2.0f;
+ sprite.setPosition(position);
+}
+void YF::render(sf::RenderWindow &window) const
+{
+ window.draw(sprite);
+}
--- /dev/null
+#ifndef YF_H
+#define YF_H
+
+#include "Moving_object.h"
+#include "Object.h"
+#include <SFML/Graphics.hpp>
+#include "json.hpp"
+
+using json = nlohmann::json;
+
+class YF : public Moving_object
+{
+public:
+ YF(sf::Texture& txtr);//, json& params);
+ ~YF() = default;
+ void collision(Object &other) override;
+ void update(Context& context) override;
+ void render(sf::RenderWindow &window) const override;
+
+private:
+ //void move(Time) override;
+
+protected:
+
+};
+
+#endif
\ No newline at end of file