El Octavio  1.0
This is a video game about adventures.
Additional Functions.cpp
Go to the documentation of this file.
1#include "../Header files/Precompile.h";
2#include "../Header files/Additional Functions.h";
3#include "../Header files/Menu.h";
4
7
8void changeFPS(int FPS, RenderWindow& window)
9{
10 window.setFramerateLimit(FPS);
11}
12
13void addIcon(RenderWindow& window)
14{
15 Image icon;
16
17 if (!icon.loadFromFile("../Images and fonts/Icon.png"))
18 {
19 cout << "Error";
20 }
21
22 window.setIcon(icon.getSize().x, icon.getSize().y, icon.getPixelsPtr());
23}
24
26{
27 Sound soundWrite;
28 SoundBuffer writeBuffer;
29
30 writeBuffer.loadFromFile("../Audios/Write.wav");
31
32 soundWrite.setBuffer(writeBuffer);
33
34 backstoryTexture.loadFromFile("../Images and fonts/Bg/BackstoryFrame.png");
36
37 //Typewriting effect
38 Font fontBackstory;
39 fontBackstory.loadFromFile("../Images and fonts/Fonts/Header font.ttf");
40
41 string Backstory = "Hello friend!\nI'm a Kurabirov and I'm here to tell you my story.\nSome time ago I was a professional boxer and I was very successful in that.\nWhen cryptocurrencies came out, I really liked them and started studying them.\nAnyway, because I knew how the market works,\nit was time to test my knowledge and bought stoshevcoin and staichocoin.\nBut things went wrong and these two cryptocurrencies collapsed.\nA lot of people have become attached to the propaganda that this will be\nthe currency of the future and we have lost all our money. Anyway, I became homeless.\nOne day, three costumed men abducted me in a van and put on a mask so I couldn't see. After a while,\nthey stopped the van, removed my mask, and I was in front of a mansion.\nIt turned out that the boss of the turkish mafia lives here(he also has a telsa).\nHe wanted me to place an order for him. Without telling me much, I agreed and here I am now.";
42 Text textBackstory("", fontBackstory, 34);
43 textBackstory.setFillColor(Color(0, 0, 0));
44 textBackstory.setPosition(81, 205);
45
46 //frame timing
48 unsigned int character = 0;
49
50 bool isTouched = false, isTouchedForBreak = false;
51
52 if(isAudioRunning(audioToggle) == true)
53 {
54 soundWrite.play();
55 }
56
57 soundWrite.setVolume(200);
58 Event ev;
59
60 while (window.isOpen())
61 {
62 while (window.pollEvent(ev))
63 {
64
65 if (ev.type == Event::Closed)
66 {
67 window.close();
68 }
69
70 if (ev.type == Event::KeyPressed && ev.key.code == Keyboard::Escape)
71 {
72 window.close();
73 }
74
75 if (ev.type == Event::KeyReleased && ev.key.code == Keyboard::Enter) {
76 isTouchedForBreak = true;
77 textBackstory.setString(String(Backstory.substr(0, Backstory.length())));
78 }
79 }
80
81
82 if (isTouched == false)
83 {
84 if (timer.getElapsedTime().asSeconds() > 0.05 && character < Backstory.length())
85 {
86 timer.restart();
87
88 character++;
89
90 textBackstory.setString(String(Backstory.substr(0, character)));
91 }
92 }
93 else if (isTouched == true) {
94 textBackstory.setString(String(Backstory.substr(0, Backstory.length())));
95 }
96
97 window.clear();
98 window.draw(backstoryImage);
99 window.draw(textBackstory);
100 window.display();
101
102 if ((ev.mouseButton.x >= 0 && ev.mouseButton.x <= 1280) && (ev.mouseButton.y >= 0 && ev.mouseButton.y <= 720))
103 {
104 isTouchedForBreak = true;
105 }
106
107 if (isTouchedForBreak == true)
108 {
109 break;
110
111 }
112 }
113
114 soundWrite.stop();
115}
void addIcon(RenderWindow &window)
void backstory(RenderWindow &window, Texture backstoryTexture, Sprite backstoryImage)
void changeFPS(int FPS, RenderWindow &window)
Sprite backstoryImage
Texture backstoryTexture
bool audioToggle
Definition: Menu.cpp:6
bool isAudioRunning(bool &audioToggle)
Definition: Menu.cpp:216
Utility class that measures the elapsed time.
Definition: Clock.hpp:42
Time restart()
Restart the clock.
Time getElapsedTime() const
Get the elapsed time.
Utility class for manipulating RGBA colors.
Definition: Color.hpp:41
Defines a system event and its parameters.
Definition: Event.hpp:45
MouseButtonEvent mouseButton
Mouse button event parameters (Event::MouseButtonPressed, Event::MouseButtonReleased)
Definition: Event.hpp:227
KeyEvent key
Key event parameters (Event::KeyPressed, Event::KeyReleased)
Definition: Event.hpp:224
EventType type
Type of the event.
Definition: Event.hpp:219
Class for loading and manipulating character fonts.
Definition: Font.hpp:51
bool loadFromFile(const std::string &filename)
Load the font from a file.
Class for loading, manipulating and saving images.
Definition: Image.hpp:47
const Uint8 * getPixelsPtr() const
Get a read-only pointer to the array of pixels.
Vector2u getSize() const
Return the size (width and height) of the image.
bool loadFromFile(const std::string &filename)
Load the image from a file on disk.
void draw(const Drawable &drawable, const RenderStates &states=RenderStates::Default)
Draw a drawable object to the render target.
void clear(const Color &color=Color(0, 0, 0, 255))
Clear the entire target with a single color.
Window that can serve as a target for 2D drawing.
Storage for audio samples defining a sound.
Definition: SoundBuffer.hpp:50
bool loadFromFile(const std::string &filename)
Load the sound buffer from a file.
Regular sound that can be played in the audio environment.
Definition: Sound.hpp:46
void play()
Start or resume playing the sound.
void setBuffer(const SoundBuffer &buffer)
Set the source buffer containing the audio data to play.
void stop()
stop playing the sound
void setVolume(float volume)
Set the volume of the sound.
Drawable representation of a texture, with its own transformations, color, etc.
Definition: Sprite.hpp:48
void setTexture(const Texture &texture, bool resetRect=false)
Change the source texture of the sprite.
Utility string class that automatically handles conversions between types and encodings.
Definition: String.hpp:46
Graphical text that can be drawn to a render target.
Definition: Text.hpp:49
void setString(const String &string)
Set the text's string.
void setFillColor(const Color &color)
Set the fill color of the text.
Image living on the graphics card that can be used for drawing.
Definition: Texture.hpp:49
bool loadFromFile(const std::string &filename, const IntRect &area=IntRect())
Load the texture from a file on disk.
float asSeconds() const
Return the time value as a number of seconds.
void setPosition(float x, float y)
set the position of the object
T x
X coordinate of the vector.
Definition: Vector2.hpp:75
T y
Y coordinate of the vector.
Definition: Vector2.hpp:76
bool pollEvent(Event &event)
Pop the event on top of the event queue, if any, and return it.
void setIcon(unsigned int width, unsigned int height, const Uint8 *pixels)
Change the window's icon.
void close()
Close the window and destroy all the attached resources.
void display()
Display on screen what has been rendered to the window so far.
bool isOpen() const
Tell whether or not the window is open.
void setFramerateLimit(unsigned int limit)
Limit the framerate to a maximum fixed frequency.
unsigned int character
Keyboard::Key code
Code of the key that has been pressed.
Definition: Event.hpp:64
int x
X position of the mouse pointer, relative to the left of the owner window.
Definition: Event.hpp:98
int y
Y position of the mouse pointer, relative to the top of the owner window.
Definition: Event.hpp:99