mirror of
https://gitlab.com/dosowisko.net/libsuperderpy.git
synced 2025-02-01 11:06:44 +01:00
revamp argument handling of timeline actions
This commit is contained in:
parent
f1e26219c4
commit
27ddfaafc9
3 changed files with 55 additions and 21 deletions
50
src/level.c
50
src/level.c
|
@ -25,8 +25,6 @@
|
|||
#include "level.h"
|
||||
#include "timeline.h"
|
||||
|
||||
int x = 0, x2 = 0;
|
||||
|
||||
void Level_Passed(struct Game *game) {
|
||||
if (game->level.current_level<6) {
|
||||
int available = atoi(GetConfigOptionDefault("MuffinAttack", "level", "1"));
|
||||
|
@ -51,24 +49,48 @@ void Level_Draw(struct Game *game) {
|
|||
}
|
||||
}
|
||||
|
||||
bool napis(struct Game *game, struct TM_Action *lol) {
|
||||
al_draw_text_with_shadow(game->font, al_map_rgb(255,255,255), x, 20, 0, "wat");
|
||||
x+=10;
|
||||
if (x>1000) { x=0; return true; }
|
||||
bool napis(struct Game *game, struct TM_Action *action, enum TM_ActionState state) {
|
||||
if (!action->arguments) {
|
||||
action->arguments = malloc(sizeof(struct TM_Arguments));
|
||||
action->arguments->value = malloc(sizeof(int));
|
||||
action->arguments->next = NULL;
|
||||
}
|
||||
int* tmp;
|
||||
tmp = (int*)action->arguments->value;
|
||||
if (state == TM_ACTIONSTATE_INIT) {
|
||||
*tmp = 0;
|
||||
} else if (state == TM_ACTIONSTATE_RUNNING) {
|
||||
al_draw_text_with_shadow(game->font, al_map_rgb(255,255,255), *tmp, 20, 0, "wat");
|
||||
*tmp+=10;
|
||||
if (*tmp>1000) { *tmp=0; return true; }
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool napis2(struct Game *game, struct TM_Action *lol) {
|
||||
al_draw_text_with_shadow(game->font, al_map_rgb(255,255,255), x2, 100, 0, "lol");
|
||||
x2+=5;
|
||||
if (x2>1000) { x2=0; return true; }
|
||||
bool napis2(struct Game *game, struct TM_Action *action, enum TM_ActionState state) {
|
||||
if (!action->arguments) {
|
||||
action->arguments = malloc(sizeof(struct TM_Arguments));
|
||||
action->arguments->value = malloc(sizeof(int));
|
||||
action->arguments->next = NULL;
|
||||
}
|
||||
int* tmp;
|
||||
tmp = (int*)action->arguments->value;
|
||||
if (state == TM_ACTIONSTATE_INIT) {
|
||||
*tmp = 0;
|
||||
} else if (state == TM_ACTIONSTATE_RUNNING) {
|
||||
al_draw_text_with_shadow(game->font, al_map_rgb(255,255,255), *tmp, 100, 0, "lol");
|
||||
*tmp+=5;
|
||||
if (*tmp>1000) { *tmp=0; return true; }
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool wyjscie(struct Game *game, struct TM_Action *lol) {
|
||||
Level_Passed(game);
|
||||
game->gamestate = GAMESTATE_LOADING;
|
||||
game->loadstate = GAMESTATE_MAP;
|
||||
bool wyjscie(struct Game *game, struct TM_Action *action, enum TM_ActionState state) {
|
||||
if (state == TM_ACTIONSTATE_DESTROY) {
|
||||
Level_Passed(game);
|
||||
game->gamestate = GAMESTATE_LOADING;
|
||||
game->loadstate = GAMESTATE_MAP;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
@ -42,9 +42,11 @@ void TM_Process() {
|
|||
// if returns true, then delete it
|
||||
if (queue) {
|
||||
if (*queue->function) {
|
||||
if ((*queue->function)(game, queue)) {
|
||||
if ((*queue->function)(game, queue, TM_ACTIONSTATE_RUNNING)) {
|
||||
(*queue->function)(game, queue, TM_ACTIONSTATE_DESTROY);
|
||||
struct TM_Action *tmp = queue;
|
||||
queue = queue->next;
|
||||
if (tmp->arguments) free(tmp->arguments); // TODO: cascade destroy
|
||||
free(tmp);
|
||||
}
|
||||
} else {
|
||||
|
@ -57,7 +59,8 @@ void TM_Process() {
|
|||
while (pom!=NULL) {
|
||||
if (pom->active) {
|
||||
if (*pom->function) {
|
||||
if ((*pom->function)(game, pom)) {
|
||||
if ((*pom->function)(game, pom, TM_ACTIONSTATE_RUNNING)) {
|
||||
(*pom->function)(game, pom, TM_ACTIONSTATE_DESTROY);
|
||||
if (tmp) {
|
||||
tmp->next = pom->next;
|
||||
} else {
|
||||
|
@ -72,6 +75,7 @@ void TM_Process() {
|
|||
tmp = pom;
|
||||
pom = pom->next;
|
||||
} else {
|
||||
if (pom->arguments) free(pom->arguments); // TODO: cascade destroy
|
||||
free(pom);
|
||||
tmp2 = tmp;
|
||||
if (!tmp) pom=background->next;
|
||||
|
@ -88,7 +92,7 @@ void TM_HandleEvent(ALLEGRO_EVENT *ev) {
|
|||
|
||||
}
|
||||
|
||||
void TM_AddAction(bool (*func)(struct Game*, struct TM_Action*), struct TM_Arguments* args) {
|
||||
void TM_AddAction(bool (*func)(struct Game*, struct TM_Action*, enum TM_ActionState), struct TM_Arguments* args) {
|
||||
struct TM_Action *action = malloc(sizeof(struct TM_Action));
|
||||
if (queue) {
|
||||
struct TM_Action *pom = queue;
|
||||
|
@ -105,9 +109,10 @@ void TM_AddAction(bool (*func)(struct Game*, struct TM_Action*), struct TM_Argum
|
|||
action->timer = NULL;
|
||||
action->active = false;
|
||||
action->delay = 0;
|
||||
(*action->function)(game, action, TM_ACTIONSTATE_INIT);
|
||||
}
|
||||
|
||||
void TM_AddBackgroundAction(bool (*func)(struct Game*, struct TM_Action*), struct TM_Arguments* args, int delay) {
|
||||
void TM_AddBackgroundAction(bool (*func)(struct Game*, struct TM_Action*, enum TM_ActionState), struct TM_Arguments* args, int delay) {
|
||||
struct TM_Action *action = malloc(sizeof(struct TM_Action));
|
||||
if (background) {
|
||||
struct TM_Action *pom = background;
|
||||
|
@ -124,6 +129,7 @@ void TM_AddBackgroundAction(bool (*func)(struct Game*, struct TM_Action*), struc
|
|||
action->timer = NULL;
|
||||
action->active = true;
|
||||
action->delay = 0;
|
||||
(*action->function)(game, action, TM_ACTIONSTATE_INIT);
|
||||
}
|
||||
|
||||
void TM_AddDelay(int delay) {
|
||||
|
|
|
@ -21,6 +21,12 @@
|
|||
|
||||
#include "main.h"
|
||||
|
||||
enum TM_ActionState {
|
||||
TM_ACTIONSTATE_INIT,
|
||||
TM_ACTIONSTATE_RUNNING,
|
||||
TM_ACTIONSTATE_DESTROY
|
||||
};
|
||||
|
||||
struct TM_Arguments {
|
||||
void *value;
|
||||
struct TM_Arguments *next;
|
||||
|
@ -28,7 +34,7 @@ struct TM_Arguments {
|
|||
};
|
||||
|
||||
struct TM_Action {
|
||||
bool (*function)(struct Game*, struct TM_Action*);
|
||||
bool (*function)(struct Game*, struct TM_Action*, enum TM_ActionState);
|
||||
struct TM_Arguments *arguments;
|
||||
ALLEGRO_TIMER *timer;
|
||||
bool active;
|
||||
|
@ -40,8 +46,8 @@ struct TM_Action {
|
|||
void TM_Init(struct Game* game);
|
||||
void TM_Process();
|
||||
void TM_HandleEvent(ALLEGRO_EVENT *ev);
|
||||
void TM_AddAction(bool (*func)(struct Game*, struct TM_Action*), struct TM_Arguments* args);
|
||||
void TM_AddBackgroundAction(bool (*func)(struct Game*, struct TM_Action*), struct TM_Arguments* args, int delay);
|
||||
void TM_AddAction(bool (*func)(struct Game*, struct TM_Action*, enum TM_ActionState), struct TM_Arguments* args);
|
||||
void TM_AddBackgroundAction(bool (*func)(struct Game*, struct TM_Action*, enum TM_ActionState), struct TM_Arguments* args, int delay);
|
||||
void TM_AddDelay(int delay);
|
||||
void TM_Pause(bool pause);
|
||||
void TM_Destroy();
|
||||
|
|
Loading…
Reference in a new issue