-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGameFunctions.cpp
More file actions
52 lines (44 loc) · 1.39 KB
/
GameFunctions.cpp
File metadata and controls
52 lines (44 loc) · 1.39 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
#include <SFML/Graphics.hpp>
#include "MainGameFunctions.h"
#include <iostream>
#include <string>
sf::View setWindowView(sf::RenderWindow& window, float length)
{
sf::View gameView(sf::FloatRect(0.f, 0.f, length, length));
float w = window.getSize().x;
float h = window.getSize().y;
if(w<=h)
{
gameView.setViewport(sf::FloatRect(0.f, (h-w)/(2*h), 1.f, w/h));
}
else
{s
gameView.setViewport(sf::FloatRect((w-h)/(2*w), 0.f, h/w, 1.f));
}
window.setView(gameView);
window.setVerticalSyncEnabled(true);
auto icon = sf::Image{};
if (!icon.loadFromFile("icon.png"))
{
std::cout << "Failure" << std::endl;
}
window.setIcon(icon.getSize().x, icon.getSize().y, icon.getPixelsPtr());
//window.setMouseCursorVisible(false);
// std::cout << gameView.getCenter().x << " " << gameView.getCenter().y << std::endl;
return gameView;
}
void resizeEvent(int code, sf::RenderWindow& window, int windowLength)
{
// if(code == sf::Keyboard::Escape)
// {
// window.close();
// window.create(sf::VideoMode(800,450),"Car Shooter", sf::Style::Default);
// setWindowView(window, windowLength);
// }
// if(code == sf::Keyboard::F11)
// {
// window.close();
// window.create(sf::VideoMode(400,400),"Car Shooter", sf::Style::Fullscreen);
// setWindowView(window, windowLength);
// }
}