mirror of
https://gitlab.com/dosowisko.net/libsuperderpy.git
synced 2025-03-04 09:11:27 +01:00
rumina hacks 3
This commit is contained in:
parent
aa1f7f3ab9
commit
c85381644c
6 changed files with 48 additions and 20 deletions
|
@ -238,6 +238,7 @@ SYMBOL_EXPORT void SetCharacterPivotPoint(struct Game* game, struct Character* c
|
||||||
character->pivotY = y;
|
character->pivotY = y;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: coords are centered (pivot-related) or top left?
|
||||||
SYMBOL_EXPORT void DrawCharacter(struct Game* game, struct Character* character) {
|
SYMBOL_EXPORT void DrawCharacter(struct Game* game, struct Character* character) {
|
||||||
int w = al_get_bitmap_width(character->bitmap), h = al_get_bitmap_height(character->bitmap);
|
int w = al_get_bitmap_width(character->bitmap), h = al_get_bitmap_height(character->bitmap);
|
||||||
al_draw_tinted_scaled_rotated_bitmap(character->bitmap, character->tint,
|
al_draw_tinted_scaled_rotated_bitmap(character->bitmap, character->tint,
|
||||||
|
@ -268,23 +269,48 @@ SYMBOL_EXPORT float GetCharacterY(struct Game* game, struct Character* character
|
||||||
return character->y * GetCharacterConfineY(game, character);
|
return character->y * GetCharacterConfineY(game, character);
|
||||||
}
|
}
|
||||||
|
|
||||||
SYMBOL_EXPORT bool IsOnCharacter(struct Game* game, struct Character* character, int x, int y, bool pixelperfect) {
|
/*
|
||||||
int x1 = GetCharacterX(game, character), y1 = GetCharacterY(game, character);
|
static void SortTwoFloats(float* v1, float* v2) {
|
||||||
|
float pom = *v1;
|
||||||
|
if (v1 > v2) {
|
||||||
|
*v1 = *v2;
|
||||||
|
*v2 = pom;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
SYMBOL_EXPORT bool IsOnCharacter(struct Game* game, struct Character* character, float x, float y, bool pixelperfect) {
|
||||||
|
// TODO: fucking rework
|
||||||
|
|
||||||
int w = al_get_bitmap_width(character->bitmap), h = al_get_bitmap_height(character->bitmap);
|
int w = al_get_bitmap_width(character->bitmap), h = al_get_bitmap_height(character->bitmap);
|
||||||
int x2 = x1 + w, y2 = y1 + h;
|
float x1 = GetCharacterX(game, character), y1 = GetCharacterY(game, character);
|
||||||
|
float x2 = x1 + w, y2 = y1 + h;
|
||||||
|
|
||||||
bool test = ((x >= x1) && (x <= x2) && (y >= y1) && (y <= y2));
|
/* float scalex = character->scaleX;
|
||||||
|
float scaley = character->scaleY;
|
||||||
if (test && pixelperfect) {
|
|
||||||
// TODO: handle scale and rotation
|
|
||||||
x -= x1;
|
|
||||||
y -= y1;
|
|
||||||
if (character->flipX) {
|
if (character->flipX) {
|
||||||
x = w - x;
|
scalex *= -1;
|
||||||
}
|
}
|
||||||
if (character->flipY) {
|
if (character->flipY) {
|
||||||
y = w - y;
|
scaley *= -1;
|
||||||
}
|
}
|
||||||
|
ALLEGRO_TRANSFORM transform;
|
||||||
|
al_identity_transform(&transform);
|
||||||
|
al_translate_transform(&transform, -character->pivotX * w, -character->pivotY * h);
|
||||||
|
al_scale_transform(&transform, scalex, scaley);
|
||||||
|
al_translate_transform(&transform, character->pivotX * w, character->pivotY * h);
|
||||||
|
al_transform_coordinates(&transform, &x1, &y1);
|
||||||
|
al_transform_coordinates(&transform, &x2, &y2);
|
||||||
|
SortTwoFloats(&x1, &x2);
|
||||||
|
SortTwoFloats(&y1, &y2);
|
||||||
|
*/
|
||||||
|
bool test = ((x >= x1) && (x <= x2) && (y >= y1) && (y <= y2));
|
||||||
|
|
||||||
|
//al_transform_coordinates(&transform, &x, &y);
|
||||||
|
|
||||||
|
if (test && pixelperfect) {
|
||||||
|
x -= x1;
|
||||||
|
y -= y1;
|
||||||
ALLEGRO_COLOR color = al_get_pixel(character->bitmap, x, y);
|
ALLEGRO_COLOR color = al_get_pixel(character->bitmap, x, y);
|
||||||
return (color.a > 0.0);
|
return (color.a > 0.0);
|
||||||
}
|
}
|
||||||
|
|
|
@ -105,6 +105,6 @@ float GetCharacterY(struct Game* game, struct Character* character);
|
||||||
int GetCharacterConfineX(struct Game* game, struct Character* character);
|
int GetCharacterConfineX(struct Game* game, struct Character* character);
|
||||||
int GetCharacterConfineY(struct Game* game, struct Character* character);
|
int GetCharacterConfineY(struct Game* game, struct Character* character);
|
||||||
|
|
||||||
bool IsOnCharacter(struct Game* game, struct Character* character, int x, int y, bool pixelperfect);
|
bool IsOnCharacter(struct Game* game, struct Character* character, float x, float y, bool pixelperfect);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -243,7 +243,7 @@ SYMBOL_INTERNAL void GamestateProgress(struct Game* game) {
|
||||||
float progress = ((game->_priv.loading.progress / progressCount) / (float)game->_priv.loading.toLoad) + (game->_priv.loading.loaded / (float)game->_priv.loading.toLoad);
|
float progress = ((game->_priv.loading.progress / progressCount) / (float)game->_priv.loading.toLoad) + (game->_priv.loading.loaded / (float)game->_priv.loading.toLoad);
|
||||||
game->loading_progress = progress;
|
game->loading_progress = progress;
|
||||||
if (game->config.debug) {
|
if (game->config.debug) {
|
||||||
PrintConsole(game, "[%s] Progress: %d% (%d/%d)", tmp->name, (int)(progress * 100), game->_priv.loading.progress, *(tmp->api->Gamestate_ProgressCount));
|
PrintConsole(game, "[%s] Progress: %d%% (%d/%d)", tmp->name, (int)(progress * 100), game->_priv.loading.progress, *(tmp->api->Gamestate_ProgressCount));
|
||||||
}
|
}
|
||||||
#ifdef LIBSUPERDERPY_SINGLE_THREAD
|
#ifdef LIBSUPERDERPY_SINGLE_THREAD
|
||||||
DrawGamestates(game);
|
DrawGamestates(game);
|
||||||
|
@ -368,6 +368,7 @@ SYMBOL_INTERNAL struct libsuperderpy_list* RemoveFromList(struct libsuperderpy_l
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: maybe make external?
|
||||||
SYMBOL_INTERNAL void* AddGarbage(struct Game* game, void* data) {
|
SYMBOL_INTERNAL void* AddGarbage(struct Game* game, void* data) {
|
||||||
game->_priv.garbage = AddToList(game->_priv.garbage, data);
|
game->_priv.garbage = AddToList(game->_priv.garbage, data);
|
||||||
return data;
|
return data;
|
||||||
|
|
|
@ -459,7 +459,7 @@ SYMBOL_INTERNAL void libsuperderpy_mainloop(void* g) {
|
||||||
game->_priv.timestamp += delta;
|
game->_priv.timestamp += delta;
|
||||||
delta /= ALLEGRO_BPS_TO_SECS(al_get_timer_speed(game->_priv.timer) / (1 / 60.f));
|
delta /= ALLEGRO_BPS_TO_SECS(al_get_timer_speed(game->_priv.timer) / (1 / 60.f));
|
||||||
LogicGamestates(game, delta);
|
LogicGamestates(game, delta);
|
||||||
redraw = true;
|
//redraw = true;
|
||||||
|
|
||||||
DrawGamestates(game);
|
DrawGamestates(game);
|
||||||
DrawConsole(game);
|
DrawConsole(game);
|
||||||
|
|
|
@ -190,6 +190,7 @@ SYMBOL_EXPORT ALLEGRO_BITMAP* LoadScaledBitmap(struct Game* game, char* filename
|
||||||
}
|
}
|
||||||
|
|
||||||
SYMBOL_EXPORT void FatalError(struct Game* game, bool exit, char* format, ...) {
|
SYMBOL_EXPORT void FatalError(struct Game* game, bool exit, char* format, ...) {
|
||||||
|
// TODO: interrupt and take over loading thread when it happens
|
||||||
char text[1024] = {0};
|
char text[1024] = {0};
|
||||||
PrintConsole(game, "Fatal Error, displaying Blue Screen of Derp...");
|
PrintConsole(game, "Fatal Error, displaying Blue Screen of Derp...");
|
||||||
va_list vl;
|
va_list vl;
|
||||||
|
@ -294,7 +295,7 @@ SYMBOL_EXPORT void FatalError(struct Game* game, bool exit, char* format, ...) {
|
||||||
al_use_transform(&game->projection);
|
al_use_transform(&game->projection);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void TestPath(char* filename, char* subpath, char** result) {
|
static void TestPath(const char* filename, const char* subpath, char** result) {
|
||||||
if (*result) { return; } //already found
|
if (*result) { return; } //already found
|
||||||
ALLEGRO_PATH* tail = al_create_path(filename);
|
ALLEGRO_PATH* tail = al_create_path(filename);
|
||||||
ALLEGRO_PATH* path = al_get_standard_path(ALLEGRO_RESOURCES_PATH);
|
ALLEGRO_PATH* path = al_get_standard_path(ALLEGRO_RESOURCES_PATH);
|
||||||
|
@ -310,7 +311,7 @@ static void TestPath(char* filename, char* subpath, char** result) {
|
||||||
al_destroy_path(path);
|
al_destroy_path(path);
|
||||||
}
|
}
|
||||||
|
|
||||||
SYMBOL_EXPORT char* GetGameName(struct Game* game, char* format) {
|
SYMBOL_EXPORT char* GetGameName(struct Game* game, const char* format) {
|
||||||
char* result = malloc(sizeof(char) * 255);
|
char* result = malloc(sizeof(char) * 255);
|
||||||
SUPPRESS_WARNING("-Wformat-nonliteral")
|
SUPPRESS_WARNING("-Wformat-nonliteral")
|
||||||
snprintf(result, 255, format, game->name);
|
snprintf(result, 255, format, game->name);
|
||||||
|
@ -318,7 +319,7 @@ SYMBOL_EXPORT char* GetGameName(struct Game* game, char* format) {
|
||||||
return AddGarbage(game, result);
|
return AddGarbage(game, result);
|
||||||
}
|
}
|
||||||
|
|
||||||
static char* TestDataFilePath(struct Game* game, char* filename) {
|
static char* TestDataFilePath(struct Game* game, const char* filename) {
|
||||||
char* result = NULL;
|
char* result = NULL;
|
||||||
|
|
||||||
TestPath(filename, "data/", &result);
|
TestPath(filename, "data/", &result);
|
||||||
|
@ -344,7 +345,7 @@ static char* TestDataFilePath(struct Game* game, char* filename) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
SYMBOL_EXPORT char* GetDataFilePath(struct Game* game, char* filename) {
|
SYMBOL_EXPORT char* GetDataFilePath(struct Game* game, const char* filename) {
|
||||||
char* result = 0;
|
char* result = 0;
|
||||||
|
|
||||||
#ifdef ALLEGRO_ANDROID
|
#ifdef ALLEGRO_ANDROID
|
||||||
|
|
|
@ -59,9 +59,9 @@ void ScaleBitmap(ALLEGRO_BITMAP* source, int width, int height);
|
||||||
ALLEGRO_BITMAP* LoadScaledBitmap(struct Game* game, char* filename, int width, int height);
|
ALLEGRO_BITMAP* LoadScaledBitmap(struct Game* game, char* filename, int width, int height);
|
||||||
|
|
||||||
/*! \brief Finds path for data file. */
|
/*! \brief Finds path for data file. */
|
||||||
char* GetDataFilePath(struct Game* game, char* filename);
|
char* GetDataFilePath(struct Game* game, const char* filename);
|
||||||
|
|
||||||
char* GetGameName(struct Game* game, char* format);
|
char* GetGameName(struct Game* game, const char* format);
|
||||||
|
|
||||||
/*! \brief Print some message on game console.
|
/*! \brief Print some message on game console.
|
||||||
*
|
*
|
||||||
|
|
Loading…
Add table
Reference in a new issue