1 /*
2  * Copyright (C) 2011-2013 Me and My Shadow
3  *
4  * This file is part of Me and My Shadow.
5  *
6  * Me and My Shadow is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * Me and My Shadow is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with Me and My Shadow.  If not, see <http://www.gnu.org/licenses/>.
18  */
19 
20 #ifndef GLOBALS_H
21 #define GLOBALS_H
22 
23 #include <SDL.h>
24 #include <string>
25 #include "libs/tinygettext/tinygettext.hpp"
26 #include "LevelPack.h"
27 #include "Render.h"
28 
29 #if defined (WIN32) || defined (__APPLE__)
30 //#define DATA_PATH
31 #else
32 #include "config.h"
33 #endif
34 
35 #define TITLE_FONT_RAISE 19
36 #define GUI_FONT_RAISE 5
37 
38 class GameState;
39 
40 //Global constants
41 //The width of the screen.
42 extern int SCREEN_WIDTH;
43 //The height of the screen.
44 extern int SCREEN_HEIGHT;
45 //The depth of the screen.
46 #if defined(ANDROID)
47 //TODO: change other surface creating code to make the game runs faster
48 const int SCREEN_BPP=16; //??? 24?? 32??
49 //const int SCREEN_FLAGS=SDL_HWSURFACE;
50 #else
51 const int SCREEN_BPP=32;
52 //const int SCREEN_FLAGS=SDL_HWSURFACE;
53 #endif
54 const int SCREEN_FLAGS = 0;
55 
56 //SDL interprets each pixel as a 32-bit number,
57 // so our masks must depend on the endianness (byte order) of the machine.
58 //NOTE: We define them here so we only have to do it once.
59 /*#if SDL_BYTEORDER == SDL_BIG_ENDIAN
60 const Uint32 BMASK=0xFF000000;
61 const Uint32 GMASK=0x00FF0000;
62 const Uint32 RMASK=0x0000FF00;
63 const Uint32 AMASK=0x000000FF;
64 #else*/
65 // NOTE: Changed to ARGB for SDL2.
66 const Uint32 BMASK=0x000000FF;
67 const Uint32 GMASK=0x0000FF00;
68 const Uint32 RMASK=0x00FF0000;
69 const Uint32 AMASK=0xFF000000;
70 /*#endif*/
71 
72 //String containing the version, used in the titelbar.
73 //NOTE: for development version please write something like "V0.5 Development version"
74 //which can trigger the corresponding achievement.
75 const std::string version = "V0.5a";
76 
77 //The height of the current level.
78 extern int LEVEL_HEIGHT;
79 //The width of the current level.
80 extern int LEVEL_WIDTH;
81 
82 //The target frames per seconds.
83 const int FPS=40;
84 
85 //The language that in which the game should be translated.
86 extern std::string language;
87 //The DictionaryManager that is used to translate the game itself.
88 extern tinygettext::DictionaryManager* dictionaryManager;
89 
90 //SDL Window and renderer
91 extern SDL_Window* sdlWindow;
92 
93 //Font that is used for titles.
94 //Knewave large.
95 extern TTF_Font* fontTitle;
96 //Font that is used for captions of buttons and other GUI elements.
97 //Knewave small.
98 extern TTF_Font* fontGUI;
99 //Font that is used for long captions of buttons and other GUI elements.
100 //Knewave smaller.
101 extern TTF_Font* fontGUISmall;
102 //Font that is used for (long) text.
103 //Blokletter-Viltstift small.
104 extern TTF_Font* fontText;
105 //Font used for scripting editor.
106 //Monospace.
107 extern TTF_Font* fontMono;
108 
109 //Small arrows used for GUI widgets.
110 //2 directions and 2 different/same colors depending on theme.
111 extern TexturePtr arrowLeft1;
112 extern TexturePtr arrowRight1;
113 extern TexturePtr arrowLeft2;
114 extern TexturePtr arrowRight2;
115 
116 //Event, used for event handling.
117 extern SDL_Event event;
118 
119 //GUI
120 class GUIObject;
121 extern GUIObject *GUIObjectRoot;
122 
123 //The state id of the current state.
124 extern int stateID;
125 //Integer containing what the next state will be.
126 extern int nextState;
127 //The currentState.
128 extern GameState* currentState;
129 
130 //Pointer to the current levelpack.
131 extern LevelPack* levels;
132 //String containing the name of the current level.
133 extern std::string levelName;
134 
135 //SDL rectangle used to store the camera.
136 //x is the x location of the camera.
137 //y is the y location of the camera.
138 //w is the width of the camera. (equal to SCREEN_WIDTH)
139 //h is the height of the camera. (equal to SCREEN_HEIGHT)
140 extern SDL_Rect camera;
141 
142 //Themable colors
143 const SDL_Color BLACK = SDL_Color{0,0,0,255};
144 
145 //Enumeration containing the different cursor types there are.
146 enum CursorType{
147 	//The default pointer.
148 	CURSOR_POINTER,
149 
150 	//The vertical ibeam, used to indicate text input.
151 	CURSOR_CARROT,
152 
153 	//A closed hand, used for indicating a drag action.
154 	CURSOR_DRAG,
155 
156 	//The different (window) size cursor icons.
157 	CURSOR_SIZE_HOR,
158 	CURSOR_SIZE_VER,
159 	CURSOR_SIZE_FDIAG,
160 	CURSOR_SIZE_BDIAG,
161 
162 	//Remove cursor used in level editor
163 	CURSOR_REMOVE,
164 
165 	//Pointing hand cursor, for hyperlinks.
166 	CURSOR_POINTING_HAND,
167 
168 	//The number of cursor types there are.
169 	CURSOR_MAX
170 };
171 //Currently used cursor type.
172 extern CursorType currentCursor;
173 //Array containing the SDL_Cursors.
174 extern SDL_Cursor* cursors[CURSOR_MAX];
175 
176 //Enumeration containing the ids of the game states.
177 enum GameStates{
178 	//State null is a special state used to indicate no state.
179 	//This is used when no next state is defined.
180 	STATE_NULL,
181 
182 	//This state is before the actual leveleditor used to make levelpacks.
183 	STATE_LEVEL_EDIT_SELECT,
184 	//This state is for the level editor.
185 	STATE_LEVEL_EDITOR,
186 	//This state is for the main menu.
187 	STATE_MENU,
188 	//This state is for the actual game.
189 	STATE_GAME,
190 	//Special state used when exiting meandmyshadow.
191 
192 	STATE_EXIT,
193 	//This state is for the help screen.
194 
195 	STATE_LEVEL_SELECT,
196 	//This state is for the options screen.
197 	STATE_OPTIONS,
198 	//This state is for the addon screen.
199 	STATE_ADDONS,
200 	//This state is for credits screen
201 	STATE_CREDITS,
202 	//This state is for statistics screen
203 	STATE_STATISTICS,
204 };
205 
206 //Enumeration containing the ids of the different block types.
207 enum GameTileType{
208 	//The normal solid block.
209 	TYPE_BLOCK=0,
210 	//Block representing the start location of the player.
211 	TYPE_START_PLAYER,
212 	//Block representing the start location of the shadow.
213 	TYPE_START_SHADOW,
214 	//The exit of the level.
215 	TYPE_EXIT,
216 	//The shadow block which is only solid for the shadow.
217 	TYPE_SHADOW_BLOCK,
218 	//Block that can kill both the player and the shadow.
219 	TYPE_SPIKES,
220 
221 	//Special point where the player can save.
222 	TYPE_CHECKPOINT,
223 	//Block that will switch the location of the player and the shadow when invoked.
224 	TYPE_SWAP,
225 	//Block that will crumble to dust when stepped on it for the third time.
226 	TYPE_FRAGILE,
227 
228 	//Normal block that moves along a path.
229 	TYPE_MOVING_BLOCK,
230 	//Shadow block that moves along a path.
231 	TYPE_MOVING_SHADOW_BLOCK,
232 	//A spike block that moves along a path.
233 	TYPE_MOVING_SPIKES,
234 
235 	//Special block which, once entered, moves the player/shadow to a different portal.
236 	TYPE_PORTAL,
237 	//A block with a button which can activate or stop moving blocks, converyor belts
238 	TYPE_BUTTON,
239 	//A switch which can activate or stop moving blocks, converyor belts
240 	TYPE_SWITCH,
241 
242 	//Solid block which works like
243 	TYPE_CONVEYOR_BELT,
244 	TYPE_SHADOW_CONVEYOR_BELT,
245 
246 	//Block that contains a message that can be read.
247 	TYPE_NOTIFICATION_BLOCK,
248 
249 	//A collectable that is able to open locked doors
250 	TYPE_COLLECTABLE,
251 
252 	//Block that can be pushed by the player and the shadow.
253 	//Pushable blocks can push other pushable blocks.
254 	TYPE_PUSHABLE,
255 
256 	//The (max) number of tiles.
257 	TYPE_MAX
258 };
259 
260 //Keyboard only mode. This is set to true if the last menu navigation is performed by keyboard.
261 extern bool isKeyboardOnly;
262 
263 #endif
264