-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRestaurant.cpp
More file actions
687 lines (603 loc) · 28.6 KB
/
Restaurant.cpp
File metadata and controls
687 lines (603 loc) · 28.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
#include "Restaurant.h"
// Overloaded constructor
// Constructor with width and height as unsigned to prevent negative dimensions
Restaurant::Restaurant(unsigned int width, unsigned int height, const std::string& title)
: window(sf::VideoMode(width, height), title),
shop(nullptr),
waitingArea(1200, 600, 290, 150),
servingHatch(0, 50, 1500, 100),
appetizer(FoodType::Appetizer, { 445, 60 }, { 40, 40 }), // (FoodType, { x, y }, { w, h })
mainCourse(FoodType::MainCourse, { 605, 60 }, { 40, 40 }), // (FoodType, { x, y }, { w, h })
dessert(FoodType::Dessert, { 775, 70 }, { 40, 40 }), // (FoodType, { x, y }, { w, h })
champagne(FoodType::Champagne, { 905, 50 }, { 40, 40 }), // (FoodType, { x, y }, { w, h })
selectedCustomer(nullptr), // initialize to nullptrs (not selected anything yet)
selectedFood(nullptr),
selectedTable(nullptr),
currentLevel(1) {
// Load font
if (!font.loadFromFile("arial.ttf")) {
std::cerr << "Error loading font\n";
}
// Initialize the bag button position and size
bagButtonPosition = sf::Vector2f(50.f, 50.f);
bagButtonSize = sf::Vector2f(200.f, 50.f);
// Setup the bag button text
bagButton.setSize(bagButtonSize);
bagButton.setPosition(bagButtonPosition);
bagButton.setFillColor(sf::Color(100, 100, 250));
// Setup the bag button text
bagButtonText.setFont(font);
bagButtonText.setString("Open Bag");
bagButtonText.setCharacterSize(24);
bagButtonText.setFillColor(sf::Color::White);
bagButtonText.setPosition(
bagButtonPosition.x + (bagButtonSize.x - bagButtonText.getLocalBounds().width) / 2,
bagButtonPosition.y + (bagButtonSize.y - bagButtonText.getLocalBounds().height) / 2
);
// Initialize the apron button position and size
apronButtonPosition = sf::Vector2f(50.f, 120.f);
apronButtonSize = sf::Vector2f(200.f, 50.f);
// Setup the apron button text
apronButton.setSize(apronButtonSize);
apronButton.setPosition(apronButtonPosition);
apronButton.setFillColor(sf::Color(250, 100, 100));
// Setup the apron button text
apronButtonText.setFont(font);
apronButtonText.setString("Open Apron");
apronButtonText.setCharacterSize(24);
apronButtonText.setFillColor(sf::Color::White);
apronButtonText.setPosition(
apronButtonPosition.x + (apronButtonSize.x - apronButtonText.getLocalBounds().width) / 2,
apronButtonPosition.y + (apronButtonSize.y - apronButtonText.getLocalBounds().height) / 2
);
// Initialize the first level
restaurantManager.setCurrentLevel(currentLevel);
// Assigns the list of customers managed by RestaurantManager to the customers vector in the Restaurant class,
// using polymorphism to handle different derived customer types through the base class pointer (CustomerEntity*),
// allowing access and rendering without knowing specific types.
customers = restaurantManager.getCustomers();
// Retrieve the player instance from the RestaurantManager class
player = restaurantManager.getPlayer(); // Accesses the player pointer managed by RestaurantManager
// Initialize tables
tables.emplace_back(Table("1", { 250, 300 }, { 130, 80 }));
tables.emplace_back(Table("2", { 550, 300 }, { 130, 80 }));
tables.emplace_back(Table("3", { 850, 300 }, { 130, 80 }));
tables.emplace_back(Table("4", { 250, 500 }, { 130, 80 }));
tables.emplace_back(Table("5", { 550, 500 }, { 130, 80 }));
tables.emplace_back(Table("6", { 850, 500 }, { 130, 80 }));
// Manually populate the StepTiles for the pathway
float tileSize = 70;
stepTiles.emplace_back(StepTile(460, 100, tileSize));
stepTiles.emplace_back(StepTile(630, 100, tileSize));
stepTiles.emplace_back(StepTile(790, 100, tileSize));
stepTiles.emplace_back(StepTile(930, 100, tileSize));
stepTiles.emplace_back(StepTile(460, 150, tileSize));
stepTiles.emplace_back(StepTile(460, 200, tileSize));
stepTiles.emplace_back(StepTile(410, 200, tileSize));
stepTiles.emplace_back(StepTile(360, 200, tileSize));
stepTiles.emplace_back(StepTile(310, 200, tileSize));
stepTiles.emplace_back(StepTile(310, 250, tileSize));
stepTiles.emplace_back(StepTile(500, 200, tileSize));
stepTiles.emplace_back(StepTile(550, 200, tileSize));
stepTiles.emplace_back(StepTile(600, 200, tileSize));
stepTiles.emplace_back(StepTile(650, 200, tileSize));
stepTiles.emplace_back(StepTile(700, 200, tileSize));
stepTiles.emplace_back(StepTile(750, 200, tileSize));
stepTiles.emplace_back(StepTile(800, 200, tileSize));
stepTiles.emplace_back(StepTile(850, 200, tileSize));
stepTiles.emplace_back(StepTile(900, 200, tileSize));
stepTiles.emplace_back(StepTile(630, 150, tileSize));
stepTiles.emplace_back(StepTile(630, 200, tileSize));
stepTiles.emplace_back(StepTile(630, 250, tileSize));
stepTiles.emplace_back(StepTile(790, 150, tileSize));
stepTiles.emplace_back(StepTile(790, 200, tileSize));
stepTiles.emplace_back(StepTile(930, 150, tileSize));
stepTiles.emplace_back(StepTile(930, 200, tileSize));
stepTiles.emplace_back(StepTile(930, 250, tileSize));
stepTiles.emplace_back(StepTile(450, 250, tileSize));
stepTiles.emplace_back(StepTile(450, 300, tileSize));
stepTiles.emplace_back(StepTile(450, 350, tileSize));
stepTiles.emplace_back(StepTile(450, 400, tileSize));
stepTiles.emplace_back(StepTile(750, 250, tileSize));
stepTiles.emplace_back(StepTile(750, 300, tileSize));
stepTiles.emplace_back(StepTile(750, 350, tileSize));
stepTiles.emplace_back(StepTile(750, 400, tileSize));
stepTiles.emplace_back(StepTile(700, 400, tileSize));
stepTiles.emplace_back(StepTile(650, 400, tileSize));
stepTiles.emplace_back(StepTile(600, 400, tileSize));
stepTiles.emplace_back(StepTile(550, 400, tileSize));
stepTiles.emplace_back(StepTile(500, 400, tileSize));
stepTiles.emplace_back(StepTile(800, 400, tileSize));
stepTiles.emplace_back(StepTile(850, 400, tileSize));
stepTiles.emplace_back(StepTile(900, 400, tileSize));
stepTiles.emplace_back(StepTile(450, 400, tileSize));
stepTiles.emplace_back(StepTile(400, 400, tileSize));
stepTiles.emplace_back(StepTile(350, 400, tileSize));
stepTiles.emplace_back(StepTile(300, 400, tileSize));
stepTiles.emplace_back(StepTile(300, 450, tileSize));
stepTiles.emplace_back(StepTile(600, 450, tileSize));
stepTiles.emplace_back(StepTile(900, 450, tileSize));
stepTiles.emplace_back(StepTile(950, 400, tileSize));
stepTiles.emplace_back(StepTile(1000, 400, tileSize));
stepTiles.emplace_back(StepTile(1050, 400, tileSize));
stepTiles.emplace_back(StepTile(1100, 400, tileSize));
stepTiles.emplace_back(StepTile(1150, 400, tileSize));
stepTiles.emplace_back(StepTile(1200, 400, tileSize));
stepTiles.emplace_back(StepTile(1200, 450, tileSize));
stepTiles.emplace_back(StepTile(1200, 500, tileSize));
stepTiles.emplace_back(StepTile(1200, 550, tileSize));
stepTiles.emplace_back(StepTile(1250, 550, tileSize));
stepTiles.emplace_back(StepTile(1300, 550, tileSize));
stepTiles.emplace_back(StepTile(1350, 550, tileSize));
}
// Main game loop
void Restaurant::run() {
// Enqueue music tracks for each level at the start
audioManager.enqueueTrack("Main Menu.wav");
audioManager.enqueueTrack("On Time! (Barely).wav");
audioManager.enqueueTrack("Table for Two.wav");
// Start playing the first track
audioManager.playNextTrack();
// Main game loop that runs while the game window is open
while (window.isOpen()) {
processEvents(); // Process player inputs and other events
checkPlayerCustomerCollision(); // Check if the player has collided with a customer
// Call to check if reputation should increase (for Fortune Cat)
player->updateReputationForFortuneCat();
// Call to check if reputation should increase (for Fortune Pig)
player->updateReputationForFortunePig();
// Call to check if reputation should increase (for Fortune Mask)
player->updateReputationForFortuneMask();
update(); // Update game objects and state
render(); // Render the game scene
int reputation = player->getPlayerReputation(); // Get the player's current reputation
// Check if the player's reputation has dropped to 0 or below
if (reputation <= 0) {
std::cout << "Player's reputation has dropped to 0 or below. Game Over!" << std::endl;
audioManager.stopMusic(); // Stop all background music
audioManager.stopJumpscareSound(); // Stop any jumpscare sound
exit(0); // Exit the program immediately
}
// Transition logic for Level 1 to Level 2
if (currentLevel == 1 && restaurantManager.isLevelComplete()) {
std::cout << "Level 1 complete! Moving to Level 2...\n";
std::cout << "Press any key to continue..." << std::endl; // Prompt user
std::cin.ignore(); // Wait for user input
std::cin.get(); // Wait for any key press
// Get or create the Shop instance
shop = Shop::getInstance(player, &enemy, selectedCustomer, cardStack);
if (shop) {
shop->resetShop(); // Reset shop for the new level
shop->openShop(); // Open the shop for purchases
}
else {
std::cerr << "Failed to get Shop instance!" << std::endl;
}
currentLevel = 2; // Move to Level 2
restaurantManager.setCurrentLevel(currentLevel); // Update RestaurantManager to new level
audioManager.playNextTrack(); // Play the next level's music track
// Update local variables to reflect new level data
customers = restaurantManager.getCustomers(); // Retrieve updated customer list
player = restaurantManager.getPlayer(); // Retrieve updated player instance
}
// Transition logic for Level 2 to Level 3
if (currentLevel == 2 && restaurantManager.isLevelComplete()) {
std::cout << "Level 2 complete! Moving to Level 3...\n";
std::cout << "Press any key to continue..." << std::endl; // Prompt user to continue
std::cin.ignore(); // Wait for user input
std::cin.get(); // Wait for any key press
// Obtain or create the Shop instance
shop = Shop::getInstance(player, &enemy, selectedCustomer, cardStack);
if (shop) {
shop->resetShop(); // Reset shop for the new level
shop->openShop(); // Open the shop for purchases
}
else {
std::cerr << "Failed to get Shop instance!" << std::endl;
}
currentLevel = 3; // Move to Level 3
restaurantManager.setCurrentLevel(currentLevel); // Update RestaurantManager to new level
audioManager.playNextTrack(); // Play the next level's music track
// Update local variables to reflect new level data
customers = restaurantManager.getCustomers(); // Retrieve updated customer list
player = restaurantManager.getPlayer(); // Retrieve updated player instance
}
// Check if Level 3 is complete, indicating the end of the game
if (currentLevel == 3 && restaurantManager.isLevelComplete()) {
std::cout << "Congratulations! You have completed all levels. Game Over!" << std::endl;
std::cout << "Press any key to exit..." << std::endl; // Prompt user to exit
std::cin.ignore(); // Wait for user input
std::cin.get(); // Wait for any key press
window.close(); // Close the game window
break; // Exit the game loop
}
}
}
// Define this method to check if the player is within the StepTile boundaries, helping in pathing and movement restriction
bool Restaurant::isWithinStepTileBoundaries(const sf::Vector2f& position) const {
// Iterate through all step tiles
for (const auto& tile : stepTiles) {
// Check if the player is within the bounds of a step tile
if (tile.contains(position)) {
return true; // Player is within one of the step tile boundaries
}
}
return false; // Player is outside all step tile boundaries
}
// Function to check if the player collides with any scrap and remove it
void Restaurant::checkPlayerScrapCollision() {
// Loop through all scraps from the RestaurantManager
for (auto currentScrap = restaurantManager.getScraps().begin(); currentScrap != restaurantManager.getScraps().end();) {
sf::FloatRect playerBounds = player->getGlobalBounds();
sf::FloatRect scrapBounds = currentScrap->getGlobalBounds();
// Check if the player's bounds intersect with the scrap's bounds
if (playerBounds.intersects(scrapBounds)) {
// Check if the scrap is already in the player's apron
if (!player->findScrapFromApron(currentScrap->getName())) {
player->addScrapToApron(currentScrap->getName());
}
// Remove the scrap from the vector
currentScrap = restaurantManager.getScraps().erase(currentScrap);
}
else {
++currentScrap; // Move to the next scrap if no collision
}
}
}
// Checks if player collides with a customer
void Restaurant::checkPlayerCustomerCollision() {
// Check for "Reputation Boosting Kit" in the bag and apply to any customer type
if (player->IsItemInBag("Reputation Boosting Kit") && player->isItemActivated("Reputation Boosting Kit")) { // Check if "Reputation Boosting Kit" is in the bag
for (auto& customer : customers) {
if (customer->getGlobalBounds().intersects(player->getGlobalBounds())) {
// Player is in proximity of a customer
// Apply the "Reputation Boosting Kit" effect to any customer type
reputationBoostingKit.applyCustomerEffect(player, customer);
}
}
}
if (player->IsItemInBag("Cigarettes") && player->isItemActivated("Cigarettes")) { // Check if "Cigarette" is in the bag
for (auto& customer : customers) {
if (dynamic_cast<VIPCustomer*>(customer)) { // Check if it's a VIP customer
if (customer->getGlobalBounds().intersects(player->getGlobalBounds())) {
// Player is in proximity of a VIP customer
// Apply the effect only if "Cigarette" is found in the inventory
cigarettes.applyCustomerEffect(player, customer);
}
}
}
}
if (player->IsItemInBag("Pearls") && player->isItemActivated("Pearls")) { // Check if "Pearls" is in the bag
for (auto& customer : customers) {
if (dynamic_cast<PrincessCustomer*>(customer)) { // Check if it's a Princess customer
if (customer->getGlobalBounds().intersects(player->getGlobalBounds())) {
// Player is in proximity of a Princess customer
// Apply the effect only if "Pearls" is found in the inventory
pearls.applyCustomerEffect(player, customer);
}
}
}
}
if (player->IsItemInBag("WaterBottle") && player->isItemActivated("WaterBottle")) { // Check if "WaterBottle" is in the bag
for (auto& customer : customers) {
if (dynamic_cast<SeniorCustomer*>(customer)) { // Check if it's a Senior customer
if (customer->getGlobalBounds().intersects(player->getGlobalBounds())) {
// Player is in proximity of a Senior customer
// Apply the effect only if "WaterBottle" is found in the inventory
waterBottle.applyCustomerEffect(player, customer);
}
}
}
}
// Apply effects of other activated items in the player's bag that impact the player or enemy directly
if (player->IsItemInBag("Speed Boosting Kit") && player->isItemActivated("Speed Boosting Kit")) {
speedBoostingKit.applyEffect(player, &enemy);
}
if (player->IsItemInBag("Boots") && player->isItemActivated("Boots")) {
boots.applyEffect(player, &enemy);
}
if (player->IsItemInBag("Heels") && player->isItemActivated("Heels")) {
heels.applyEffect(player, &enemy);
}
if (player->IsItemInBag("Butter") && player->isItemActivated("Butter")) {
butter.applyEffect(player, &enemy);
}
if (player->IsItemInBag("Axolotl") && player->isItemActivated("Axolotl")) {
axolotl.applyEffect(player, &enemy);
}
if (player->IsItemInBag("Fortune Cat") && player->isItemActivated("Fortune Cat")) {
fortuneCat.applyEffect(player, &enemy);
}
if (player->IsItemInBag("Fortune Pig") && player->isItemActivated("Fortune Pig")) {
fortunePig.applyEffect(player, &enemy);
}
}
// Processes all events
void Restaurant::processEvents() {
sf::Event event;
while (window.pollEvent(event)) {
if (event.type == sf::Event::Closed) {
window.close();
}
// Check for a mouse click on the bag button
if (event.type == sf::Event::MouseButtonPressed && event.mouseButton.button == sf::Mouse::Left) {
sf::Vector2i mousePos = sf::Mouse::getPosition(window);
// Check if the click is within the bounds of the bag button
if (bagButton.getGlobalBounds().contains(sf::Vector2f(mousePos))) {
player->handleBagMenu();
}
// Check if the click is within the bounds of the apron button
if (apronButton.getGlobalBounds().contains(sf::Vector2f(mousePos))) {
player->handleApronMenu();
}
}
// Handle key presses
if (event.type == sf::Event::KeyPressed) {
// Press spacebar to review player's current reputation
if (event.key.code == sf::Keyboard::Space) {
if (player) {
std::cout << "Player Reputation: " << player->getPlayerReputation() << std::endl;
std::cout << "\n";
}
else {
std::cout << "Player instance is null\n" << std::endl; // Debugging output
}
}
}
// Handle mouse clicks
if (event.type == sf::Event::MouseButtonPressed) {
float mouseX = event.mouseButton.x;
float mouseY = event.mouseButton.y;
// Handle right mouse clicks
if (event.mouseButton.button == sf::Mouse::Right) {
handleRightClick(mouseX, mouseY);
}
}
}
}
bool isColliding = false;
// Updates game state and elements each frame
void Restaurant::update() {
// Handle player movement with arrow keys
if (player) {
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Up)) {
// Move up
sf::Vector2f newPosition = player->getPosition();
newPosition.y -= player->getPlayerSpeed();
// Check boundaries before updating the position
if (isWithinStepTileBoundaries(newPosition)) {
player->setPosition(newPosition);
}
}
else if (sf::Keyboard::isKeyPressed(sf::Keyboard::Down)) {
// Move down
sf::Vector2f newPosition = player->getPosition();
newPosition.y += player->getPlayerSpeed();
if (isWithinStepTileBoundaries(newPosition)) {
player->setPosition(newPosition);
}
}
else if (sf::Keyboard::isKeyPressed(sf::Keyboard::Left)) {
// Move left
sf::Vector2f newPosition = player->getPosition();
newPosition.x -= player->getPlayerSpeed();
if (isWithinStepTileBoundaries(newPosition)) {
player->setPosition(newPosition);
}
}
else if (sf::Keyboard::isKeyPressed(sf::Keyboard::Right)) {
// Move right
sf::Vector2f newPosition = player->getPosition();
newPosition.x += player->getPlayerSpeed();
if (isWithinStepTileBoundaries(newPosition)) {
player->setPosition(newPosition);
}
}
}
// Check for interactions based on player proximity to objects
handlePlayerProximity();
// Check if player is colliding with any scrap
checkPlayerScrapCollision();
// Update each customer in the restaurant
for (auto& customer : customers) {
customer->update();
}
// Update enemy spawning and behavior through restaurant manager
restaurantManager.update();
bool hasColliding = false;
// If the enemy has spawned, update the enemy behavior
if (restaurantManager.isEnemySpawned()) {
enemy.chase(player, *this);
// Check for collisions between the player and the enemy
if (checkCollision(*player, enemy)) {
if (!isColliding) {
// Apply effect if player has a specific item and it's active
if (player->IsItemInBag("Fortune Mask") && player->isItemActivated("Fortune Mask")) {
fortuneMask.applyEffect(player, &enemy);
}
std::cout << "Playing Jumpscare Sound..." << std::endl;
audioManager.playJumpscareSound("Jumpscare Sound.wav", 20); // Play sound
enemy.attackPlayerReputation(); // Decrease player's reputation
isColliding = true; // Set collision state to true
}
}
else {
isColliding = false; // Reset collision state if no collision
}
}
// Check if all customers have finished their meals
restaurantManager.checkLevelCompletion(window, customers);
}
// Checks for collision between player and enemy
bool Restaurant::checkCollision(const Player& player, const Enemy& enemy) {
// Get bounding boxes of player and enemy
sf::FloatRect playerBounds = player.getGlobalBounds();
sf::FloatRect enemyBounds = enemy.getGlobalBounds();
// Check for intersection between bounding boxes
return playerBounds.intersects(enemyBounds);
}
// Renders the game elements on the screen
void Restaurant::render() {
window.clear();
// Draw static restaurant elements
waitingArea.draw(window);
servingHatch.draw(window);
// Draw each step tile
for (auto& tile : stepTiles) {
tile.draw(window);
}
// Draw each table
for (auto& table : tables) {
table.draw(window);
}
// Draw food items
appetizer.draw(window);
mainCourse.draw(window);
dessert.draw(window);
champagne.draw(window);
// Draw enemy if it has spawned
if (restaurantManager.isEnemySpawned()) {
enemy.draw(window);
}
// Draw scraps on the screen
for (const Scrap& scrap : restaurantManager.getScraps()) {
scrap.draw(window);
}
// Draw each customer in the restaurant
for (auto& customer : customers) {
customer->draw(window);
}
// Draw the player character
if (player) {
player->draw(window);
}
// Draw the bag button
window.draw(bagButton);
window.draw(bagButtonText);
// Draw the apron button
window.draw(apronButton);
window.draw(apronButtonText);
window.display();
}
// Handles logic when the player is intersecting specific objects
void Restaurant::handlePlayerProximity() {
bool foodSelectionConfirmed = false; // Flag to confirm food selection
// Check if player intersects any food item and set selectedFood
if (appetizer.getGlobalBounds().intersects(player->getGlobalBounds())) {
if (!appetizer.isMessagePrinted()) {
std::cout << "Food selected: Appetizer\n";
appetizer.setMessagePrinted(true);
}
selectedFood = &appetizer;
foodSelectionConfirmed = false;
}
else if (mainCourse.getGlobalBounds().intersects(player->getGlobalBounds())) {
if (!mainCourse.isMessagePrinted()) {
std::cout << "Food selected: Main Course\n";
mainCourse.setMessagePrinted(true);
}
selectedFood = &mainCourse;
foodSelectionConfirmed = false;
}
else if (dessert.getGlobalBounds().intersects(player->getGlobalBounds())) {
if (!dessert.isMessagePrinted()) {
std::cout << "Food selected: Dessert\n";
dessert.setMessagePrinted(true);
}
selectedFood = &dessert;
foodSelectionConfirmed = false;
}
else if (champagne.getGlobalBounds().intersects(player->getGlobalBounds())) {
if (!champagne.isMessagePrinted()) {
std::cout << "Food selected: Champagne\n";
champagne.setMessagePrinted(true);
}
selectedFood = &champagne;
foodSelectionConfirmed = false;
}
else {
// Reset message status if no food selected
appetizer.setMessagePrinted(false);
mainCourse.setMessagePrinted(false);
dessert.setMessagePrinted(false);
champagne.setMessagePrinted(false);
appetizer.resetMessageStatus();
mainCourse.resetMessageStatus();
dessert.resetMessageStatus();
champagne.resetMessageStatus();
}
// Check proximity to customers and confirm food selection
for (auto& customer : customers) {
if (customer->getGlobalBounds().intersects(player->getGlobalBounds())) {
if (!customer->isMessagePrinted()) {
std::cout << customer->getCustomerID() << " is selected\n";
customer->setMessagePrinted(true);
}
// If food is selected but not confirmed, confirm selection by touching customer again
if (selectedFood != nullptr && !foodSelectionConfirmed) {
selectedCustomer = customer;
foodSelectionConfirmed = true; // Now food selection is confirmed
std::cout << "Food selection confirmed. Customer " << selectedCustomer->getCustomerID() << " ready for food assignment.\n";
}
// If no food is selected, just select the customer for seating
else if (selectedFood == nullptr) {
selectedCustomer = customer;
}
break; // Exit the loop after selecting customer
}
else {
customer->resetMessageStatus(); // Reset if not colliding
}
}
// Check if the player's circle is colliding a table
for (auto& table : tables) {
if (table.getGlobalBounds().intersects(player->getGlobalBounds())) {
if (!table.isMessagePrinted()) {
std::cout << "Table " << table.getTableID() << " is " << (table.isAvailable() ? "vacant\n" : "occupied\n");
table.setMessagePrinted(true);
}
selectedTable = &table;
break;
}
else {
table.resetMessageStatus();
}
}
// Assign customer to table if conditions are met
if (selectedCustomer != nullptr && !selectedCustomer->isSeated() && selectedTable != nullptr && selectedTable->isAvailable()) {
std::cout << "Customer " << selectedCustomer->getCustomerID() << " assigned to Table " << selectedTable->getTableID() << std::endl;
// Assign table to customer and update positions and states
selectedTable->setAvailability(false);
selectedCustomer->setSeated(true);
selectedCustomer->setPosition(selectedTable->getPosition().x + selectedTable->getWidth() / 2 - selectedCustomer->getRadius(),
selectedTable->getPosition().y + selectedTable->getHeight() / 2 - selectedCustomer->getRadius());
selectedCustomer->seat(selectedTable);
// Deselect customer after seating
selectedCustomer = nullptr;
}
// Assign food to customer if selection is confirmed
if (foodSelectionConfirmed && selectedCustomer != nullptr && selectedCustomer->isSeated()) {
*selectedFood >> selectedCustomer; // Use the overloaded operator for food assignment
// Deselect both food and customer after assignment
selectedFood = nullptr;
selectedCustomer = nullptr;
foodSelectionConfirmed = false; // Reset confirmation state
}
}
// Handles right-click interactions to display customer stats
void Restaurant::handleRightClick(float mouseX, float mouseY) {
for (CustomerEntity* customer : customers) {
if (customer->isClicked(mouseX, mouseY)) {
std::cout << *customer << std::endl; // Output customer stats
}
}
}
// Destructor
Restaurant::~Restaurant() {
// Delete all dynamically allocated customers
for (auto customer : customers) {
delete customer;
}
// Set the vector to empty to release any held memory
customers.clear();
}