-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
63 lines (51 loc) · 1.27 KB
/
main.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
#include <SFML/System.hpp>
#include <SFML/Window.hpp>
#include <SFML/Graphics.hpp>
#include <SFML/Audio.hpp>
#include "actor.h"
#include "map.h"
#include "enums.h"
#include <iostream>
using namespace sf;
int main(int argc, char **argv)
{
RenderWindow window(VideoMode(928, 640, 32), "Sokoban game");
int currLevel =0;
if(argc>1){
currLevel=atoi(argv[1]);
}
std::cout<< currLevel << std::endl;
Actor actor;
Map map(currLevel);
while(window.IsOpened())
{
// handling events in cycle
Event event;
while(window.GetEvent(event))
{
// This game can be closed with escape button too
if(event.Type == Event::Closed || (event.Type == Event::KeyPressed && event.Key.Code == Key::Escape)){
window.Close();
}
// Handle player movements
if(event.Type == Event::KeyPressed && event.Key.Code == Key::Left){
actor.move(Left, &map);
}
if(event.Type == Event::KeyPressed && event.Key.Code == Key::Up){
actor.move(Up, &map);
}
if(event.Type == Event::KeyPressed && event.Key.Code == Key::Right){
actor.move(Right, &map);
}
if(event.Type == Event::KeyPressed && event.Key.Code == Key::Down){
actor.move(Down, &map);
}
}
//Clearing window
window.Clear();
map.draw(&window);
// Drawing
window.Display();
}
return 0;
}