-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy paththehutriesapplication.cpp
103 lines (93 loc) · 2.8 KB
/
thehutriesapplication.cpp
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
#include "thehutriesapplication.h"
#include <fstream>
#include "game.h"
#include "gamebalance.h"
TheHutriesApplication::TheHutriesApplication() : applicationWidth (1024),
applicationHeight (640)
{
}
void TheHutriesApplication::start()
{
hutrieApplication.create(sf::VideoMode::getDesktopMode(), "The Hutries", sf::Style::Fullscreen);
while (!GameBalance::exitFlag)
{
Game game(&hutrieApplication, applicationWidth, applicationHeight, horizontalScreenZoom, verticalScreenZoom, fullscreenEnable());
game.menu();
if (GameBalance::exitFlag)
{
hutrieApplication.close();
break;
}
game.play();
}
}
void TheHutriesApplication::adjustResolution()
{
horizontalScreenZoom = getXResolution() / 1280;
verticalScreenZoom = getYResolution() / 768;
}
bool TheHutriesApplication::fullscreenEnable()
{
return (bool) !displayMode.compare("fullscreen");
}
float TheHutriesApplication::getXResolution()
{
float x;
std::istringstream issX(resolution.substr(0,4));
issX >> x;
return x;
}
float TheHutriesApplication::getYResolution()
{
float y;
std::istringstream issY(resolution.substr(7));
issY >> y;
return y;
}
void TheHutriesApplication::readSettingsFromFile()
{
std::ifstream settingsFile;
settingsFile.open ("config/settings.txt", std::ios_base :: in);
if(settingsFile.good() == false)
{
std::cout << "File doesn't exist! Failed to open settings file" << std::endl;
std::cout << "Default settings: ON" << std::endl;
resolution = "1360 x 768";
displayMode = "fullscreen";
musicVolume = 100;
sfxVolume = 80;
}
else
{
std::string bin;
std::getline( settingsFile, bin);
std::getline( settingsFile, bin);
std::getline( settingsFile, resolution);
std::getline( settingsFile, bin);
std::getline( settingsFile, bin);
std::getline( settingsFile, displayMode);
std::getline( settingsFile, displayMode);
std::getline( settingsFile, bin);
std::getline( settingsFile, bin);
std::getline( settingsFile, musicVolumeString);
std::getline( settingsFile, bin);
std::getline( settingsFile, bin);
std::getline( settingsFile, sfxVolumeString);
settingsFile.close();
}
}
void TheHutriesApplication::stringsToNumbers()
{
std::stringstream convertMusic(musicVolumeString);
if (!(convertMusic >> musicVolume))
musicVolume = 0;
std::stringstream convertSFX(sfxVolumeString);
if (!(convertSFX >> sfxVolume))
sfxVolume = 0;
}
void TheHutriesApplication::adjustVolume()
{
stringsToNumbers();
GameBalance::musicVolume = musicVolume;
GameBalance::sfxVolume = sfxVolume;
}