mirror of https://git.sr.ht/~kikoodx/momento
Death and next level events
This commit is contained in:
parent
4afc7ce24b
commit
a296033f51
|
@ -30,7 +30,8 @@ enum { UP_LEFT, UP_RIGHT, DOWN_LEFT, DOWN_RIGHT };
|
|||
|
||||
struct Player player_init(void);
|
||||
void player_draw(struct Player player);
|
||||
void player_update(struct Player *player);
|
||||
/* return 1 if exit reached, -1 on death/reset and 0 otherwise */
|
||||
int player_update(struct Player *player);
|
||||
void player_collide(Tile collisions[COLLIDE_POINTS], int x, int y);
|
||||
int player_collide_tile(Tile collisions[COLLIDE_POINTS], int x, int y,
|
||||
Tile tile, int update);
|
||||
|
|
|
@ -7,5 +7,6 @@ enum {
|
|||
TILE_VOID,
|
||||
TILE_SOLID,
|
||||
TILE_START,
|
||||
TILE_END,
|
||||
TILE_EXIT,
|
||||
TILE_LETAL,
|
||||
};
|
||||
|
|
|
@ -14,7 +14,8 @@
|
|||
}
|
||||
#define PATH_PREFIX u"\\\\fls0\\mtem\\"
|
||||
|
||||
static const uint16_t filepaths[][32] = {PATH_PREFIX "0000.kble", {0}};
|
||||
static const uint16_t filepaths[][32] = {
|
||||
PATH_PREFIX "0000.kble", PATH_PREFIX "0001.kble", {0}};
|
||||
|
||||
/* globals are needed when using gint_switch() */
|
||||
struct Level level;
|
||||
|
|
20
src/main.c
20
src/main.c
|
@ -32,6 +32,7 @@ int main(void)
|
|||
{
|
||||
int i;
|
||||
int timer;
|
||||
int player_return_code;
|
||||
volatile int has_ticked = 1;
|
||||
|
||||
/* load level */
|
||||
|
@ -58,7 +59,24 @@ int main(void)
|
|||
has_ticked = 0;
|
||||
/* update */
|
||||
clearevents();
|
||||
player_update(&player);
|
||||
player_return_code = player_update(&player);
|
||||
switch (player_return_code) {
|
||||
case 1:
|
||||
level_id += 1;
|
||||
gint_switch(level_load);
|
||||
if (fatal_error == -1)
|
||||
PANIC(fatal_error_msg);
|
||||
player = player_init();
|
||||
break;
|
||||
case -1:
|
||||
gint_switch(level_load);
|
||||
if (fatal_error == -1)
|
||||
PANIC(fatal_error_msg);
|
||||
player = player_init();
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
/* draw */
|
||||
dclear(C_BLACK);
|
||||
|
|
|
@ -8,8 +8,10 @@
|
|||
|
||||
static void player_move(struct Player *player, int x, int y);
|
||||
|
||||
void player_update(struct Player *player)
|
||||
/* return 1 if exit reached, -1 on death/reset and 0 otherwise */
|
||||
int player_update(struct Player *player)
|
||||
{
|
||||
Tile collisions[COLLIDE_POINTS];
|
||||
const int on_ground =
|
||||
player_collide_solid(player->x, player->y + 1);
|
||||
|
||||
|
@ -88,6 +90,15 @@ void player_update(struct Player *player)
|
|||
/* move the player */
|
||||
player_move(player, 0, spd_y);
|
||||
player_move(player, spd_x, 0);
|
||||
|
||||
/* check for death and exit */
|
||||
if (player_collide_tile(collisions, player->x, player->y,
|
||||
TILE_EXIT, 1))
|
||||
return 1;
|
||||
if (player_collide_tile(collisions, player->x, player->y,
|
||||
TILE_LETAL, 0))
|
||||
return -1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void player_move(struct Player *player, int x, int y)
|
||||
|
|
Loading…
Reference in New Issue