1 /*
2     FreeBlocks -  A simple puzzle game, similar to Tetris Attack
3     Copyright (C) 2012 Justin Jacobs
4 
5     This program is free software: you can redistribute it and/or modify
6     it under the terms of the GNU General Public License as published by
7     the Free Software Foundation, either version 3 of the License, or
8     (at your option) any later version.
9 
10     This program is distributed in the hope that it will be useful,
11     but WITHOUT ANY WARRANTY; without even the implied warranty of
12     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13     GNU General Public License for more details.
14 
15     You should have received a copy of the GNU General Public License
16     along with this program.  If not, see <http://www.gnu.org/licenses/>.
17 */
18 
19 #ifndef SYS_H
20 #define SYS_H
21 
22 #include <SDL.h>
23 #include <SDL_ttf.h>
24 #include <SDL_mixer.h>
25 
26 #include "dork/dork_string.h"
27 
28 typedef enum { false = 0, true = 1 } bool;
29 
30 #define GAME_MODE_DEFAULT 0
31 #define GAME_MODE_JEWELS 1
32 
33 #ifdef __GCW0__
34 #define HALF_GFX
35 #define SCREEN_BPP 16
36 #else
37 #define SCREEN_BPP 32
38 #endif
39 
40 #ifdef HALF_GFX
41 #define SCREEN_WIDTH 320
42 #define SCREEN_HEIGHT 240
43 #define GFX_PREFIX "/graphics/320x240/"
44 #define FONT_SIZE 12
45 #else
46 #define SCREEN_WIDTH 640
47 #define SCREEN_HEIGHT 480
48 #define GFX_PREFIX "/graphics/"
49 #define FONT_SIZE 24
50 #endif
51 
52 #define FPS 30
53 #define JOY_DEADZONE 100
54 #define ACTION_COOLDOWN 10 / (60/FPS)
55 
56 #define OPTIONS_MAIN 0
57 #define OPTIONS_CONTROLS 1
58 #define OPTIONS_REBIND 2
59 
60 #ifndef PKGDATADIR
61 #define PKGDATADIR "./res"
62 #endif
63 
64 #ifdef _MSC_VER
65 #define HOME_DIR_ENV "AppData"
66 #else
67 #define HOME_DIR_ENV "HOME"
68 #endif
69 
70 #ifdef _MSC_VER
71 #define MKDIR_MODE 0
72 #define mkdir(p, a) _mkdir(p)
73 #else
74 #define MKDIR_MODE (S_IRWXU | S_IRWXG | S_IRWXO)
75 #endif
76 
77 #ifdef _MSC_VER
78 #include <direct.h>
79 #define mkdir(p, a) _mkdir(p)
80 #elif defined(_WIN32)
81 #define mkdir(p, a) mkdir(p)
82 #endif
83 
84 #ifdef _MSC_VER
85 #define stat _stat
86 #endif
87 
88 enum KEYBINDS {
89     KEY_SWITCH = 0,
90     KEY_BUMP = 1,
91     KEY_ACCEPT = 2,
92     KEY_PAUSE = 3,
93     KEY_EXIT = 4,
94     KEY_LEFT = 5,
95     KEY_RIGHT = 6,
96     KEY_UP = 7,
97     KEY_DOWN = 8
98 };
99 
100 extern const char* const key_desc[];
101 
102 extern SDL_Surface* screen;
103 extern TTF_Font* font;
104 
105 extern int score;
106 extern int high_scores[10];
107 extern bool title_screen;
108 extern bool high_scores_screen;
109 extern int options_screen;
110 extern bool game_over;
111 extern bool paused;
112 extern bool quit;
113 extern int game_mode;
114 
115 struct Cursor {
116     int x1;
117     int y1;
118     int x2;
119     int y2;
120 };
121 extern struct Cursor cursor;
122 
123 extern int action_cooldown;
124 typedef enum {
125     ACTION_NONE, ACTION_LEFT, ACTION_RIGHT, ACTION_UP, ACTION_DOWN
126 }ActionMove;
127 extern ActionMove action_move;
128 extern ActionMove action_last_move;
129 extern bool action_switch;
130 extern bool action_bump;
131 extern bool action_accept;
132 extern bool action_pause;
133 extern bool action_exit;
134 
135 extern Dork_String path_dir_config;
136 extern Dork_String path_file_config;
137 extern Dork_String path_file_highscores;
138 extern Dork_String path_file_highscores_jewels;
139 
140 extern int option_joystick;
141 extern int option_sound;
142 extern int option_music;
143 extern int option_fullscreen;
144 
145 extern SDLKey option_key[9];
146 extern int option_joy_button[5];
147 extern int option_joy_axis_x;
148 extern int option_joy_axis_y;
149 
150 extern SDLKey last_key;
151 extern int last_joy_button;
152 
153 extern SDL_Event event;
154 
155 // Timers
156 extern unsigned int startTimer;
157 extern unsigned int endTimer;
158 extern unsigned int deltaTimer;
159 
160 // Functions
161 bool sysInit();
162 char* sysGetFilePath(Dork_String *dest, const char* path, bool is_gfx);
163 bool sysLoadImage(SDL_Surface** dest, const char* path);
164 bool sysLoadFont(TTF_Font** dest, const char* path, int font_size);
165 bool sysLoadMusic(Mix_Music** dest, const char* path);
166 bool sysLoadSound(Mix_Chunk** dest, const char* path);
167 bool sysLoadFiles();
168 void sysCleanup();
169 void sysInput();
170 void sysInputReset();
171 void sysConfigSetPaths();
172 void sysConfigLoad();
173 void sysConfigSave();
174 void sysConfigApply();
175 void sysHighScoresLoad();
176 void sysHighScoresSave();
177 void sysHighScoresClear();
178 
179 // Images
180 extern SDL_Surface* surface_blocks;
181 extern SDL_Surface* surface_clear;
182 extern SDL_Surface* surface_cursor;
183 extern SDL_Surface* surface_cursor_highlight;
184 extern SDL_Surface* surface_bar;
185 extern SDL_Surface* surface_bar_inactive;
186 extern SDL_Surface* surface_background;
187 extern SDL_Surface* surface_background_jewels;
188 extern SDL_Surface* surface_title;
189 extern SDL_Surface* surface_highscores;
190 
191 // Music and Sounds
192 extern Mix_Music* music;
193 extern Mix_Music* music_jewels;
194 extern Mix_Chunk* sound_menu;
195 extern Mix_Chunk* sound_switch;
196 extern Mix_Chunk* sound_match;
197 extern Mix_Chunk* sound_drop;
198 
199 // Joystick
200 extern SDL_Joystick* joy;
201 
202 #endif
203