2016-07-04 00:56:45 +02:00
|
|
|
/*! \file character.h
|
|
|
|
* \brief Headers of character and spritesheet functions.
|
|
|
|
*/
|
|
|
|
/*
|
|
|
|
* 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
|
2017-07-22 18:22:12 +02:00
|
|
|
* the Free Software Foundation; either version 3 of the License, or
|
2016-07-04 00:56:45 +02:00
|
|
|
* (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
|
2017-07-22 18:22:12 +02:00
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2016-07-04 00:56:45 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef LIBSUPERDERPY_CHARACTER_H
|
|
|
|
#define LIBSUPERDERPY_CHARACTER_H
|
|
|
|
|
2017-09-10 21:35:14 +02:00
|
|
|
#include "libsuperderpy.h"
|
2016-07-04 00:56:45 +02:00
|
|
|
#include <allegro5/allegro.h>
|
|
|
|
#include <allegro5/allegro_font.h>
|
|
|
|
|
2018-03-20 21:39:37 +01:00
|
|
|
struct SpritesheetFrame {
|
|
|
|
char* file;
|
|
|
|
ALLEGRO_BITMAP* bitmap;
|
|
|
|
double duration;
|
|
|
|
int row;
|
|
|
|
int col;
|
|
|
|
int x;
|
|
|
|
int y;
|
|
|
|
bool flipX;
|
|
|
|
bool flipY;
|
|
|
|
};
|
|
|
|
|
2016-07-04 00:56:45 +02:00
|
|
|
/*! \brief Structure representing one spritesheet for character animation. */
|
|
|
|
struct Spritesheet {
|
2017-09-10 21:35:14 +02:00
|
|
|
char* name; /*!< Name of the spritesheet (used in file paths). */
|
|
|
|
ALLEGRO_BITMAP* bitmap; /*!< Spritesheet bitmap. */
|
2018-03-20 21:39:37 +01:00
|
|
|
int frameCount;
|
2017-09-10 21:35:14 +02:00
|
|
|
int rows; /*!< Number of rows in the spritesheet. */
|
|
|
|
int cols; /*!< Number of columns in the spritesheet. */
|
2018-03-20 21:39:37 +01:00
|
|
|
double duration;
|
|
|
|
char* file;
|
2018-02-10 04:29:57 +01:00
|
|
|
int repeats; /*!< Number of repeats to make before the spritesheet is changed to its successor. */
|
2017-09-10 21:35:14 +02:00
|
|
|
char* successor; /*!< Name of animation successor. If it's not blank, then animation will be played only once. */
|
2018-03-21 02:05:22 +01:00
|
|
|
char* predecessor;
|
2018-03-20 21:39:37 +01:00
|
|
|
bool bidir;
|
|
|
|
bool reversed;
|
|
|
|
double pivotX;
|
|
|
|
double pivotY;
|
|
|
|
bool flipX;
|
|
|
|
bool flipY;
|
|
|
|
struct SpritesheetFrame* frames;
|
|
|
|
|
|
|
|
int width;
|
|
|
|
int height;
|
|
|
|
|
2017-09-10 21:35:14 +02:00
|
|
|
struct Spritesheet* next; /*!< Next spritesheet in the queue. */
|
2018-02-10 04:29:57 +01:00
|
|
|
|
|
|
|
// TODO: missing docs
|
2016-07-04 00:56:45 +02:00
|
|
|
};
|
|
|
|
|
2018-06-27 19:30:35 +02:00
|
|
|
struct Character;
|
|
|
|
typedef void CharacterCallback(struct Game*, struct Character*, struct Spritesheet* newAnim, struct Spritesheet* oldAnim, void*);
|
2018-06-28 04:25:56 +02:00
|
|
|
#define CharacterCallback(x) void x(struct Game* game, struct Character* character, struct Spritesheet* new, struct Spritesheet* old, void* data)
|
2018-06-27 19:30:35 +02:00
|
|
|
|
2016-07-04 00:56:45 +02:00
|
|
|
/*! \brief Structure representing one visible character. */
|
|
|
|
struct Character {
|
2017-09-10 21:35:14 +02:00
|
|
|
char* name; /*!< Name of the character (used in file paths). */
|
2018-02-10 04:29:57 +01:00
|
|
|
struct Character* parent; /*!< Parent character. NULL is no parent. */
|
2018-03-20 21:39:37 +01:00
|
|
|
//ALLEGRO_BITMAP* bitmap; /*!< Subbitmap with character's current frame. */
|
|
|
|
struct SpritesheetFrame* frame; /*!< Current frame. */
|
2017-09-10 21:35:14 +02:00
|
|
|
struct Spritesheet* spritesheet; /*!< Current spritesheet used by character. */
|
|
|
|
struct Spritesheet* spritesheets; /*!< List of all spritesheets registered to character. */
|
|
|
|
int pos; /*!< Current spritesheet position. */
|
2018-03-20 21:39:37 +01:00
|
|
|
double delta; /*!< A counter used internally to slow down spritesheet animation. */ // TODO: change to delta
|
2018-02-10 04:29:57 +01:00
|
|
|
char* successor; /*!< Name of the next spritesheet to be played when the current one finishes. */
|
2018-03-21 02:05:22 +01:00
|
|
|
char* predecessor; /*!< Name of the next spritesheet to be played when the current one finishes when in reverse mode. */
|
2017-09-10 21:35:14 +02:00
|
|
|
float x; /*!< Horizontal position of character. */
|
|
|
|
float y; /*!< Vertical position of character. */
|
2018-02-10 04:29:57 +01:00
|
|
|
ALLEGRO_COLOR tint; /*!< Color with which the character's pixels will be multiplied (tinted). White for no effect. */
|
2018-03-20 21:39:37 +01:00
|
|
|
//float pivotX; /*!< Pivot point's X, for scaling and rotating, relative of character's size. */
|
|
|
|
//float pivotY; /*!< Pivot point's Y, for scaling and rotating, relative of character's size. */
|
2018-02-10 04:29:57 +01:00
|
|
|
float scaleX; /*!< Scale factor for X axis. */
|
|
|
|
float scaleY; /*!< Scale factor for Y axis. */
|
|
|
|
float angle; /*!< Character's rotation angle (radians). */
|
|
|
|
int confineX; /*!< Width of the canvas being drawn to, for correct position calculation; when -1, uses parent's confines or viewport size */
|
|
|
|
int confineY; /*!< Height of the canvas being drawn to, for correct position calculation; when -1, uses parent's confines or viewport size */
|
|
|
|
bool flipX; /*!< Flips the character's sprite vertically. */
|
|
|
|
bool flipY; /*!< Flips the character's sprite horizontally. */
|
2018-04-13 03:00:54 +02:00
|
|
|
int repeats; /*!< Number of repeats left before the spritesheet is changed to its successor or stopped. */
|
2018-03-21 02:05:22 +01:00
|
|
|
bool reversing; /*!< Whether the animation is currently played backwards. */
|
|
|
|
bool reversed; /*!< Whether the current animation has been requested as reversed. */
|
2018-03-20 21:39:37 +01:00
|
|
|
bool hidden;
|
2018-02-09 03:34:50 +01:00
|
|
|
void* data; /*!< Additional, custom character data (HP etc.). */
|
2018-06-27 19:30:35 +02:00
|
|
|
CharacterCallback* callback;
|
2018-03-20 21:39:37 +01:00
|
|
|
void* callbackData;
|
|
|
|
bool shared; /*!< Marks the list of spritesheets as shared, so it won't be freed together with the character. */
|
2018-02-10 04:29:57 +01:00
|
|
|
|
|
|
|
// TODO: parents
|
2016-07-04 00:56:45 +02:00
|
|
|
};
|
|
|
|
|
2018-02-10 04:29:57 +01:00
|
|
|
// TODO: document functions
|
|
|
|
|
2017-09-10 21:35:14 +02:00
|
|
|
void SelectSpritesheet(struct Game* game, struct Character* character, char* name);
|
2018-04-26 14:33:52 +02:00
|
|
|
void SwitchSpritesheet(struct Game* game, struct Character* character, char* name);
|
2018-02-10 04:29:57 +01:00
|
|
|
void EnqueueSpritesheet(struct Game* game, struct Character* character, char* name);
|
2017-09-10 21:35:14 +02:00
|
|
|
void RegisterSpritesheet(struct Game* game, struct Character* character, char* name);
|
2018-04-15 23:00:17 +02:00
|
|
|
struct Spritesheet* GetSpritesheet(struct Game* game, struct Character* character, char* name);
|
2016-07-04 00:56:45 +02:00
|
|
|
|
2018-06-04 19:10:29 +02:00
|
|
|
ALLEGRO_TRANSFORM GetCharacterTransform(struct Game* game, struct Character* character);
|
|
|
|
|
2018-02-10 04:29:57 +01:00
|
|
|
void DrawCharacter(struct Game* game, struct Character* character);
|
2017-09-10 21:35:14 +02:00
|
|
|
void DrawScaledCharacterF(struct Game* game, struct Character* character, ALLEGRO_COLOR tint, float scalex, float scaley, int flags);
|
|
|
|
void DrawScaledCharacter(struct Game* game, struct Character* character, ALLEGRO_COLOR tint, float scalex, float scaley, int flags);
|
2016-07-04 00:56:45 +02:00
|
|
|
|
2017-09-10 21:35:14 +02:00
|
|
|
struct Character* CreateCharacter(struct Game* game, char* name);
|
|
|
|
void DestroyCharacter(struct Game* game, struct Character* character);
|
2016-07-04 00:56:45 +02:00
|
|
|
|
2017-09-10 21:35:14 +02:00
|
|
|
void LoadSpritesheets(struct Game* game, struct Character* character);
|
|
|
|
void UnloadSpritesheets(struct Game* game, struct Character* character);
|
2016-07-04 00:56:45 +02:00
|
|
|
|
2018-02-10 04:29:57 +01:00
|
|
|
void AnimateCharacter(struct Game* game, struct Character* character, float delta, float speed_modifier);
|
2017-09-10 21:35:14 +02:00
|
|
|
void MoveCharacter(struct Game* game, struct Character* character, float x, float y, float angle);
|
|
|
|
void MoveCharacterF(struct Game* game, struct Character* character, float x, float y, float angle);
|
|
|
|
void SetCharacterPosition(struct Game* game, struct Character* character, float x, float y, float angle);
|
|
|
|
void SetCharacterPositionF(struct Game* game, struct Character* character, float x, float y, float angle);
|
2018-02-03 03:17:36 +01:00
|
|
|
void SetCharacterConfines(struct Game* game, struct Character* character, int x, int y);
|
2016-08-26 23:52:32 +02:00
|
|
|
|
2018-02-10 04:29:57 +01:00
|
|
|
float GetCharacterX(struct Game* game, struct Character* character);
|
|
|
|
float GetCharacterY(struct Game* game, struct Character* character);
|
2018-02-03 03:17:36 +01:00
|
|
|
int GetCharacterConfineX(struct Game* game, struct Character* character);
|
|
|
|
int GetCharacterConfineY(struct Game* game, struct Character* character);
|
2016-07-04 00:56:45 +02:00
|
|
|
|
2018-03-15 00:46:52 +01:00
|
|
|
bool IsOnCharacter(struct Game* game, struct Character* character, float x, float y, bool pixelperfect);
|
2018-03-20 21:39:37 +01:00
|
|
|
void ShowCharacter(struct Game* game, struct Character* character);
|
|
|
|
void HideCharacter(struct Game* game, struct Character* character);
|
2016-08-29 23:44:15 +02:00
|
|
|
|
2016-07-04 00:56:45 +02:00
|
|
|
#endif
|