pause_game{false},
player{},
bottles{},
+ helper{},
+ main_enemy_texture{},
time_since_last_bottle{0.0f},
+ game_time{0},
+ time_since_last_yf{0.0f},
bottle_texture {},
+ YF_texture {},
+ yf{},
data{},
- enemy{}
-
+ enemy{},
+ points{0}
{
std::ifstream f("assets/data.json");
data = json::parse(f);
player = std::make_unique<Player>(data["player"]);
helper = std::make_unique<Helper>(data["helper"]);
+ game_map = std::make_unique<Map>(data["map"]);
+ enemy = std::make_unique<Main_enemy>(main_enemy_texture, data["main_enemy"]);
bottle_texture.loadFromFile("assets/kir.png");
-
+ YF_texture.loadFromFile("assets/YF.png");
}
void Game_state::update(Context &context)
}
}
+ player->update(context);
+ helper->update(context);
+
+ if (player->collides(*helper))
+ {
+ points += player->get_collected();
+ player->zero_collected();
+
+ player->collision(*helper);
+ helper->collision(*player);
+ }
+ /*
+ if (player->get_x() < 0) player->set_x(0);
+ if (player->get_x() > S_WIDTH) player->set_x(S_WIDTH);
+ if (player->get_y() < 0) player->set_y(0);
+ if (player->get_y() > S_HEIGHT) player->set_y(S_HEIGHT);
+ */
+
time_since_last_bottle += context.time.asSeconds();
-
- //std::cout << std::fixed << std::setprecision(3) << time_since_last_bottle << std::endl;
+ time_since_last_yf += context.time.asSeconds();
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;
time_since_last_bottle = 0;
}
- //game time
+ if (time_since_last_yf >= 8)
+ {
+ yf.push_back(std::make_unique<YF>(YF_texture));
+ if(yf.size() > 1)
+ {
+ yf.erase(yf.begin());
+ }
+ time_since_last_yf = 0;
+
+ }
- game_map.update(context);
- player->update(context);
- helper->update(context);
- enemy.update(context);
+ enemy->update(context);
+ game_map->update(points, remaining_time);
-
+ 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
{
- game_map.render(window);
+ game_map->render(window);
player->render(window);
- enemy.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);
protected:
private:
float time_since_last_bottle;
+ float game_time;
+ float time_since_last_yf;
- Map game_map;
+ std::unique_ptr<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;
+ sf::Texture YF_texture;
+ std::vector<std::unique_ptr<YF>> yf;
+
json data;
+ int points;
};