]> git.jsancho.org Git - lugaru.git/blob - Source/Game.cpp
Sorted all source files in folders
[lugaru.git] / Source / Game.cpp
1 /*
2 Copyright (C) 2003, 2010 - Wolfire Games
3 Copyright (C) 2010-2016 - Lugaru contributors (see AUTHORS file)
4
5 This file is part of Lugaru.
6
7 Lugaru is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
11
12 Lugaru is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with Lugaru.  If not, see <http://www.gnu.org/licenses/>.
19 */
20
21 #include "SDL_thread.h"
22 #include "Game.h"
23 #include "Audio/openal_wrapper.h"
24 #include "Level/Dialog.h"
25
26
27 extern int mainmenu;
28
29 const char *pathtypenames[] = {"keepwalking", "pause"};
30 const char *editortypenames[] = {
31     "active", "sitting", "sitting wall", "sleeping",
32     "dead1", "dead2", "dead3", "dead4"
33 };
34
35 namespace Game
36 {
37 Texture terraintexture;
38 Texture terraintexture2;
39 Texture loadscreentexture;
40 Texture Maparrowtexture;
41 Texture Mapboxtexture;
42 Texture Mapcircletexture;
43 Texture cursortexture;
44 GLuint screentexture = 0;
45 GLuint screentexture2 = 0;
46 Texture Mainmenuitems[10];
47
48 int selected = 0;
49 int keyselect = 0;
50
51 int newdetail = 0;
52 int newscreenwidth = 0;
53 int newscreenheight = 0;
54
55 bool gameon = 0;
56 float deltah = 0;
57 float deltav = 0;
58 int mousecoordh = 0;
59 int mousecoordv = 0;
60 int oldmousecoordh = 0;
61 int oldmousecoordv = 0;
62 float yaw = 0;
63 float pitch = 0;
64 SkyBox *skybox = NULL;
65 bool cameramode = 0;
66 bool firstload = 0;
67
68 Texture hawktexture;
69 float hawkyaw = 0;
70 float hawkcalldelay = 0;
71
72 float leveltime = 0;
73 float wonleveltime = 0;
74 float loadtime = 0;
75
76 Model hawk;
77 XYZ hawkcoords;
78 XYZ realhawkcoords;
79
80 Model eye;
81 Model iris;
82 Model cornea;
83
84 bool stealthloading = 0;
85
86 int musictype = 0;
87
88 XYZ mapcenter;
89 float mapradius = 0;
90
91 Text *text = NULL;
92 float fps = 0;
93
94 bool editorenabled = 0;
95 int editortype = 0;
96 float editorsize = 0;
97 float editoryaw = 0;
98 float editorpitch = 0;
99
100 int tryquit = 0;
101
102 XYZ pathpoint[30];
103 int numpathpoints = 0;
104 int numpathpointconnect[30] = {};
105 int pathpointconnect[30][30] = {};
106 int pathpointselected = 0;
107
108 int endgame = 0;
109 bool scoreadded = 0;
110 int numchallengelevels = 0;
111
112 bool console = false;
113 std::string consoletext[15] = {};
114 std::string displaytext[15] = {};
115 float displaytime[15] = {};
116 float displayblinkdelay = 0;
117 bool displayblink = 0;
118 unsigned displayselected = 0;
119 float consoleblinkdelay = 0;
120 bool consoleblink = 0;
121 unsigned consoleselected = 0;
122
123 unsigned short crouchkey = 0, jumpkey = 0, forwardkey = 0, backkey = 0, leftkey = 0, rightkey = 0, drawkey = 0, throwkey = 0, attackkey = 0;
124 unsigned short consolekey = 0;
125
126 int loading = 0;
127
128 int oldenvironment = 0;
129 int targetlevel = 0;
130 float changedelay = 0;
131
132 bool waiting = false;
133 }
134
135 void Game::fireSound(int sound)
136 {
137     emit_sound_at(sound);
138 }
139
140 void Game::inputText(string& str, unsigned* charselected)
141 {
142     SDL_Event evenement;
143
144     if (!waiting) {
145         SDL_StartTextInput();
146         waiting = true;
147     }
148
149     while (SDL_PollEvent(&evenement)) {
150         if (!sdlEventProc(evenement)) {
151             tryquit = 1;
152             break;
153         }
154         switch (evenement.type) {
155         case SDL_TEXTEDITING:
156             /* FIXME - We should handle this for complete input method support */
157             break;
158         case SDL_TEXTINPUT:
159             str.insert(*charselected, evenement.text.text);
160             (*charselected) += strlen(evenement.text.text);
161             break;
162         case SDL_KEYDOWN:
163             if (evenement.key.keysym.sym == SDLK_ESCAPE) {
164                 str.clear();
165                 *charselected = 0;
166                 waiting = false;
167             } else if (evenement.key.keysym.sym == SDLK_BACKSPACE) {
168                 if ((*charselected) > 0) {
169                     (*charselected)--;
170                     str.erase(*charselected, 1);
171                 }
172             } else if (evenement.key.keysym.sym == SDLK_DELETE) {
173                 if ((*charselected) < str.size()) {
174                     str.erase(*charselected, 1);
175                 }
176             } else if (evenement.key.keysym.sym == SDLK_HOME) {
177                 (*charselected) = 0;
178             } else if (evenement.key.keysym.sym == SDLK_END) {
179                 (*charselected) = str.size();
180             } else if (evenement.key.keysym.sym == SDLK_LEFT) {
181                 if ((*charselected) != 0)
182                     (*charselected)--;
183             } else if (evenement.key.keysym.sym == SDLK_RIGHT) {
184                 if ((*charselected) < str.size())
185                     (*charselected)++;
186             } else if (evenement.key.keysym.sym == SDLK_RETURN) {
187                 waiting = false;
188             }
189             break;
190         }
191     }
192
193     if (!waiting) {
194         SDL_StopTextInput();
195     }
196 }