2012-02-28 13:09:12 +01:00
|
|
|
/*! \file main.h
|
|
|
|
* \brief Headers of main file of SuperDerpy engine.
|
|
|
|
*
|
|
|
|
* Contains basic functions shared by all views.
|
|
|
|
*/
|
2012-03-04 13:32:42 +01:00
|
|
|
/*
|
|
|
|
* Copyright (c) Sebastian Krzyszkowiak <dos@dosowisko.net>
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
*/
|
2012-02-16 15:40:58 +01:00
|
|
|
#ifndef MAIN_H
|
|
|
|
#define MAIN_H
|
|
|
|
|
|
|
|
#include <allegro5/allegro.h>
|
|
|
|
#include <allegro5/allegro_audio.h>
|
|
|
|
#include <allegro5/allegro_acodec.h>
|
|
|
|
#include <allegro5/allegro_image.h>
|
|
|
|
#include <allegro5/allegro_font.h>
|
|
|
|
#include <allegro5/allegro_ttf.h>
|
|
|
|
|
2012-02-28 13:09:12 +01:00
|
|
|
/*! \brief Enum of all available gamestates. */
|
2012-02-16 15:40:58 +01:00
|
|
|
enum gamestate_enum {
|
2012-03-02 16:52:13 +01:00
|
|
|
GAMESTATE_PAUSE,
|
2012-02-16 15:40:58 +01:00
|
|
|
GAMESTATE_LOADING,
|
2012-02-17 00:19:21 +01:00
|
|
|
GAMESTATE_MENU,
|
|
|
|
GAMESTATE_ABOUT,
|
2012-02-18 05:53:39 +01:00
|
|
|
GAMESTATE_INTRO,
|
2012-02-21 23:33:02 +01:00
|
|
|
GAMESTATE_MAP,
|
|
|
|
GAMESTATE_LEVEL
|
2012-02-16 15:40:58 +01:00
|
|
|
};
|
|
|
|
|
2012-04-06 17:28:38 +02:00
|
|
|
/*! \brief Resources used by moonwalk level placeholder. */
|
|
|
|
struct Moonwalk {
|
2012-02-28 23:16:55 +01:00
|
|
|
ALLEGRO_BITMAP *fade_bitmap; /*!< Bitmap used on fade-in and fade-out animations. */
|
|
|
|
ALLEGRO_BITMAP *image; /*!< Background texture. */
|
|
|
|
ALLEGRO_SAMPLE *sample; /*!< Sample with background music. */
|
2012-03-02 17:47:02 +01:00
|
|
|
ALLEGRO_SAMPLE_INSTANCE *music; /*!< Sample instance with background music. */
|
|
|
|
unsigned int music_pos; /*!< Position of sample instance. Used when pausing game. */
|
2012-02-28 23:16:55 +01:00
|
|
|
int current_level; /*!< Level number. */
|
|
|
|
int derpy_frame; /*!< Current frame of Derpy animation. */
|
|
|
|
int derpy_frame_tmp; /*!< Counter used to slow down Derpy animation. */
|
|
|
|
double derpy_pos; /*!< Position of Derpy on screen. */
|
2012-02-22 12:43:14 +01:00
|
|
|
};
|
|
|
|
|
2012-04-06 17:28:38 +02:00
|
|
|
/*! \brief Resources used by Level state. */
|
|
|
|
struct Level {
|
|
|
|
int current_level;
|
2012-04-08 19:01:30 +02:00
|
|
|
float speed;
|
|
|
|
float bg_pos, st_pos, fg_pos, cl_pos;
|
2012-04-08 23:25:14 +02:00
|
|
|
float derpy_x, derpy_y;
|
|
|
|
int sheet_rows, sheet_cols, sheet_pos, sheet_tmp, sheet_speed;
|
2012-04-08 19:01:30 +02:00
|
|
|
ALLEGRO_BITMAP *background, *stage, *foreground, *clouds;
|
2012-04-08 23:25:14 +02:00
|
|
|
ALLEGRO_BITMAP *welcome;
|
|
|
|
ALLEGRO_BITMAP *derpy_walkcycle; /*!< Derpy walk cycle spritesheet. */
|
|
|
|
ALLEGRO_BITMAP *derpy; /*!< Derpy sprite. */
|
2012-04-06 17:28:38 +02:00
|
|
|
struct Moonwalk moonwalk;
|
|
|
|
};
|
|
|
|
|
2012-03-07 22:06:19 +01:00
|
|
|
/*! \brief Enum of menu states in Menu and Pause game states. */
|
|
|
|
enum menustate_enum {
|
|
|
|
MENUSTATE_MAIN,
|
|
|
|
MENUSTATE_OPTIONS,
|
|
|
|
MENUSTATE_CONTROLS,
|
|
|
|
MENUSTATE_VIDEO,
|
2012-03-13 12:42:28 +01:00
|
|
|
MENUSTATE_PAUSE,
|
|
|
|
MENUSTATE_AUDIO
|
2012-03-07 22:06:19 +01:00
|
|
|
};
|
|
|
|
|
2012-02-28 13:09:12 +01:00
|
|
|
/*! \brief Resources used by Menu state. */
|
2012-02-16 15:40:58 +01:00
|
|
|
struct Menu {
|
2012-02-28 13:09:12 +01:00
|
|
|
ALLEGRO_BITMAP *menu_fade_bitmap;
|
|
|
|
ALLEGRO_BITMAP *image;
|
|
|
|
ALLEGRO_BITMAP *cloud;
|
|
|
|
ALLEGRO_BITMAP *cloud2;
|
|
|
|
ALLEGRO_BITMAP *pie;
|
|
|
|
ALLEGRO_BITMAP *pie_bitmap;
|
|
|
|
ALLEGRO_BITMAP *pinkcloud_bitmap;
|
|
|
|
ALLEGRO_BITMAP *pinkcloud;
|
|
|
|
ALLEGRO_BITMAP *rain;
|
2012-02-29 23:00:59 +01:00
|
|
|
ALLEGRO_BITMAP *rain_bitmap;
|
2012-02-28 13:09:12 +01:00
|
|
|
ALLEGRO_BITMAP *mountain;
|
|
|
|
float cloud_position;
|
|
|
|
float cloud2_position;
|
2012-02-16 17:05:16 +01:00
|
|
|
int mountain_position;
|
2012-02-28 13:09:12 +01:00
|
|
|
ALLEGRO_SAMPLE *sample;
|
|
|
|
ALLEGRO_SAMPLE *rain_sample;
|
|
|
|
ALLEGRO_SAMPLE *click_sample;
|
2012-03-05 21:07:42 +01:00
|
|
|
ALLEGRO_SAMPLE_INSTANCE *music; /*!< Sample instance with background music. */
|
|
|
|
ALLEGRO_SAMPLE_INSTANCE *rain_sound; /*!< Sample instance with rain sound. */
|
|
|
|
ALLEGRO_SAMPLE_INSTANCE *click; /*!< Sample instance with click sound. */
|
2012-02-28 13:09:12 +01:00
|
|
|
ALLEGRO_FONT *font_title;
|
|
|
|
ALLEGRO_FONT *font_subtitle;
|
|
|
|
ALLEGRO_FONT *font;
|
|
|
|
ALLEGRO_FONT *font_selected;
|
2012-02-16 23:36:25 +01:00
|
|
|
int selected;
|
2012-03-07 22:06:19 +01:00
|
|
|
enum menustate_enum menustate;
|
2012-02-29 23:00:59 +01:00
|
|
|
bool loaded;
|
2012-03-08 12:34:47 +01:00
|
|
|
struct {
|
|
|
|
bool fullscreen;
|
|
|
|
int fps;
|
|
|
|
int width;
|
|
|
|
int height;
|
|
|
|
} options;
|
2012-02-16 15:40:58 +01:00
|
|
|
};
|
|
|
|
|
2012-02-28 13:09:12 +01:00
|
|
|
/*! \brief Resources used by Loading state. */
|
2012-02-16 15:40:58 +01:00
|
|
|
struct Loading {
|
2012-02-28 13:09:12 +01:00
|
|
|
ALLEGRO_BITMAP *loading_bitmap;
|
|
|
|
ALLEGRO_BITMAP *image;
|
2012-02-16 15:40:58 +01:00
|
|
|
};
|
|
|
|
|
2012-03-02 16:52:13 +01:00
|
|
|
/*! \brief Resources used by Pause state. */
|
|
|
|
struct Pause {
|
|
|
|
ALLEGRO_BITMAP *bitmap;
|
2012-03-04 13:24:35 +01:00
|
|
|
ALLEGRO_BITMAP *derpy;
|
2012-03-02 16:52:13 +01:00
|
|
|
};
|
|
|
|
|
2012-02-28 13:09:12 +01:00
|
|
|
/*! \brief Resources used by About state. */
|
2012-02-18 06:26:58 +01:00
|
|
|
struct About {
|
2012-02-28 13:09:12 +01:00
|
|
|
ALLEGRO_BITMAP *fade_bitmap;
|
|
|
|
ALLEGRO_BITMAP *image;
|
|
|
|
ALLEGRO_BITMAP *text_bitmap;
|
|
|
|
ALLEGRO_BITMAP *letter;
|
2012-02-19 20:18:28 +01:00
|
|
|
ALLEGRO_SAMPLE *sample;
|
2012-03-05 21:07:42 +01:00
|
|
|
ALLEGRO_SAMPLE_INSTANCE *music; /*!< Sample instance with background music. */
|
2012-02-22 13:38:56 +01:00
|
|
|
ALLEGRO_FONT *font;
|
|
|
|
float x;
|
2012-04-03 21:17:56 +02:00
|
|
|
int fadeloop;
|
2012-02-18 06:26:58 +01:00
|
|
|
};
|
|
|
|
|
2012-02-28 13:09:12 +01:00
|
|
|
/*! \brief Resources used by Map state. */
|
2012-02-18 18:49:35 +01:00
|
|
|
struct Map {
|
2012-02-28 13:09:12 +01:00
|
|
|
ALLEGRO_BITMAP *map;
|
|
|
|
ALLEGRO_BITMAP *background;
|
|
|
|
ALLEGRO_BITMAP *map_bg;
|
|
|
|
ALLEGRO_BITMAP *highlight;
|
|
|
|
ALLEGRO_BITMAP *arrow;
|
|
|
|
int selected;
|
|
|
|
int available;
|
2012-02-21 23:33:02 +01:00
|
|
|
float arrowpos;
|
2012-02-28 13:09:12 +01:00
|
|
|
ALLEGRO_SAMPLE *sample;
|
|
|
|
ALLEGRO_SAMPLE *click_sample;
|
2012-03-05 21:07:42 +01:00
|
|
|
ALLEGRO_SAMPLE_INSTANCE *music; /*!< Sample instance with background music. */
|
|
|
|
ALLEGRO_SAMPLE_INSTANCE *click; /*!< Sample instance with click sound. */
|
2012-02-18 18:49:35 +01:00
|
|
|
};
|
|
|
|
|
2012-02-28 13:09:12 +01:00
|
|
|
/*! \brief Resources used by Intro state. */
|
2012-02-18 04:14:35 +01:00
|
|
|
struct Intro {
|
|
|
|
int position;
|
|
|
|
int page;
|
2012-04-04 00:06:47 +02:00
|
|
|
bool in_animation; /*!< Animation as in page transition animation. */
|
|
|
|
float anim;
|
2012-02-28 13:09:12 +01:00
|
|
|
ALLEGRO_BITMAP *table;
|
|
|
|
ALLEGRO_BITMAP *table_bitmap;
|
2012-04-04 00:06:47 +02:00
|
|
|
ALLEGRO_BITMAP *animation;
|
|
|
|
ALLEGRO_BITMAP *animsprites[5];
|
2012-02-18 05:53:39 +01:00
|
|
|
ALLEGRO_FONT *font;
|
2012-02-19 20:18:28 +01:00
|
|
|
ALLEGRO_SAMPLE *sample;
|
2012-03-05 21:07:42 +01:00
|
|
|
ALLEGRO_SAMPLE_INSTANCE *music; /*!< Sample instance with background music. */
|
2012-03-04 22:02:23 +01:00
|
|
|
ALLEGRO_AUDIO_STREAM *audiostream;
|
2012-02-18 04:14:35 +01:00
|
|
|
};
|
|
|
|
|
2012-02-28 13:09:12 +01:00
|
|
|
/*! \brief Resources used by Game state. */
|
2012-02-16 15:40:58 +01:00
|
|
|
struct Game {
|
|
|
|
ALLEGRO_DISPLAY *display;
|
2012-02-28 13:09:12 +01:00
|
|
|
ALLEGRO_FONT *font;
|
|
|
|
ALLEGRO_FONT *font_console;
|
2012-02-16 15:40:58 +01:00
|
|
|
enum gamestate_enum gamestate;
|
|
|
|
enum gamestate_enum loadstate;
|
|
|
|
ALLEGRO_EVENT_QUEUE *event_queue;
|
|
|
|
ALLEGRO_TIMER *timer;
|
2012-02-17 13:25:06 +01:00
|
|
|
ALLEGRO_BITMAP *console;
|
2012-02-28 13:09:12 +01:00
|
|
|
bool showconsole;
|
2012-03-13 12:42:28 +01:00
|
|
|
int fx;
|
|
|
|
int music;
|
|
|
|
int voice;
|
2012-02-28 13:09:12 +01:00
|
|
|
bool fullscreen;
|
|
|
|
bool debug;
|
|
|
|
int fps;
|
|
|
|
int width;
|
|
|
|
int height;
|
2012-02-29 23:00:59 +01:00
|
|
|
bool shuttingdown;
|
2012-03-08 12:34:47 +01:00
|
|
|
bool restart;
|
2012-02-16 15:40:58 +01:00
|
|
|
struct Menu menu;
|
|
|
|
struct Loading loading;
|
2012-02-18 04:14:35 +01:00
|
|
|
struct Intro intro;
|
2012-02-18 06:26:58 +01:00
|
|
|
struct About about;
|
2012-02-18 18:49:35 +01:00
|
|
|
struct Map map;
|
2012-02-22 12:43:14 +01:00
|
|
|
struct Level level;
|
2012-03-02 16:52:13 +01:00
|
|
|
struct Pause pause;
|
2012-03-05 11:13:08 +01:00
|
|
|
struct {
|
2012-03-13 12:42:28 +01:00
|
|
|
ALLEGRO_VOICE *v;
|
2012-03-05 21:07:42 +01:00
|
|
|
ALLEGRO_MIXER *mixer;
|
2012-03-05 11:13:08 +01:00
|
|
|
ALLEGRO_MIXER *music;
|
2012-03-13 12:42:28 +01:00
|
|
|
ALLEGRO_MIXER *voice;
|
2012-03-05 11:13:08 +01:00
|
|
|
ALLEGRO_MIXER *fx;
|
|
|
|
} audio;
|
2012-02-16 15:40:58 +01:00
|
|
|
};
|
|
|
|
|
2012-02-28 13:09:12 +01:00
|
|
|
/*! \brief Draws text with shadow.
|
|
|
|
*
|
|
|
|
* Draws given text two times: once with color (0,0,0,128) and 1px off in both x and y axis,
|
|
|
|
* and second time with actual given color and position.
|
|
|
|
*/
|
2012-02-24 23:58:18 +01:00
|
|
|
void al_draw_text_with_shadow(ALLEGRO_FONT *font, ALLEGRO_COLOR color, float x, float y, int flags, char const *text);
|
2012-02-28 13:09:12 +01:00
|
|
|
|
|
|
|
/*! \brief Preloads gamestate set in game->loadstate. */
|
2012-02-16 15:40:58 +01:00
|
|
|
void PreloadGameState(struct Game *game);
|
2012-02-28 13:09:12 +01:00
|
|
|
|
|
|
|
/*! \brief Unloads gamestate set in game->gamestate. */
|
2012-02-16 15:40:58 +01:00
|
|
|
void UnloadGameState(struct Game *game);
|
2012-02-28 13:09:12 +01:00
|
|
|
|
|
|
|
/*! \brief Loads gamestate set in game->loadstate. */
|
2012-02-16 15:40:58 +01:00
|
|
|
void LoadGameState(struct Game *game);
|
2012-02-28 13:09:12 +01:00
|
|
|
|
|
|
|
/*! \brief Print some message on game console.
|
|
|
|
*
|
|
|
|
* Draws message on console bitmap, so it'll be displayed when calling DrawConsole.
|
|
|
|
* If game->debug is true, then it also prints given message on stdout.
|
|
|
|
* It needs to be called in printf style.
|
|
|
|
*/
|
2012-02-19 22:54:33 +01:00
|
|
|
void PrintConsole(struct Game *game, char* format, ...);
|
2012-02-28 13:09:12 +01:00
|
|
|
|
|
|
|
/*! \brief Draws console bitmap on screen. */
|
2012-02-17 13:25:06 +01:00
|
|
|
void DrawConsole(struct Game *game);
|
2012-02-16 15:40:58 +01:00
|
|
|
|
2012-03-04 15:57:23 +01:00
|
|
|
//void ScaleBitmap(ALLEGRO_BITMAP* source, int width, int height);
|
|
|
|
ALLEGRO_BITMAP* LoadScaledBitmap(char* filename, int width, int height);
|
2012-03-01 10:49:20 +01:00
|
|
|
float tps(struct Game *game, float t);
|
2012-03-01 00:37:16 +01:00
|
|
|
|
2012-03-02 16:52:13 +01:00
|
|
|
void DrawGameState(struct Game *game);
|
|
|
|
|
2012-03-08 22:21:02 +01:00
|
|
|
int Shared_Load(struct Game *game);
|
|
|
|
void Shared_Unload(struct Game *game);
|
|
|
|
|
2012-02-26 00:47:41 +01:00
|
|
|
#endif
|