From: lukel495 Date: Mon, 27 Nov 2023 07:51:08 +0000 (+0100) Subject: merging yf and game_time X-Git-Url: https://gitweb.forssennils.se/?a=commitdiff_plain;h=134efef5640db2050792e91950ad865c8d65a04a;p=TDDC76_proj.git merging yf and game_time --- 134efef5640db2050792e91950ad865c8d65a04a diff --cc src/States.cc index eff307c,7cc5c5d..af793b7 --- a/src/States.cc +++ b/src/States.cc @@@ -16,14 -15,14 +16,17 @@@ Game_state::Game_state() 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); @@@ -32,11 -30,9 +35,11 @@@ player = std::make_unique(data["player"]); helper = std::make_unique(data["helper"]); + game_map = std::make_unique(data["map"]); + enemy = std::make_unique(main_enemy_texture, data["main_enemy"]); bottle_texture.loadFromFile("assets/kir.png"); - + YF_texture.loadFromFile("assets/YF.png"); } void Game_state::update(Context &context) @@@ -77,45 -74,50 +80,66 @@@ } } + 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_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_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); diff --cc src/States.h index 9eedbf5,45fff0c..033d30a --- a/src/States.h +++ b/src/States.h @@@ -41,18 -42,18 +42,22 @@@ public protected: private: float time_since_last_bottle; + float game_time; + float time_since_last_yf; - Map game_map; + std::unique_ptr 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; + sf::Texture YF_texture; + std::vector> yf; + json data; + int points; };