Stages can now be beat

This commit is contained in:
Juhani Krekelä 2022-01-15 16:16:42 +00:00
parent 220ee0e453
commit cfc00470f6
3 changed files with 37 additions and 1 deletions

View File

@ -2,7 +2,8 @@
.SUFFIXES: .inc .txt
NAME = platformer
TILES = grass_tile.inc dirt_tile.inc flag_tile.inc stage1_tile.inc stage2_tile.inc
TILES = grass_tile.inc dirt_tile.inc flag_tile.inc \
stage1_tile.inc stage2_tile.inc star_tile.inc
all: $(NAME)

View File

@ -16,6 +16,7 @@
#define STAGES 2
enum game_mode { TITLESCREEN, STAGE };
enum game_mode game_mode = TITLESCREEN;
bool stages_beat[STAGES];
#define PLAYFIELD_SIDE 100
#define TILE_SIDE 10
@ -28,6 +29,7 @@ enum palette {
GRASS_DARK,
FLAG_STEM,
FLAG_FLAG,
STAR_STAR,
ERROR,
};
static enum palette playfield[PLAYFIELD_SIDE * PLAYFIELD_SIDE];
@ -38,6 +40,7 @@ static enum palette playfield[PLAYFIELD_SIDE * PLAYFIELD_SIDE];
#include "stage1_tile.inc"
#include "stage2_tile.inc"
#include "star_tile.inc"
static char tilemap[] = " "
" "
@ -268,6 +271,18 @@ static void update_stage(struct timespec now, struct timespec dt_timespec) {
in_jump = jump_duration;
jump_start_y = player_y + jump_maxheight;
}
// Touching tiles
size_t midpoint_x = player_x + TILE_SIDE / 2;
size_t midpoint_y = player_y + TILE_SIDE / 2;
if (sample_tilemap(midpoint_x, midpoint_y) == '!') {
stages_beat[selection_index] = true;
if (selection_index < STAGES - 1)
selection_index++;
game_mode = TITLESCREEN;
initialize();
return;
}
}
static void update_titlescreen(struct timespec now, struct timespec dt_timespec) {
@ -332,6 +347,12 @@ static void draw_stage(void) {
static void draw_titlescreen(void) {
memset(playfield, 0, sizeof(playfield));
for (size_t i = 0; i < STAGES; i++) {
size_t x = i * TILE_SIDE + TILE_SIDE;
size_t y = 0;
if (stages_beat[i])
draw_tile(star_tile, x, y);
}
draw_tile(stage1_tile, 1 * TILE_SIDE, TILE_SIDE);
draw_tile(stage2_tile, 2 * TILE_SIDE, TILE_SIDE);
size_t underline_y = 2 * TILE_SIDE + 1;
@ -373,6 +394,7 @@ int main(int argc, char *argv[]) {
[GRASS_DARK] = make_color(100, 64, 0),
[FLAG_STEM] = make_color(0, 0, 0),
[FLAG_FLAG] = make_color(255, 0, 0),
[STAR_STAR] = make_color(255, 255, 0),
[ERROR] = make_color(255, 0, 255),
};

13
star_tile.txt Normal file
View File

@ -0,0 +1,13 @@
BG
xSTAR_STAR
----------
x
xxx
xxxxxxxxx
xxxxxxx
xxx
xxxxx
xx xx