]> git.jsancho.org Git - lugaru.git/blob - Source/Game.cpp
Moved Account::active in Account class. Maybe it should be changed for a method and...
[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 "Game.h"
22 #include "openal_wrapper.h"
23 #include "SDL_thread.h"
24 #include "Dialog.h"
25
26 extern int mainmenu;
27
28 const char *pathtypenames[] = {"keepwalking", "pause"};
29 const char *editortypenames[] = {
30     "active", "sitting", "sitting wall", "sleeping",
31     "dead1", "dead2", "dead3", "dead4"
32 };
33
34 namespace Game
35 {
36 Texture terraintexture;
37 Texture terraintexture2;
38 Texture loadscreentexture;
39 Texture Maparrowtexture;
40 Texture Mapboxtexture;
41 Texture Mapcircletexture;
42 Texture cursortexture;
43 GLuint screentexture = 0;
44 GLuint screentexture2 = 0;
45 Texture Mainmenuitems[10];
46
47 int selected = 0;
48 int keyselect = 0;
49
50 int newdetail = 0;
51 int newscreenwidth = 0;
52 int newscreenheight = 0;
53
54 bool gameon = 0;
55 float deltah = 0;
56 float deltav = 0;
57 int mousecoordh = 0;
58 int mousecoordv = 0;
59 int oldmousecoordh = 0;
60 int oldmousecoordv = 0;
61 float yaw = 0;
62 float pitch = 0;
63 SkyBox *skybox = NULL;
64 bool cameramode = 0;
65 bool firstload = 0;
66
67 Texture hawktexture;
68 float hawkyaw = 0;
69 float hawkcalldelay = 0;
70
71 float leveltime = 0;
72 float wonleveltime = 0;
73 float loadtime = 0;
74
75 Model hawk;
76 XYZ hawkcoords;
77 XYZ realhawkcoords;
78
79 Model eye;
80 Model iris;
81 Model cornea;
82
83 bool stealthloading = 0;
84
85 int musictype = 0;
86
87 XYZ mapcenter;
88 float mapradius = 0;
89
90 Text *text = NULL;
91 float fps = 0;
92
93 bool editorenabled = 0;
94 int editortype = 0;
95 float editorsize = 0;
96 float editoryaw = 0;
97 float editorpitch = 0;
98
99 int tryquit = 0;
100
101 XYZ pathpoint[30];
102 int numpathpoints = 0;
103 int numpathpointconnect[30] = {};
104 int pathpointconnect[30][30] = {};
105 int pathpointselected = 0;
106
107 int endgame = 0;
108 bool scoreadded = 0;
109 int numchallengelevels = 0;
110
111 bool console = false;
112 std::string consoletext[15] = {};
113 std::string displaytext[15] = {};
114 float displaytime[15] = {};
115 float displayblinkdelay = 0;
116 bool displayblink = 0;
117 unsigned displayselected = 0;
118 float consoleblinkdelay = 0;
119 bool consoleblink = 0;
120 unsigned consoleselected = 0;
121
122 unsigned short crouchkey = 0, jumpkey = 0, forwardkey = 0, backkey = 0, leftkey = 0, rightkey = 0, drawkey = 0, throwkey = 0, attackkey = 0;
123 unsigned short consolekey = 0;
124
125 int loading = 0;
126
127 int oldenvironment = 0;
128 int targetlevel = 0;
129 float changedelay = 0;
130
131 bool waiting = false;
132 }
133
134 void Game::fireSound(int sound)
135 {
136     emit_sound_at(sound);
137 }
138
139 void Game::inputText(string& str, unsigned* charselected)
140 {
141     SDL_Event evenement;
142
143     if (!waiting) {
144         SDL_StartTextInput();
145         waiting = true;
146     }
147
148     while (SDL_PollEvent(&evenement)) {
149         if (!sdlEventProc(evenement)) {
150             tryquit = 1;
151             break;
152         }
153         switch (evenement.type) {
154         case SDL_TEXTEDITING:
155             /* FIXME - We should handle this for complete input method support */
156             break;
157         case SDL_TEXTINPUT:
158             str.insert(*charselected, evenement.text.text);
159             (*charselected) += strlen(evenement.text.text);
160             break;
161         case SDL_KEYDOWN:
162             if (evenement.key.keysym.sym == SDLK_ESCAPE) {
163                 str.clear();
164                 *charselected = 0;
165                 waiting = false;
166             } else if (evenement.key.keysym.sym == SDLK_BACKSPACE) {
167                 if ((*charselected) > 0) {
168                     (*charselected)--;
169                     str.erase(*charselected, 1);
170                 }
171             } else if (evenement.key.keysym.sym == SDLK_DELETE) {
172                 if ((*charselected) < str.size()) {
173                     str.erase(*charselected, 1);
174                 }
175             } else if (evenement.key.keysym.sym == SDLK_HOME) {
176                 (*charselected) = 0;
177             } else if (evenement.key.keysym.sym == SDLK_END) {
178                 (*charselected) = str.size();
179             } else if (evenement.key.keysym.sym == SDLK_LEFT) {
180                 if ((*charselected) != 0)
181                     (*charselected)--;
182             } else if (evenement.key.keysym.sym == SDLK_RIGHT) {
183                 if ((*charselected) < str.size())
184                     (*charselected)++;
185             } else if (evenement.key.keysym.sym == SDLK_RETURN) {
186                 waiting = false;
187             }
188             break;
189         }
190     }
191
192     if (!waiting) {
193         SDL_StopTextInput();
194     }
195 }