/
GlobalValues.cpp
103 lines (83 loc) · 2.49 KB
/
GlobalValues.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 "GlobalValues.h"
sf::RenderWindow* window;
sf::View* view;
sf::View* DEFAULT_VIEW;
string getResourcePath()
{
return RESOURCE_PATH;
}
void initRandom()
{
srand(time(0)); // This will ensure a really randomized number by help of time.
}
// Given 15, will return a rand nr between 0-14
int getRandomNumber(int range)
{
static bool randNotInitialised = false;
if (randNotInitialised)
{
initRandom();
}
return rand()%range;
}
// Can't use sf::Mouse::isButtonPressed(sf::Mouse::Left) since it is always true. This one resets to false after doing some action
// and is set to true only when left click is pressed again.
bool leftClickPressed = false;
bool previousLeftClickState = sf::Mouse::isButtonPressed(sf::Mouse::Left); // Left click on previous refresh.
double mouseX = 0; // Mouse coords since sf::Mouse::getPosition(*window).x is too long.
double mouseY = 0;
double relativeMouseX = 0; // Mouse coords since sf::Mouse::getPosition(*window).x is too long.
double relativeMouseY = 0;
// The size of the whole monitor.
int getMonitorWidth()
{
static int screen_width = sf::VideoMode::getDesktopMode().width;
return screen_width;
}
int getMonitorHeight()
{
static int screen_height = sf::VideoMode::getDesktopMode().height;
return screen_height;
}
// Returns the size of the programs' window. Can be less or eaqual to monitor size, but never larger. It should be used when creating the window.
int getWindowWidth()
{
return getAndUpdateWindowWidth(false);
}
int getAndUpdateWindowWidth(bool update)
{
static int windowWidth = 900;
if (update)
{
windowWidth = window->getSize().x;
}
return windowWidth;
}
int getAndUpdateWindowHeight(bool update)
{
static int windowHeight = 676;
if(update)
{
windowHeight = window->getSize().y;
}
return windowHeight;
}
int getWindowHeight()
{
return getAndUpdateWindowHeight(false);
}
sf::Clock runtime;
double SCROLL_SPEED = 2;
bool keys[256];
int mouseScroll = 0; // Negative or positive depending on which way the player scrolls.
sf::RectangleShape mapSize(sf::Vector2f(2000,2000));
// A drawing method that anyone can use. Used when the caller does not want to deal
// with the sprite crap on his side.
sf::Sprite freeSprite;
void drawSprite(int x, int y, double w, double h, TextureIndex textureIndex)
{
freeSprite.setPosition(x, y);
freeSprite.setTexture(getTexture(textureIndex));
freeSprite.setScale(w / getTexture(textureIndex).getSize().x, h / getTexture(textureIndex).getSize().y);
window->draw(freeSprite);
}