Super Derpy: Muffin Attack
 All Classes Files Functions Variables Enumerations Macros
main.h
Go to the documentation of this file.
1 
6 /*
7  * Copyright (c) Sebastian Krzyszkowiak <dos@dosowisko.net>
8  *
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, write to the Free Software
21  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
22  */
23 #ifndef MAIN_H
24 #define MAIN_H
25 
26 #include <allegro5/allegro.h>
27 #include <allegro5/allegro_audio.h>
28 #include <allegro5/allegro_acodec.h>
29 #include <allegro5/allegro_image.h>
30 #include <allegro5/allegro_font.h>
31 #include <allegro5/allegro_ttf.h>
32 #include "allegro_utils.h"
33 
37 #define PROGRESS_INIT(a) float load_p = 0, load_a = a;
38 
39 #define PROGRESS if (progress) (*progress)(game, load_p+=1/load_a);
40 
41 struct Game;
42 
45  GAMESTATE_PAUSE,
46  GAMESTATE_LOADING,
47  GAMESTATE_MENU,
48  GAMESTATE_ABOUT,
49  GAMESTATE_INTRO,
50  GAMESTATE_MAP,
51  GAMESTATE_LEVEL,
52  GAMESTATE_DISCLAIMER
53 };
54 
56 struct Moonwalk {
57  ALLEGRO_BITMAP *fade_bitmap;
58  ALLEGRO_BITMAP *image;
61  double derpy_pos;
62 };
63 
65 struct Obstacle {
66  ALLEGRO_BITMAP **bitmap;
67  float x;
68  float y;
69  float speed;
70  float angle;
71  int points;
72  bool hit;
74  int cols;
75  int rows;
76  int pos;
77  int blanks;
78  float tmp_pos;
79  float anim_speed;
81  void (*callback)(struct Game*, struct Obstacle*);
82  void *data;
83  struct Obstacle *prev;
84  struct Obstacle *next;
85 };
86 
88 struct Spritesheet {
89  char* name;
90  ALLEGRO_BITMAP* bitmap;
91  int rows;
92  int cols;
93  int blanks;
94  float speed;
95  float aspect;
96  float scale;
97  struct Spritesheet* next;
98 };
99 
101 struct Level {
103  float speed;
105  float bg_pos;
106  float st_pos;
107  float fg_pos;
108  float cl_pos;
109  float derpy_x;
110  float derpy_y;
111  float derpy_angle;
112  float hp;
114  bool failed;
115  float meter_alpha;
118  int sheet_pos;
120  float sheet_tmp;
121  float sheet_speed;
123  float sheet_scale;
124  ALLEGRO_FONT *letter_font;
125  ALLEGRO_SAMPLE *sample;
126  ALLEGRO_SAMPLE_INSTANCE *music;
127  unsigned int music_pos;
128  ALLEGRO_BITMAP *owl;
129  ALLEGRO_BITMAP *background;
130  ALLEGRO_BITMAP *stage;
131  ALLEGRO_BITMAP *foreground;
132  ALLEGRO_BITMAP *clouds;
133  ALLEGRO_BITMAP *welcome;
134  ALLEGRO_BITMAP **derpy_sheet;
135  ALLEGRO_BITMAP *derpy;
136  ALLEGRO_BITMAP *meter_bmp;
137  ALLEGRO_BITMAP *meter_image;
138  ALLEGRO_BITMAP *letter;
142  struct {
143  ALLEGRO_BITMAP *pie1;
144  ALLEGRO_BITMAP *pie2;
145  ALLEGRO_BITMAP *muffin;
146  ALLEGRO_BITMAP *badmuffin;
147  ALLEGRO_BITMAP *cherry;
148  ALLEGRO_BITMAP *pig;
149  ALLEGRO_BITMAP *screwball;
150  } obst_bmps;
151  struct Obstacle *obstacles;
153 };
154 
157  MENUSTATE_MAIN,
158  MENUSTATE_OPTIONS,
159  MENUSTATE_CONTROLS,
160  MENUSTATE_VIDEO,
161  MENUSTATE_PAUSE,
162  MENUSTATE_AUDIO
163 };
164 
166 struct Menu {
167  ALLEGRO_BITMAP *menu_fade_bitmap;
168  ALLEGRO_BITMAP *image;
169  ALLEGRO_BITMAP *cloud;
170  ALLEGRO_BITMAP *cloud2;
171  ALLEGRO_BITMAP *pie;
172  ALLEGRO_BITMAP *pie_bitmap;
173  ALLEGRO_BITMAP *pinkcloud_bitmap;
174  ALLEGRO_BITMAP *pinkcloud;
175  ALLEGRO_BITMAP *rain;
176  ALLEGRO_BITMAP *rain_bitmap;
177  ALLEGRO_BITMAP *mountain;
178  ALLEGRO_BITMAP *logo;
179  ALLEGRO_BITMAP *logoblur;
180  ALLEGRO_BITMAP *glass;
181  ALLEGRO_BITMAP *blurbg;
182  ALLEGRO_BITMAP *blurbg2;
186  ALLEGRO_SAMPLE *sample;
187  ALLEGRO_SAMPLE *rain_sample;
188  ALLEGRO_SAMPLE *click_sample;
189  ALLEGRO_SAMPLE_INSTANCE *music;
190  ALLEGRO_SAMPLE_INSTANCE *rain_sound;
191  ALLEGRO_SAMPLE_INSTANCE *click;
192  ALLEGRO_FONT *font_title;
193  ALLEGRO_FONT *font_subtitle;
194  ALLEGRO_FONT *font;
195  ALLEGRO_FONT *font_selected;
196  int selected;
198  bool loaded;
199  struct {
200  bool fullscreen;
201  int fps;
202  int width;
203  int height;
204  } options;
205 };
206 
208 struct Loading {
209  ALLEGRO_BITMAP *loading_bitmap;
210  ALLEGRO_BITMAP *image;
211 };
212 
214 struct Pause {
215  ALLEGRO_BITMAP *bitmap;
216  ALLEGRO_BITMAP *derpy;
217 };
218 
220 struct About {
221  ALLEGRO_BITMAP *fade_bitmap;
222  ALLEGRO_BITMAP *image;
223  ALLEGRO_BITMAP *text_bitmap;
224  ALLEGRO_BITMAP *letter;
225  ALLEGRO_SAMPLE *sample;
226  ALLEGRO_SAMPLE_INSTANCE *music;
227  ALLEGRO_FONT *font;
228  float x;
229  int fadeloop;
230 };
231 
233 struct Map {
234  ALLEGRO_BITMAP *map;
235  ALLEGRO_BITMAP *map_bg;
236  ALLEGRO_BITMAP *highlight;
237  ALLEGRO_BITMAP *arrow;
238  int selected;
239  int available;
240  float arrowpos;
241  ALLEGRO_SAMPLE *sample;
242  ALLEGRO_SAMPLE *click_sample;
243  ALLEGRO_SAMPLE_INSTANCE *music;
244  ALLEGRO_SAMPLE_INSTANCE *click;
245 };
246 
248 struct Intro {
249  int position;
250  int page;
252  float anim;
253  ALLEGRO_BITMAP *table;
254  ALLEGRO_BITMAP *table_bitmap;
255  ALLEGRO_BITMAP *frame;
256  ALLEGRO_BITMAP *animsprites[5];
257  ALLEGRO_FONT *font;
258  ALLEGRO_SAMPLE *sample;
259  ALLEGRO_SAMPLE_INSTANCE *music;
260  ALLEGRO_AUDIO_STREAM *audiostream;
261 };
262 
264 struct Game {
265  ALLEGRO_DISPLAY *display;
266  ALLEGRO_FONT *font;
267  ALLEGRO_FONT *font_console;
270  ALLEGRO_EVENT_QUEUE *event_queue;
271  ALLEGRO_TIMER *timer;
272  ALLEGRO_BITMAP *console;
273  bool showconsole;
274  int fx;
275  int music;
276  int voice;
277  bool fullscreen;
278  bool debug;
279  int fps;
280  int width;
281  int height;
283  bool restart;
284  struct Menu menu;
285  struct Loading loading;
286  struct Intro intro;
287  struct About about;
288  struct Map map;
289  struct Level level;
290  struct Pause pause;
291  struct {
292  ALLEGRO_VOICE *v;
293  ALLEGRO_MIXER *mixer;
294  ALLEGRO_MIXER *music;
295  ALLEGRO_MIXER *voice;
296  ALLEGRO_MIXER *fx;
297  } audio;
298 };
299 
301 void PreloadGameState(struct Game *game, void (*progress)(struct Game*, float));
302 
304 void UnloadGameState(struct Game *game);
305 
307 void LoadGameState(struct Game *game);
308 
315 void PrintConsole(struct Game *game, char* format, ...);
316 
318 void DrawConsole(struct Game *game);
319 
321 ALLEGRO_BITMAP* LoadScaledBitmap(char* filename, int width, int height);
322 
324 float tps(struct Game *game, float t);
325 
327 void DrawGameState(struct Game *game);
328 
330 int Shared_Load(struct Game *game);
331 
333 void Shared_Unload(struct Game *game);
334 
335 #endif