-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
64 lines (54 loc) · 1.83 KB
/
main.cpp
File metadata and controls
64 lines (54 loc) · 1.83 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
52
53
54
55
56
57
58
59
60
61
62
63
64
#include <SFML/Graphics.hpp>
//#include <iostream>
//#include <sstream>
#include "TextureManager.hpp"
#include "PhysicEngine.hpp"
#include "TileMap.hpp"
#include "Player.hpp"
#include "Key.hpp"
#include "AnimatedSprite.hpp"
int main()
{
bool hasFocus(true);
PhysicEngine* eng(PhysicEngine::getInstance());
Player myPlayer;
Key myKey;
sf::Image tileChart, tiles, compressedMapImage;
tileChart.loadFromFile("TileChart.png");
tiles.loadFromFile("Tiles.png");
compressedMapImage.loadFromFile("Map.png");
TileMap myMap;
myMap.buildTileMap(tileChart, tiles, compressedMapImage);
sf::RenderWindow window(sf::VideoMode(1366, 768), "Unnamed Colorful Game", sf::Style::Fullscreen);
//window.setFramerateLimit(240.f);
sf::View myView(window.getDefaultView());
sf::Clock clock;
while(window.isOpen()&&hasFocus&&!myPlayer.isDead())
{
sf::Event event;
while (window.pollEvent(event))
{
if (event.type == sf::Event::GainedFocus)
hasFocus=true;
else if (event.type == sf::Event::LostFocus)
hasFocus==false;
else if (event.type == sf::Event::Closed || (event.type == sf::Event::KeyPressed && event.key.code == sf::Keyboard::Escape))
window.close();
else
myPlayer.handleEvent(event);
}
myKey.update(clock.getElapsedTime().asSeconds());
eng->update(clock.restart().asSeconds());
//std::stringstream ss;
//ss<<"Fps: "<<1.f/clock.restart().asSeconds();
//window.setTitle(ss.str());
myView.setCenter(myPlayer.getPosition());
window.setView(myView);
window.clear(sf::Color::Black);
window.draw(myMap);
window.draw(myPlayer);
window.draw(myKey);
window.display();
}
return 0;
}