Stages can now be beat
This commit is contained in:
parent
220ee0e453
commit
cfc00470f6
3
Makefile
3
Makefile
|
@ -2,7 +2,8 @@
|
||||||
.SUFFIXES: .inc .txt
|
.SUFFIXES: .inc .txt
|
||||||
|
|
||||||
NAME = platformer
|
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)
|
all: $(NAME)
|
||||||
|
|
||||||
|
|
22
platformer.c
22
platformer.c
|
@ -16,6 +16,7 @@
|
||||||
#define STAGES 2
|
#define STAGES 2
|
||||||
enum game_mode { TITLESCREEN, STAGE };
|
enum game_mode { TITLESCREEN, STAGE };
|
||||||
enum game_mode game_mode = TITLESCREEN;
|
enum game_mode game_mode = TITLESCREEN;
|
||||||
|
bool stages_beat[STAGES];
|
||||||
|
|
||||||
#define PLAYFIELD_SIDE 100
|
#define PLAYFIELD_SIDE 100
|
||||||
#define TILE_SIDE 10
|
#define TILE_SIDE 10
|
||||||
|
@ -28,6 +29,7 @@ enum palette {
|
||||||
GRASS_DARK,
|
GRASS_DARK,
|
||||||
FLAG_STEM,
|
FLAG_STEM,
|
||||||
FLAG_FLAG,
|
FLAG_FLAG,
|
||||||
|
STAR_STAR,
|
||||||
ERROR,
|
ERROR,
|
||||||
};
|
};
|
||||||
static enum palette playfield[PLAYFIELD_SIDE * PLAYFIELD_SIDE];
|
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 "stage1_tile.inc"
|
||||||
#include "stage2_tile.inc"
|
#include "stage2_tile.inc"
|
||||||
|
#include "star_tile.inc"
|
||||||
|
|
||||||
static char tilemap[] = " "
|
static char tilemap[] = " "
|
||||||
" "
|
" "
|
||||||
|
@ -268,6 +271,18 @@ static void update_stage(struct timespec now, struct timespec dt_timespec) {
|
||||||
in_jump = jump_duration;
|
in_jump = jump_duration;
|
||||||
jump_start_y = player_y + jump_maxheight;
|
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) {
|
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) {
|
static void draw_titlescreen(void) {
|
||||||
memset(playfield, 0, sizeof(playfield));
|
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(stage1_tile, 1 * TILE_SIDE, TILE_SIDE);
|
||||||
draw_tile(stage2_tile, 2 * TILE_SIDE, TILE_SIDE);
|
draw_tile(stage2_tile, 2 * TILE_SIDE, TILE_SIDE);
|
||||||
size_t underline_y = 2 * TILE_SIDE + 1;
|
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),
|
[GRASS_DARK] = make_color(100, 64, 0),
|
||||||
[FLAG_STEM] = make_color(0, 0, 0),
|
[FLAG_STEM] = make_color(0, 0, 0),
|
||||||
[FLAG_FLAG] = make_color(255, 0, 0),
|
[FLAG_FLAG] = make_color(255, 0, 0),
|
||||||
|
[STAR_STAR] = make_color(255, 255, 0),
|
||||||
[ERROR] = make_color(255, 0, 255),
|
[ERROR] = make_color(255, 0, 255),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,13 @@
|
||||||
|
BG
|
||||||
|
xSTAR_STAR
|
||||||
|
----------
|
||||||
|
|
||||||
|
|
||||||
|
x
|
||||||
|
xxx
|
||||||
|
xxxxxxxxx
|
||||||
|
xxxxxxx
|
||||||
|
xxx
|
||||||
|
xxxxx
|
||||||
|
xx xx
|
||||||
|
|
Loading…
Reference in New Issue