-
Notifications
You must be signed in to change notification settings - Fork 0
/
avo.h
67 lines (61 loc) · 2.08 KB
/
avo.h
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
#pragma once
#include <SFML/Graphics.hpp>
#include <SFML/Window.hpp>
#include <cstdlib>
#include <ctime>
#include <string>
#include <vector>
#include "pet_stats.h"
// inheriting from the petStats class
class avo : public PetStats {
private:
std::vector<std::string> avocado_quotes; // quotes
sf::Music avo_sound; // avo sound
public:
// constructor to initialize quotes and load sound
avo() {
// initializing the quotes for Avocado
avocado_quotes = {
"What did the avocado say to the toast? You’re my butter half!",
"If life gives you avocados, make guacamole!",
"I’m just an avocado, living in a toast world.",
"I’m not a regular avocado, I’m a cool avocado.",
"You guac my world!",
"An avocado a day keeps the bad vibes away.",
"How does an avocado propose? With a guac ring!",
"Just avocado-ing with the flow!"};
// function to load sound
if (!avo_sound.openFromFile(
"[Cartoon Sound FX] Avocado sound effect.mp3")) {
std::cout << "Failed to load avocado sound!" << std::endl;
}
avo_sound.setVolume(100); // setting the volume
}
// function to make sound
void make_sound() override {
if (avo_sound.getStatus() != sf::Sound::Playing) {
avo_sound.play();
}
}
// function to get a random quote for the avocado
std::string getRandomAvoQuote() {
std::srand(static_cast<unsigned>(
std::time(0))); // seed for random number generation
int index = std::rand() % avocado_quotes.size();
return avocado_quotes[index];
}
// function to update the Avo quote
void updateAvoQuote(std::string& selectedQuote, sf::Clock& quoteClock,
float quoteInterval, bool& quoteVisible) {
if (quoteClock.getElapsedTime().asSeconds() >= quoteInterval) {
selectedQuote = getRandomAvoQuote();
quoteClock.restart();
quoteVisible = true;
}
float displayDuration = 10.0f;
if (quoteVisible &&
quoteClock.getElapsedTime().asSeconds() >= displayDuration) {
quoteVisible = false;
}
}
};