forked from fallahn/tmxlite
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
95 lines (73 loc) · 2.6 KB
/
Copy pathmain.cpp
File metadata and controls
95 lines (73 loc) · 2.6 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
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
/*********************************************************************
(c) Matt Marchant & contributors 2016 - 2024
http://trederia.blogspot.com
tmxlite - Zlib license.
This software is provided 'as-is', without any express or
implied warranty. In no event will the authors be held
liable for any damages arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute
it freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented;
you must not claim that you wrote the original software.
If you use this software in a product, an acknowledgment
in the product documentation would be appreciated but
is not required.
2. Altered source versions must be plainly marked as such,
and must not be misrepresented as being the original software.
3. This notice may not be removed or altered from any
source distribution.
*********************************************************************/
#include "SFMLOrthogonalLayer.hpp"
#include <SFML/Graphics/RenderWindow.hpp>
#include <SFML/Window/Event.hpp>
#include <SFML/Window/Keyboard.hpp>
int main()
{
sf::RenderWindow window(sf::VideoMode(800, 600), "SFML window");
tmx::Map map;
map.load("assets/demo.tmx");
MapLayer layerZero(map, 0);
MapLayer layerOne(map, 1);
MapLayer layerTwo(map, 2);
sf::Clock globalClock;
sf::Clock wiggleClock;
bool doWiggle = false;
while (window.isOpen())
{
sf::Event event;
while (window.pollEvent(event))
{
if (event.type == sf::Event::Closed)
{
window.close();
}
else if( event.type == sf::Event::KeyPressed )
{
switch(event.key.code)
{
case sf::Keyboard::W:
// toggle doWiggle
doWiggle = !doWiggle;
break;
}
}
}
sf::Time duration = globalClock.restart();
layerZero.update(duration);
sf::Vector2f newOffset = sf::Vector2f(0.f, 0.f);
if (doWiggle)
{
newOffset = sf::Vector2f(std::cos(wiggleClock.getElapsedTime().asSeconds()) * 100.f, 0.f);
}
layerZero.setOffset(newOffset);
layerOne.setOffset(newOffset);
layerTwo.setOffset(newOffset);
window.clear(sf::Color::Black);
window.draw(layerZero);
window.draw(layerOne);
window.draw(layerTwo);
window.display();
}
return 0;
}