mirror of
https://gitlab.com/dosowisko.net/libsuperderpy.git
synced 2025-02-01 19:16:44 +01:00
implement obstracles callbacks
This commit is contained in:
parent
d4c5028216
commit
b6d8136609
2 changed files with 28 additions and 8 deletions
19
src/level.c
19
src/level.c
|
@ -72,6 +72,20 @@ bool Fly(struct Game *game, struct TM_Action *action, enum TM_ActionState state)
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Obst_MoveUpDown(struct Game *game, struct Obstracle *obstracle) {
|
||||||
|
if (obstracle->data) {
|
||||||
|
obstracle->y -= 0.5;
|
||||||
|
if (obstracle->y<=0) {
|
||||||
|
obstracle->data=NULL;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
obstracle->y += 0.5;
|
||||||
|
if (obstracle->y>=100) {
|
||||||
|
obstracle->data++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
bool GenerateObstracles(struct Game *game, struct TM_Action *action, enum TM_ActionState state) {
|
bool GenerateObstracles(struct Game *game, struct TM_Action *action, enum TM_ActionState state) {
|
||||||
/*float* tmp; bool* in;*/
|
/*float* tmp; bool* in;*/
|
||||||
int* count;
|
int* count;
|
||||||
|
@ -98,6 +112,8 @@ bool GenerateObstracles(struct Game *game, struct TM_Action *action, enum TM_Act
|
||||||
obst->speed = 0;
|
obst->speed = 0;
|
||||||
obst->bitmap = game->level.obst_bmps.pie;
|
obst->bitmap = game->level.obst_bmps.pie;
|
||||||
obst->callback = NULL;
|
obst->callback = NULL;
|
||||||
|
obst->data = NULL;
|
||||||
|
if (rand()%100<=50) obst->callback=Obst_MoveUpDown;
|
||||||
if (game->level.obstracles) {
|
if (game->level.obstracles) {
|
||||||
game->level.obstracles->prev = obst;
|
game->level.obstracles->prev = obst;
|
||||||
obst->next = game->level.obstracles;
|
obst->next = game->level.obstracles;
|
||||||
|
@ -172,8 +188,9 @@ void Level_Draw(struct Game *game) {
|
||||||
if (tmp->x > -10) {
|
if (tmp->x > -10) {
|
||||||
al_draw_bitmap(tmp->bitmap, (tmp->x/100.0)*al_get_display_width(game->display), (tmp->y/100.0)*al_get_display_height(game->display), 0);
|
al_draw_bitmap(tmp->bitmap, (tmp->x/100.0)*al_get_display_width(game->display), (tmp->y/100.0)*al_get_display_height(game->display), 0);
|
||||||
tmp->x -= game->level.speed*310;
|
tmp->x -= game->level.speed*310;
|
||||||
|
if (tmp->callback) tmp->callback(game, tmp);
|
||||||
} else {
|
} else {
|
||||||
/* Delete from queue... */
|
/* TODO: Delete from queue... */
|
||||||
}
|
}
|
||||||
tmp = tmp->next;
|
tmp = tmp->next;
|
||||||
}
|
}
|
||||||
|
|
17
src/main.h
17
src/main.h
|
@ -50,13 +50,7 @@ struct Moonwalk {
|
||||||
double derpy_pos; /*!< Position of Derpy on screen. */
|
double derpy_pos; /*!< Position of Derpy on screen. */
|
||||||
};
|
};
|
||||||
|
|
||||||
struct Obstracle {
|
struct Obstracle;
|
||||||
ALLEGRO_BITMAP *bitmap;
|
|
||||||
float x, y, speed;
|
|
||||||
int points;
|
|
||||||
void *callback;
|
|
||||||
struct Obstracle *prev, *next;
|
|
||||||
};
|
|
||||||
|
|
||||||
/*! \brief Resources used by Level state. */
|
/*! \brief Resources used by Level state. */
|
||||||
struct Level {
|
struct Level {
|
||||||
|
@ -223,6 +217,15 @@ struct Game {
|
||||||
} audio;
|
} audio;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct Obstracle {
|
||||||
|
ALLEGRO_BITMAP *bitmap;
|
||||||
|
float x, y, speed;
|
||||||
|
int points;
|
||||||
|
void (*callback)(struct Game*, struct Obstracle*);
|
||||||
|
void *data;
|
||||||
|
struct Obstracle *prev, *next;
|
||||||
|
};
|
||||||
|
|
||||||
/*! \brief Draws text with shadow.
|
/*! \brief Draws text with shadow.
|
||||||
*
|
*
|
||||||
* Draws given text two times: once with color (0,0,0,128) and 1px off in both x and y axis,
|
* Draws given text two times: once with color (0,0,0,128) and 1px off in both x and y axis,
|
||||||
|
|
Loading…
Reference in a new issue