mirror of
https://gitlab.com/dosowisko.net/libsuperderpy.git
synced 2025-03-04 17:21:27 +01:00
moar work on timeline
This commit is contained in:
parent
3e17070298
commit
f1e26219c4
5 changed files with 173 additions and 18 deletions
42
src/level.c
42
src/level.c
|
@ -23,6 +23,9 @@
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
#include "pause.h"
|
#include "pause.h"
|
||||||
#include "level.h"
|
#include "level.h"
|
||||||
|
#include "timeline.h"
|
||||||
|
|
||||||
|
int x = 0, x2 = 0;
|
||||||
|
|
||||||
void Level_Passed(struct Game *game) {
|
void Level_Passed(struct Game *game) {
|
||||||
if (game->level.current_level<6) {
|
if (game->level.current_level<6) {
|
||||||
|
@ -44,11 +47,42 @@ void Level_Draw(struct Game *game) {
|
||||||
if (game->level.current_level!=1) Moonwalk_Draw(game);
|
if (game->level.current_level!=1) Moonwalk_Draw(game);
|
||||||
else {
|
else {
|
||||||
al_clear_to_color(al_map_rgb(0,0,0));
|
al_clear_to_color(al_map_rgb(0,0,0));
|
||||||
|
TM_Process();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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; }
|
||||||
|
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; }
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool wyjscie(struct Game *game, struct TM_Action *lol) {
|
||||||
|
Level_Passed(game);
|
||||||
|
game->gamestate = GAMESTATE_LOADING;
|
||||||
|
game->loadstate = GAMESTATE_MAP;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
void Level_Load(struct Game *game) {
|
void Level_Load(struct Game *game) {
|
||||||
|
al_clear_to_color(al_map_rgb(0,0,0));
|
||||||
if (game->level.current_level!=1) Moonwalk_Load(game);
|
if (game->level.current_level!=1) Moonwalk_Load(game);
|
||||||
|
else {
|
||||||
|
TM_Init(game);
|
||||||
|
TM_AddAction(&napis, NULL);
|
||||||
|
TM_AddAction(&napis, NULL);
|
||||||
|
TM_AddAction(&napis, NULL);
|
||||||
|
TM_AddBackgroundAction(&napis2, NULL, 0);
|
||||||
|
TM_AddAction(&wyjscie, NULL);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int Level_Keydown(struct Game *game, ALLEGRO_EVENT *ev) {
|
int Level_Keydown(struct Game *game, ALLEGRO_EVENT *ev) {
|
||||||
|
@ -61,6 +95,10 @@ int Level_Keydown(struct Game *game, ALLEGRO_EVENT *ev) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Level_ProcessLogic(struct Game *game, ALLEGRO_EVENT *ev) {
|
||||||
|
if (game->level.current_level==1) TM_HandleEvent(ev);
|
||||||
|
}
|
||||||
|
|
||||||
void Level_Preload(struct Game *game) {
|
void Level_Preload(struct Game *game) {
|
||||||
Pause_Preload(game);
|
Pause_Preload(game);
|
||||||
if (game->level.current_level!=1) Moonwalk_Preload(game);
|
if (game->level.current_level!=1) Moonwalk_Preload(game);
|
||||||
|
@ -69,7 +107,9 @@ void Level_Preload(struct Game *game) {
|
||||||
void Level_Unload(struct Game *game) {
|
void Level_Unload(struct Game *game) {
|
||||||
Pause_Unload_Real(game);
|
Pause_Unload_Real(game);
|
||||||
if (game->level.current_level!=1) Moonwalk_Unload(game);
|
if (game->level.current_level!=1) Moonwalk_Unload(game);
|
||||||
else Level_Passed(game);
|
else {
|
||||||
|
TM_Destroy();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Level_UnloadBitmaps(struct Game *game) {
|
void Level_UnloadBitmaps(struct Game *game) {
|
||||||
|
|
|
@ -25,6 +25,7 @@ void Level_Draw(struct Game *game);
|
||||||
void Level_Preload(struct Game *game);
|
void Level_Preload(struct Game *game);
|
||||||
void Level_Unload(struct Game *game);
|
void Level_Unload(struct Game *game);
|
||||||
void Level_Load(struct Game *game);
|
void Level_Load(struct Game *game);
|
||||||
|
void Level_ProcessLogic(struct Game *game, ALLEGRO_EVENT *ev);
|
||||||
int Level_Keydown(struct Game *game, ALLEGRO_EVENT *ev);
|
int Level_Keydown(struct Game *game, ALLEGRO_EVENT *ev);
|
||||||
void Level_UnloadBitmaps(struct Game *game);
|
void Level_UnloadBitmaps(struct Game *game);
|
||||||
void Level_PreloadBitmaps(struct Game *game);
|
void Level_PreloadBitmaps(struct Game *game);
|
|
@ -391,7 +391,7 @@ int main(int argc, char **argv){
|
||||||
ALLEGRO_EVENT ev;
|
ALLEGRO_EVENT ev;
|
||||||
al_wait_for_event(game.event_queue, &ev);
|
al_wait_for_event(game.event_queue, &ev);
|
||||||
|
|
||||||
if(ev.type == ALLEGRO_EVENT_TIMER) {
|
if ((ev.type == ALLEGRO_EVENT_TIMER) && (ev.timer.source == game.timer)) {
|
||||||
redraw = true;
|
redraw = true;
|
||||||
}
|
}
|
||||||
else if(ev.type == ALLEGRO_EVENT_DISPLAY_CLOSE) {
|
else if(ev.type == ALLEGRO_EVENT_DISPLAY_CLOSE) {
|
||||||
|
@ -418,6 +418,10 @@ int main(int argc, char **argv){
|
||||||
game.gamestate = GAMESTATE_LOADING;
|
game.gamestate = GAMESTATE_LOADING;
|
||||||
game.loadstate = GAMESTATE_MENU;
|
game.loadstate = GAMESTATE_MENU;
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
if (game.gamestate == GAMESTATE_LEVEL) {
|
||||||
|
Level_ProcessLogic(&game, &ev);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(redraw && al_is_event_queue_empty(game.event_queue)) {
|
if(redraw && al_is_event_queue_empty(game.event_queue)) {
|
||||||
|
|
114
src/timeline.c
114
src/timeline.c
|
@ -19,35 +19,129 @@
|
||||||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
*/
|
*/
|
||||||
#include <allegro5/allegro.h>
|
#include <allegro5/allegro.h>
|
||||||
|
#include <stdio.h>
|
||||||
#include "timeline.h"
|
#include "timeline.h"
|
||||||
|
|
||||||
int lastid;
|
unsigned int lastid;
|
||||||
|
struct Game* game = NULL;
|
||||||
|
struct TM_Action *queue, *background;
|
||||||
|
bool paused;
|
||||||
|
|
||||||
void TM_Init() {
|
void TM_Init(struct Game* g) {
|
||||||
|
game = g;
|
||||||
|
lastid = 0;
|
||||||
|
queue = NULL;
|
||||||
|
background = NULL;
|
||||||
|
paused = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
void TM_Process() {
|
||||||
|
if (!game) return;
|
||||||
|
if (paused) return;
|
||||||
|
// process first element from queue
|
||||||
|
// if returns true, then delete it
|
||||||
|
if (queue) {
|
||||||
|
if (*queue->function) {
|
||||||
|
if ((*queue->function)(game, queue)) {
|
||||||
|
struct TM_Action *tmp = queue;
|
||||||
|
queue = queue->next;
|
||||||
|
free(tmp);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// TODO: handle delay
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// process all elements from background marked as active
|
||||||
|
struct TM_Action *tmp, *tmp2, *pom = background;
|
||||||
|
tmp = NULL;
|
||||||
|
while (pom!=NULL) {
|
||||||
|
if (pom->active) {
|
||||||
|
if (*pom->function) {
|
||||||
|
if ((*pom->function)(game, pom)) {
|
||||||
|
if (tmp) {
|
||||||
|
tmp->next = pom->next;
|
||||||
|
} else {
|
||||||
|
background = pom->next;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// TODO: handle delay
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ((!tmp) || (tmp->next==pom)) {
|
||||||
|
tmp = pom;
|
||||||
|
pom = pom->next;
|
||||||
|
} else {
|
||||||
|
free(pom);
|
||||||
|
tmp2 = tmp;
|
||||||
|
if (!tmp) pom=background->next;
|
||||||
|
else pom=tmp->next;
|
||||||
|
tmp = tmp2;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void TM_HandleEvent(ALLEGRO_EVENT *ev) {
|
||||||
|
if (!game) return;
|
||||||
|
if (paused) return;
|
||||||
|
// TODO: mark action as active
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void TM_AddAction(void *func, struct TM_Arguments* args) {
|
void TM_AddAction(bool (*func)(struct Game*, struct TM_Action*), struct TM_Arguments* args) {
|
||||||
|
struct TM_Action *action = malloc(sizeof(struct TM_Action));
|
||||||
|
if (queue) {
|
||||||
|
struct TM_Action *pom = queue;
|
||||||
|
while (pom->next!=NULL) {
|
||||||
|
pom=pom->next;
|
||||||
|
}
|
||||||
|
pom->next = action;
|
||||||
|
} else {
|
||||||
|
queue = action;
|
||||||
|
}
|
||||||
|
action->next = NULL;
|
||||||
|
action->function = func;
|
||||||
|
action->arguments = args;
|
||||||
|
action->timer = NULL;
|
||||||
|
action->active = false;
|
||||||
|
action->delay = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void TM_AddBackgroundAction(void *func, struct TM_Arguments* args, int delay) {
|
void TM_AddBackgroundAction(bool (*func)(struct Game*, struct TM_Action*), struct TM_Arguments* args, int delay) {
|
||||||
|
struct TM_Action *action = malloc(sizeof(struct TM_Action));
|
||||||
|
if (background) {
|
||||||
|
struct TM_Action *pom = background;
|
||||||
|
while (pom->next!=NULL) {
|
||||||
|
pom=pom->next;
|
||||||
|
}
|
||||||
|
pom->next = action;
|
||||||
|
} else {
|
||||||
|
background = action;
|
||||||
|
}
|
||||||
|
action->next = NULL;
|
||||||
|
action->function = func;
|
||||||
|
action->arguments = args;
|
||||||
|
action->timer = NULL;
|
||||||
|
action->active = true;
|
||||||
|
action->delay = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void TM_AddDelay(int delay) {
|
void TM_AddDelay(int delay) {
|
||||||
|
TM_AddAction(NULL, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
void TM_Pause(bool pause) {
|
void TM_Pause(bool pause) {
|
||||||
|
paused = pause;
|
||||||
|
// TODO: pause timers
|
||||||
}
|
}
|
||||||
|
|
||||||
void TM_Destroy() {
|
void TM_Destroy() {
|
||||||
|
// TODO: delete everything from queues
|
||||||
|
// maybe delete all args too?
|
||||||
|
game = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct TM_Arguments* TM_AddToArgs() {
|
struct TM_Arguments* TM_AddToArgs(struct TM_Arguments* args, void* arg) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -19,15 +19,31 @@
|
||||||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
struct TM_Arguments {
|
#include "main.h"
|
||||||
|
|
||||||
|
struct TM_Arguments {
|
||||||
|
void *value;
|
||||||
|
struct TM_Arguments *next;
|
||||||
|
//*prev;
|
||||||
};
|
};
|
||||||
|
|
||||||
void TM_Init();
|
struct TM_Action {
|
||||||
void TM_AddAction(void *func, struct TM_Arguments* args);
|
bool (*function)(struct Game*, struct TM_Action*);
|
||||||
void TM_AddBackgroundAction(void *func, struct TM_Arguments* args, int delay);
|
struct TM_Arguments *arguments;
|
||||||
|
ALLEGRO_TIMER *timer;
|
||||||
|
bool active;
|
||||||
|
int delay;
|
||||||
|
struct TM_Action *next;
|
||||||
|
//*prev;
|
||||||
|
};
|
||||||
|
|
||||||
|
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_AddDelay(int delay);
|
void TM_AddDelay(int delay);
|
||||||
void TM_Pause(bool pause);
|
void TM_Pause(bool pause);
|
||||||
void TM_Destroy();
|
void TM_Destroy();
|
||||||
struct TM_Arguments* TM_AddToArgs();
|
struct TM_Arguments* TM_AddToArgs(struct TM_Arguments* args, void* arg);
|
||||||
void TM_DestroyArgs(struct TM_Arguments* args);
|
void TM_DestroyArgs(struct TM_Arguments* args);
|
Loading…
Add table
Reference in a new issue