libsuperderpy/src/main.h

336 lines
15 KiB
C
Raw Normal View History

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-05-09 10:58:45 +02:00
#include "allegro_utils.h"
2012-02-16 15:40:58 +01:00
2012-05-19 18:09:20 +02:00
/*! \brief Declares variables used by displaying progress bar on loading screen.
* Takes number of loading steps as parameter.
*/
#define PROGRESS_INIT(a) float load_p = 0, load_a = a;
2012-05-19 18:09:20 +02:00
/*! \brief Increments progress of loading. */
#define PROGRESS if (progress) (*progress)(game, load_p+=1/load_a);
struct Game;
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,
GAMESTATE_MENU,
GAMESTATE_ABOUT,
GAMESTATE_INTRO,
2012-02-21 23:33:02 +01:00
GAMESTATE_MAP,
GAMESTATE_LEVEL,
GAMESTATE_DISCLAIMER
2012-02-16 15:40:58 +01: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. */
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-05-19 18:09:20 +02:00
/*! \brief Structure representing obstacles and power-ups flying through the level. */
2012-05-19 15:31:41 +02:00
struct Obstacle {
2012-05-19 18:09:20 +02:00
ALLEGRO_BITMAP **bitmap; /*!< Pointer to bitmap used by obstacle. */
2012-05-20 14:40:49 +02:00
float x; /*!< Horizontal position on the screen, in range 0-100. */
float y; /*!< Vertical position on the screen, in range 0-100. */
2012-05-19 18:09:20 +02:00
float speed; /*!< Horizontal speed of obstracle. */
2012-05-21 14:00:42 +02:00
float angle; /*!< Angle of bitmap rotation in radians. */
2012-05-19 18:09:20 +02:00
int points; /*!< Number of points given when hit by player. Positive gives HP to power, negative takes it. */
bool hit; /*!< Indicates if this obstacle was already hit by the player or not. */
2012-05-20 14:40:49 +02:00
int cols; /*!< Number of columns in spritesheet. */
int rows; /*!< Number of rows in spritesheet. */
int pos; /*!< Current position in spritesheet. */
int blanks; /*!< Number of blank frames at the end of the spritesheet. */
float tmp_pos; /*!< Temporary counter used to slow down spritesheet animation. */
float anim_speed; /*!< Speed of spritesheet animation. */
2012-05-19 18:09:20 +02:00
void (*callback)(struct Game*, struct Obstacle*); /*!< Pointer to function called to update obstacle position, animate it, etc. */
void *data; /*!< Pointer passed to callback function. */
struct Obstacle *prev; /*!< Previous obstacle on the list. */
struct Obstacle *next; /*!< Next obstacle on the list. */
};
2012-04-30 22:15:11 +02:00
2012-05-19 18:28:19 +02:00
/*! \brief Structure representing one spritesheet animation of Derpy. */
2012-05-03 19:42:23 +02:00
struct Spritesheet {
2012-05-19 18:09:20 +02:00
char* name; /*!< Readable name of the spritesheet. */
ALLEGRO_BITMAP* bitmap; /*!< Spritesheet bitmap. */
int rows; /*!< Number of rows in the spritesheet. */
int cols; /*!< Number of columns in the spritesheet. */
int blanks; /*!< Number of blank frames at the end of the spritesheet. */
float speed; /*!< Speed modifier of spritesheet animation. */
float aspect; /*!< Aspect ratio of the frame. */
float scale; /*!< Scale modifier of the frame. */
struct Spritesheet* next; /*!< Next spritesheet in the queue. */
2012-05-03 19:42:23 +02:00
};
/*! \brief Resources used by Level state. */
struct Level {
2012-04-30 22:15:11 +02:00
int current_level; /*!< Level number. */
2012-05-19 18:09:20 +02:00
float speed; /*!< Speed of the player. */
float speed_modifier; /*!< Modifier of the speed of the player. */
2012-05-19 18:09:20 +02:00
float bg_pos; /*!< Position of the background layer of the scene. */
float st_pos; /*!< Position of the stage layer of the scene. */
float fg_pos; /*!< Position of the foreground layer of the scene. */
float cl_pos; /*!< Position of the clouds layer of the scene. */
float derpy_x; /*!< Horizontal position of Derpy (0-1). */
float derpy_y; /*!< Vertical position of Derpy (0-1). */
2012-06-19 17:18:33 +02:00
float derpy_angle; /*!< Angle of Derpy sprite on screen (radians). */
2012-05-19 18:09:20 +02:00
float hp; /*!< Player health points (0-1). */
bool handle_input; /*!< When false, player looses control over Derpy. */
bool failed; /*!< Indicates if player failed level. */
float meter_alpha; /*!< Alpha level of HP meter. */
int sheet_rows; /*!< Number of rows in current spritesheet. */
int sheet_cols; /*!< Number of cols in current spritesheet. */
int sheet_pos; /*!< Frame position in current spritesheet. */
int sheet_blanks; /*!< Number of blank frames at the end of current spritesheet. */
float sheet_tmp; /*!< Temporary counter used to slow down spritesheet animation. */
float sheet_speed; /*!< Current speed of Derpy animation. */
float sheet_speed_modifier; /*!< Modifier of speed, specified by current spritesheet. */
float sheet_scale; /*!< Scale modifier of current spritesheet. */
2012-07-08 00:23:40 +02:00
ALLEGRO_FONT *letter_font; /*!< Font used in letter from Twilight on first level. */
2012-04-09 15:25:56 +02:00
ALLEGRO_SAMPLE *sample; /*!< Sample with background music. */
ALLEGRO_SAMPLE_INSTANCE *music; /*!< Sample instance with background music. */
unsigned int music_pos; /*!< Position of sample instance. Used when pausing game. */
2012-05-20 23:17:52 +02:00
ALLEGRO_BITMAP *owl; /*!< Owlicious bitmap. */
2012-05-19 18:09:20 +02:00
ALLEGRO_BITMAP *background; /*!< Bitmap of the background layer of the scene. */
ALLEGRO_BITMAP *stage; /*!< Bitmap of the stage layer of the scene. */
ALLEGRO_BITMAP *foreground; /*!< Bitmap of the foreground layer of the scene. */
ALLEGRO_BITMAP *clouds; /*!< Bitmap of the clouds layer of the scene. */
ALLEGRO_BITMAP *welcome; /*!< Bitmap of the welcome text (for instance "Level 1: Fluttershy"). */
ALLEGRO_BITMAP **derpy_sheet; /*!< Pointer to active Derpy sprite sheet. */
2012-04-08 23:25:14 +02:00
ALLEGRO_BITMAP *derpy; /*!< Derpy sprite. */
2012-05-19 18:09:20 +02:00
ALLEGRO_BITMAP *meter_bmp; /*!< Bitmap of the HP meter. */
ALLEGRO_BITMAP *meter_image; /*!< Derpy image used in the HP meter. */
2012-05-21 22:27:49 +02:00
ALLEGRO_BITMAP *letter; /*!< Bitmap with letter from Twilight. */
2012-05-19 18:48:29 +02:00
bool debug_show_sprite_frames; /*!< When true, displays colorful borders around spritesheets and their active areas. */
2012-05-03 19:42:23 +02:00
struct Spritesheet* derpy_sheets; /*!< List of sprite sheets of Derpy character. */
struct Spritesheet* pony_sheets; /*!< List of sprite sheets of character rescued by Derpy. */
2012-05-01 22:52:30 +02:00
struct {
2012-05-22 21:29:55 +02:00
ALLEGRO_BITMAP *pie1; /*!< Pie bitmap. */
ALLEGRO_BITMAP *pie2; /*!< Pie bitmap (crossed). */
2012-05-21 18:47:17 +02:00
ALLEGRO_BITMAP *muffin; /*!< Good muffin bitmap. */
ALLEGRO_BITMAP *badmuffin; /*!< Bad muffin bitmap. */
2012-05-23 10:34:36 +02:00
ALLEGRO_BITMAP *cherry; /*!< Cherry bitmap. */
2012-05-20 14:40:49 +02:00
ALLEGRO_BITMAP *pig; /*!< Pig spritesheet bitmap. */
2012-05-21 18:47:17 +02:00
ALLEGRO_BITMAP *screwball; /*!< Screwball spritesheet bitmap. */
2012-05-19 18:09:20 +02:00
} obst_bmps; /*!< Obstacle bitmaps. */
struct Obstacle *obstacles; /*!< List of obstacles being currently rendered. */
struct Moonwalk moonwalk; /*!< Moonwalk placeholder data. */
};
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-05-21 10:14:49 +02:00
ALLEGRO_BITMAP *menu_fade_bitmap; /*!< Screenshot bitmap used for fades. */
ALLEGRO_BITMAP *image; /*!< Bitmap with lower portion of menu landscape. */
ALLEGRO_BITMAP *cloud; /*!< Bitmap with bigger cloud. */
ALLEGRO_BITMAP *cloud2; /*!< Bitmap with small cloud. */
ALLEGRO_BITMAP *pie; /*!< Unscaled bitmap with pie. */
ALLEGRO_BITMAP *pie_bitmap; /*!< Scaled and "rendered" bitmap with pies. */
ALLEGRO_BITMAP *pinkcloud_bitmap; /*!< Scaled bitmap with pinkcloud and home. */
ALLEGRO_BITMAP *pinkcloud; /*!< Unscaled bitmap with pinkcloud and home. */
ALLEGRO_BITMAP *rain; /*!< Unscaled bitmap with rain drop. */
ALLEGRO_BITMAP *rain_bitmap; /*!< Scaled and "rendered" bitmap with rain drops. */
ALLEGRO_BITMAP *mountain; /*!< Flashing mountain in background bitmap. */
ALLEGRO_BITMAP *logo; /*!< Logo displayed in the background. */
2012-07-03 23:44:03 +02:00
ALLEGRO_BITMAP *logoblur; /*!< Prerendered blurred logo. */
ALLEGRO_BITMAP *glass; /*!< Texture used for glass effect in the logo. */
2012-07-03 23:44:03 +02:00
ALLEGRO_BITMAP *blurbg; /*!< Temporary bitmap used for blur effect in glass logo. */
ALLEGRO_BITMAP *blurbg2; /*!< Temporary bitmap used for blur effect in glass logo. */
2012-05-21 10:14:49 +02:00
float cloud_position; /*!< Position of bigger cloud. */
float cloud2_position; /*!< Position of small cloud. */
int mountain_position; /*!< Position of flashing mountain. */
ALLEGRO_SAMPLE *sample; /*!< Background music sample. */
ALLEGRO_SAMPLE *rain_sample; /*!< Rain sound sample. */
ALLEGRO_SAMPLE *click_sample; /*!< Click sound 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-05-21 10:14:49 +02:00
ALLEGRO_FONT *font_title; /*!< Font of "Super Derpy" text. */
ALLEGRO_FONT *font_subtitle; /*!< Font of "Muffin Attack" text. */
ALLEGRO_FONT *font; /*!< Font of standard menu item. */
ALLEGRO_FONT *font_selected; /*!< Font of selected menu item. */
int selected; /*!< Number of selected menu item. */
enum menustate_enum menustate; /*!< Current menu page. */
bool loaded; /*!< True if Menu state has been already loaded. */
struct {
bool fullscreen;
int fps;
int width;
int height;
2012-05-21 10:14:49 +02:00
} options; /*!< Options which can be changed in menu. */
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-05-19 18:09:20 +02:00
ALLEGRO_BITMAP *loading_bitmap; /*!< Rendered loading bitmap. */
ALLEGRO_BITMAP *image; /*!< Loading background. */
2012-02-16 15:40:58 +01:00
};
2012-03-02 16:52:13 +01:00
/*! \brief Resources used by Pause state. */
struct Pause {
2012-05-19 18:09:20 +02:00
ALLEGRO_BITMAP *bitmap; /*!< Bitmap with screenshot. */
ALLEGRO_BITMAP *derpy; /*!< Derpy on foreground. */
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-05-19 18:09:20 +02:00
ALLEGRO_BITMAP *fade_bitmap; /*!< Bitmap with screenshot, used in fades. */
ALLEGRO_BITMAP *image; /*!< Background bitmap. */
ALLEGRO_BITMAP *text_bitmap; /*!< Bitmap with scrolled text. */
ALLEGRO_BITMAP *letter; /*!< Paper bitmap. */
ALLEGRO_SAMPLE *sample; /*!< Sample with background music. */
2012-03-05 21:07:42 +01:00
ALLEGRO_SAMPLE_INSTANCE *music; /*!< Sample instance with background music. */
2012-05-19 18:09:20 +02:00
ALLEGRO_FONT *font; /*!< Font used in the text on letter. */
float x; /*!< Horizontal position of the text. */
int fadeloop; /*!< Loop counter used in fades. */
2012-02-18 06:26:58 +01:00
};
2012-02-28 13:09:12 +01:00
/*! \brief Resources used by Map state. */
struct Map {
2012-05-21 10:14:49 +02:00
ALLEGRO_BITMAP *map; /*!< Background table bitmap. */
ALLEGRO_BITMAP *map_bg; /*!< Map bitmap. */
ALLEGRO_BITMAP *highlight; /*!< Level highlights bitmap. */
ALLEGRO_BITMAP *arrow; /*!< Arrow bitmap. */
int selected; /*!< Number of currently selected level. */
int available; /*!< Number of highest available level. */
2012-05-19 18:09:20 +02:00
float arrowpos; /*!< Vertical position of the arrow. */
2012-05-21 10:14:49 +02:00
ALLEGRO_SAMPLE *sample; /*!< Sample with backgrond music. */
ALLEGRO_SAMPLE *click_sample; /*!< Sample with click sound. */
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-28 13:09:12 +01:00
/*! \brief Resources used by Intro state. */
2012-02-18 04:14:35 +01:00
struct Intro {
2012-05-21 10:14:49 +02:00
int position; /*!< Position of the page. */
int page; /*!< Current page number. */
2012-04-04 00:06:47 +02:00
bool in_animation; /*!< Animation as in page transition animation. */
2012-05-21 10:14:49 +02:00
float anim; /*!< Counter used for spritesheet animations. */
ALLEGRO_BITMAP *table; /*!< Background paper bitmap, two pages long. */
ALLEGRO_BITMAP *table_bitmap; /*!< Unscaled background paper bitmap. */
ALLEGRO_BITMAP *frame; /*!< Bitmap with frame around the screen. */
ALLEGRO_BITMAP *animsprites[5]; /*!< Array with spritesheet bitmaps. */
ALLEGRO_FONT *font; /*!< Font used for text. */
ALLEGRO_SAMPLE *sample; /*!< Background music sample. */
2012-03-05 21:07:42 +01:00
ALLEGRO_SAMPLE_INSTANCE *music; /*!< Sample instance with background music. */
2012-05-21 10:14:49 +02:00
ALLEGRO_AUDIO_STREAM *audiostream; /*!< Audiostream used for Celestia voice. */
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 {
2012-05-21 10:14:49 +02:00
ALLEGRO_DISPLAY *display; /*!< Main Allegro display. */
ALLEGRO_FONT *font; /*!< Main font used in game. */
ALLEGRO_FONT *font_console; /*!< Font used in game console. */
enum gamestate_enum gamestate; /*!< Current game state. */
enum gamestate_enum loadstate; /*!< Game state to be loaded. */
ALLEGRO_EVENT_QUEUE *event_queue; /*!< Main event queue. */
ALLEGRO_TIMER *timer; /*!< Main FPS timer. */
ALLEGRO_BITMAP *console; /*!< Bitmap with game console. */
bool showconsole; /*!< If true, game console is rendered on screen. */
int fx; /*!< Effects volume. */
int music; /*!< Music volume. */
int voice; /*!< Voice volume. */
bool fullscreen; /*!< Fullscreen toggle. */
bool debug; /*!< Toggles debug mode. */
int fps; /*!< FPS limit */
int width; /*!< Width of window as being set in configuration. */
int height; /*!< Height of window as being set in configuration. */
bool shuttingdown; /*!< If true then shut down of the game is pending. */
bool restart; /*!< If true then restart of the game is pending. */
struct Menu menu; /*!< Resources used by Menu state. */
struct Loading loading; /*!< Resources used by Menu state. */
struct Intro intro; /*!< Resources used by Intro state. */
struct About about; /*!< Resources used by About state. */
struct Map map; /*!< Resources used by Map state. */
struct Level level; /*!< Resources used by Level state. */
struct Pause pause; /*!< Resources used by Pause state. */
struct {
2012-05-21 10:14:49 +02:00
ALLEGRO_VOICE *v; /*!< Main voice used by the game. */
ALLEGRO_MIXER *mixer; /*!< Main mixer of the game. */
ALLEGRO_MIXER *music; /*!< Music mixer. */
ALLEGRO_MIXER *voice; /*!< Voice mixer. */
ALLEGRO_MIXER *fx; /*!< Effects mixer. */
} audio; /*!< Audio resources. */
2012-02-16 15:40:58 +01:00
};
2012-02-28 13:09:12 +01:00
/*! \brief Preloads gamestate set in game->loadstate. */
void PreloadGameState(struct Game *game, void (*progress)(struct Game*, float));
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.
*/
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-05-19 18:09:20 +02:00
/*! \brief Loads bitmap into memory and scales it with software linear filtering. */
2012-03-04 15:57:23 +01:00
ALLEGRO_BITMAP* LoadScaledBitmap(char* filename, int width, int height);
2012-05-19 18:09:20 +02:00
/*! \brief Draws console bitmap on screen. */
2012-03-01 10:49:20 +01:00
float tps(struct Game *game, float t);
2012-03-01 00:37:16 +01:00
2012-05-19 18:09:20 +02:00
/*! \brief Draws frame from current gamestate. */
2012-03-02 16:52:13 +01:00
void DrawGameState(struct Game *game);
2012-05-19 18:09:20 +02:00
/*! \brief Load shared resources. */
int Shared_Load(struct Game *game);
2012-05-19 18:09:20 +02:00
/*! \brief Unload shared resources. */
void Shared_Unload(struct Game *game);
2012-02-26 00:47:41 +01:00
#endif