mirror of
https://github.com/BreizhHardware/bloubloulespoissons.git
synced 2026-01-18 16:47:31 +01:00
add return to menu and reset player env
This commit is contained in:
10
env.cpp
10
env.cpp
@@ -24,6 +24,16 @@ std::atomic<bool> messageThreadRunning(false);
|
||||
std::atomic<bool> isHost(false);
|
||||
|
||||
|
||||
void resetAll(){
|
||||
game_running = false;
|
||||
isPlayingOnline = false;
|
||||
messageThreadRunning = false;
|
||||
isHost = false;
|
||||
players.empty();
|
||||
players_server.empty();
|
||||
}
|
||||
|
||||
|
||||
bool initEnvironment(SDL_Renderer* renderer) {
|
||||
SDL_Surface* backgroundSurface = IMG_Load("../img/background.png");
|
||||
if (backgroundSurface == nullptr) {
|
||||
|
||||
2
env.h
2
env.h
@@ -40,4 +40,6 @@ extern std::atomic<bool> isHost;
|
||||
bool initEnvironment(SDL_Renderer* renderer);
|
||||
std::vector<SDL_Texture*> initTexture(SDL_Renderer* renderer);
|
||||
|
||||
void resetAll();
|
||||
|
||||
#endif // ENV_H
|
||||
22
main.cpp
22
main.cpp
@@ -312,6 +312,7 @@ void onPlayerLost(Menu &menu){
|
||||
menuRunning = true;
|
||||
menu.changePage("Main");
|
||||
menu.show();
|
||||
resetAll();
|
||||
}
|
||||
|
||||
EventHandler eventHandler;
|
||||
@@ -472,8 +473,18 @@ int pas_la_fontion_main_enfin_ce_nest_pas_la_fontion_principale_du_programme_mai
|
||||
freopen("CON", "w", stdout);
|
||||
freopen("CON", "w", stderr);
|
||||
|
||||
for (int i = 0; i < FISH_NUMBER ; ++i) {
|
||||
school.emplace_back(rand() % ENV_WIDTH, rand() % ENV_HEIGHT, 0.1, 0.1, school, i, 75, 75, renderer, rand() % 2 == 0 ? 1 : 0, fishTextures[rand() % fishCount]);
|
||||
for (int i = 0; i < FISH_NUMBER; ++i) {
|
||||
int x = rand() % ENV_WIDTH;
|
||||
int y = rand() % ENV_HEIGHT;
|
||||
double speedX = 0.1;
|
||||
double speedY = 0.1;
|
||||
std::cout << fishCount << std::endl;
|
||||
int textureIndex = rand() % fishCount;
|
||||
int gender = rand() % 2 == 0 ? 1 : 0;
|
||||
|
||||
std::cout << "Creating fish " << i << " at (" << x << ", " << y << ") with texture " << textureIndex << " and gender " << gender << std::endl;
|
||||
|
||||
school.emplace_back(x, y, speedX, speedY, school, i, 75, 75, renderer, gender, fishTextures[textureIndex]);
|
||||
}
|
||||
std::ranges::sort(school, Fish::SortByX);
|
||||
std::vector<std::thread> fish_threads;
|
||||
@@ -524,6 +535,8 @@ int pas_la_fontion_main_enfin_ce_nest_pas_la_fontion_principale_du_programme_mai
|
||||
}
|
||||
std::cout << "All threads killed" << std::endl;
|
||||
// running = false;
|
||||
school.empty();
|
||||
players.clear();
|
||||
eventHandler.triggerEvent("playerLost");
|
||||
return 0;
|
||||
}
|
||||
@@ -630,7 +643,8 @@ int pas_la_fontion_main_enfin_ce_nest_pas_la_fontion_principale_du_programme_mai
|
||||
} catch (const std::system_error& e) {
|
||||
std::cerr << "Exception caught 5: " << e.what() << std::endl;
|
||||
}
|
||||
|
||||
school.empty();
|
||||
players.clear();
|
||||
eventHandler.triggerEvent("playerLost");
|
||||
}
|
||||
else if (argc > 0 && argc < 65535 && args != "") {
|
||||
@@ -691,6 +705,8 @@ int pas_la_fontion_main_enfin_ce_nest_pas_la_fontion_principale_du_programme_mai
|
||||
} catch (const std::system_error& e) {
|
||||
std::cerr << "Exception caught 4: " << e.what() << std::endl;
|
||||
}
|
||||
school.empty();
|
||||
players.clear();
|
||||
eventHandler.triggerEvent("playerLost");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user