-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
113 lines (103 loc) · 3.15 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
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
104
105
106
107
108
109
110
111
112
113
#include "SFML/Graphics.hpp"
#include "jeu.h"
#include "menu.h"
#include "timer.h"
#include <iostream>
#include "const.h"
#include <tr1/memory>
#include "son/sound_manager.h"
#include <SFML/Audio.hpp>
using namespace std;
using namespace sf;
RenderWindow app(sf::VideoMode(1024 , 768), "jeu");
/*
TODO LIST
- Projectiles
-menu recommencer
*/
int main()
{
const int SCREEN_WIDTH(1024), SCREEN_HEIGHT(768), MAX_MENU(3);
app.UseVerticalSync(true);
app.SetFramerateLimit(60);
int stateLevel, score(0);
//Gestionnaire d'images
image_manager *imageManager;
imageManager = image_manager::getInstance();
imageManager->addResourceDirectory("images/" );
Menu menu;
Jeu jeu(SCREEN_WIDTH, SCREEN_HEIGHT, menu);
Timer timer;
int select(1);
Event Event;
sf::SoundBuffer buffer;
sf:: Sound sound;
buffer = sound_manager::getInstance()->getBuffer("son/clic.ogg");
sound.SetBuffer(buffer);
sound.SetLoop(false);
sound.SetPitch(1.f);
sound.SetVolume(50.f);
//Gestion du highlight du menu avec un système de points
while (app.IsOpened())
{
app.Clear();
while(app.GetEvent(Event))
{
if (Event.Type == sf::Event::Closed)
app.Close();/*
if((Event.Type == sf::Event::KeyPressed) && (Event.Key.Code == sf::Key::Escape))
{
app.Close();
}*/
if((Event.Type == sf::Event::KeyPressed) && (Event.Key.Code == sf::Key::Down || Event.Key.Code == sf::Key::Right))
{
sound.Play();
if(select == MAX_MENU)
select +=0;
else
select +=1;
}
if((Event.Type == sf::Event::KeyPressed) && (Event.Key.Code == sf::Key::Up || Event.Key.Code == sf::Key::Left))
{
sound.Play();
if(select == 1)
select -=0;
else
select -=1;
}
//Action à effectuer quand on appuie ur entrée : dépend du nombre de points
if((Event.Type == sf::Event::KeyPressed) && (Event.Key.Code == sf::Key::Num1))
{
sound.Play();
switch(select)
{
case 1:
{
if(Level_manager::getInstance()->endOfGame())
{
Level_manager::getInstance()->setLevelNumber(1);
menu.setLevel(1);
}
stateLevel = jeu.start(menu.getLevel());
break;
}
case 2:
{
if(menu.getLevel() > 1)
stateLevel = jeu.start(menu.getLevel()-1);
break;
}
case 3:
{
break;
}
}
}
}
score = jeu.getTotalScore();
menu.drawMainMenu(select, score);
app.Display();
timer.sleep(1);
}
return 0;
}