libsuperderpy/src/character.h

159 lines
7.4 KiB
C
Raw Normal View History

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
#include "libsuperderpy.h"
2016-07-04 00:56:45 +02:00
2018-03-20 21:39:37 +01:00
struct SpritesheetFrame {
char* file;
char* filepath;
ALLEGRO_BITMAP *bitmap, *source;
2018-03-20 21:39:37 +01:00
double duration;
ALLEGRO_COLOR tint;
2018-03-20 21:39:37 +01:00
int row;
int col;
int x;
int y;
int sx;
int sy;
int sw;
int sh;
2018-03-20 21:39:37 +01:00
bool flipX;
bool flipY;
};
2016-07-04 00:56:45 +02:00
/*! \brief Structure representing one spritesheet for character animation. */
struct Spritesheet {
char* name; /*!< Name of the spritesheet (used in file paths). */
ALLEGRO_BITMAP* bitmap; /*!< Spritesheet bitmap. */
2018-12-16 15:35:53 +01:00
int frame_count;
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;
char* filepath;
2018-02-10 04:29:57 +01:00
int repeats; /*!< Number of repeats to make before the spritesheet is changed to its successor. */
char* successor; /*!< Name of animation successor. If it's not blank, then animation will be played only once. */
char* predecessor;
2018-03-20 21:39:37 +01:00
bool bidir;
bool reversed;
double pivotX;
double pivotY;
int offsetX;
int offsetY;
2018-03-20 21:39:37 +01:00
bool flipX;
bool flipY;
struct SpritesheetFrame* frames;
int width;
int height;
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
};
struct Character;
typedef void CharacterCallback(struct Game*, struct Character*, struct Spritesheet* newAnim, struct Spritesheet* oldAnim, void*);
#define CharacterCallback(x) void x(struct Game* game, struct Character* character, struct Spritesheet* new, struct Spritesheet* old, void* data)
typedef void CharacterDestructor(struct Game*, struct Character*);
2016-07-04 00:56:45 +02:00
/*! \brief Structure representing one visible character. */
struct Character {
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. */
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. */
char* predecessor; /*!< Name of the next spritesheet to be played when the current one finishes when in reverse mode. */
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. */
bool parent_tint; /*!< When true, the character tint is multiplied by its parent tint. */
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. */
int repeats; /*!< Number of repeats left before the spritesheet is changed to its successor or stopped. */
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.). */
CharacterCallback* callback;
2018-12-16 15:35:53 +01:00
void* callback_data;
CharacterDestructor* destructor;
2018-03-20 21:39:37 +01:00
bool shared; /*!< Marks the list of spritesheets as shared, so it won't be freed together with the character. */
2016-07-04 00:56:45 +02:00
};
2018-02-10 04:29:57 +01:00
// TODO: document functions
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);
void RegisterSpritesheet(struct Game* game, struct Character* character, char* name);
struct Spritesheet* GetSpritesheet(struct Game* game, struct Character* character, char* name);
2016-07-04 00:56:45 +02:00
ALLEGRO_TRANSFORM GetCharacterTransform(struct Game* game, struct Character* character);
ALLEGRO_COLOR GetCharacterTint(struct Game* game, struct Character* character);
2018-02-10 04:29:57 +01:00
void DrawCharacter(struct Game* game, struct Character* character);
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
struct Character* CreateCharacter(struct Game* game, char* name);
void DestroyCharacter(struct Game* game, struct Character* character);
2016-07-04 00:56:45 +02:00
void LoadSpritesheets(struct Game* game, struct Character* character, void (*progress)(struct Game*));
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);
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);
void SetCharacterConfines(struct Game* game, struct Character* character, int x, int y);
void SetParentCharacter(struct Game* game, struct Character* character, struct Character* parent);
2018-11-27 04:43:58 +01:00
void CopyCharacter(struct Game* game, struct Character* from, struct Character* to);
2018-02-10 04:29:57 +01:00
float GetCharacterX(struct Game* game, struct Character* character);
float GetCharacterY(struct Game* game, struct Character* character);
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);
bool IsCharacterHidden(struct Game* game, struct Character* character);
2016-08-29 23:44:15 +02:00
2016-07-04 00:56:45 +02:00
#endif