Switchable tiles
This commit is contained in:
parent
67572c9a69
commit
922d49d6a0
2
Makefile
2
Makefile
|
@ -3,6 +3,8 @@
|
||||||
|
|
||||||
NAME = platformer
|
NAME = platformer
|
||||||
TILES = grass_tile.inc dirt_tile.inc flag_tile.inc \
|
TILES = grass_tile.inc dirt_tile.inc flag_tile.inc \
|
||||||
|
switch1_off_tile.inc switch1_on_tile.inc \
|
||||||
|
tile1_off_tile.inc tile1_on_tile.inc \
|
||||||
stage1_tile.inc stage2_tile.inc star_tile.inc
|
stage1_tile.inc stage2_tile.inc star_tile.inc
|
||||||
|
|
||||||
all: $(NAME)
|
all: $(NAME)
|
||||||
|
|
33
platformer.c
33
platformer.c
|
@ -29,6 +29,9 @@ enum palette {
|
||||||
GRASS_DARK,
|
GRASS_DARK,
|
||||||
FLAG_STEM,
|
FLAG_STEM,
|
||||||
FLAG_FLAG,
|
FLAG_FLAG,
|
||||||
|
SWITCH_SWITCH,
|
||||||
|
SWITCH1_HIGHLIGHT,
|
||||||
|
TILE1,
|
||||||
STAR_STAR,
|
STAR_STAR,
|
||||||
ERROR,
|
ERROR,
|
||||||
};
|
};
|
||||||
|
@ -37,6 +40,10 @@ static enum palette playfield[PLAYFIELD_SIDE * PLAYFIELD_SIDE];
|
||||||
#include "grass_tile.inc"
|
#include "grass_tile.inc"
|
||||||
#include "dirt_tile.inc"
|
#include "dirt_tile.inc"
|
||||||
#include "flag_tile.inc"
|
#include "flag_tile.inc"
|
||||||
|
#include "switch1_off_tile.inc"
|
||||||
|
#include "switch1_on_tile.inc"
|
||||||
|
#include "tile1_off_tile.inc"
|
||||||
|
#include "tile1_on_tile.inc"
|
||||||
|
|
||||||
#include "stage1_tile.inc"
|
#include "stage1_tile.inc"
|
||||||
#include "stage2_tile.inc"
|
#include "stage2_tile.inc"
|
||||||
|
@ -60,12 +67,15 @@ static char *stages[] = {
|
||||||
" "
|
" "
|
||||||
" "
|
" "
|
||||||
" "
|
" "
|
||||||
" "
|
" A "
|
||||||
" "
|
" 11g "
|
||||||
" !"
|
"@ !"
|
||||||
"gggggggggg"
|
"ggg gg"
|
||||||
};
|
};
|
||||||
|
|
||||||
|
enum switches_state { ALL_OFF, SWITCH1 };
|
||||||
|
enum switches_state switches_state;
|
||||||
|
|
||||||
static uint32_t main_window = 0;
|
static uint32_t main_window = 0;
|
||||||
static uint32_t window_width = 600;
|
static uint32_t window_width = 600;
|
||||||
static uint32_t window_height = 500;
|
static uint32_t window_height = 500;
|
||||||
|
@ -126,7 +136,8 @@ static char sample_tilemap(size_t x, size_t y) {
|
||||||
|
|
||||||
static bool solid_tile(size_t x, size_t y) {
|
static bool solid_tile(size_t x, size_t y) {
|
||||||
char tile = sample_tilemap(x, y);
|
char tile = sample_tilemap(x, y);
|
||||||
return tile != ' ' && tile != '!' && tile != '@';
|
return tile != ' ' && tile != '!' && tile != '@' && tile != 'A' &&
|
||||||
|
(tile != '1' || switches_state == SWITCH1);
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool jumping = false;
|
static bool jumping = false;
|
||||||
|
@ -140,6 +151,7 @@ static size_t selection_index = 0;
|
||||||
|
|
||||||
static void initialize_stage(void) {
|
static void initialize_stage(void) {
|
||||||
strcpy(tilemap, stages[selection_index]);
|
strcpy(tilemap, stages[selection_index]);
|
||||||
|
switches_state = ALL_OFF;
|
||||||
jumping = false;
|
jumping = false;
|
||||||
on_ground = false;
|
on_ground = false;
|
||||||
player_dx = 0;
|
player_dx = 0;
|
||||||
|
@ -294,13 +306,17 @@ static void update_stage(struct timespec now, struct timespec dt_timespec) {
|
||||||
// Touching tiles
|
// Touching tiles
|
||||||
size_t midpoint_x = player_x + TILE_SIDE / 2;
|
size_t midpoint_x = player_x + TILE_SIDE / 2;
|
||||||
size_t midpoint_y = player_y + TILE_SIDE / 2;
|
size_t midpoint_y = player_y + TILE_SIDE / 2;
|
||||||
if (sample_tilemap(midpoint_x, midpoint_y) == '!') {
|
switch(sample_tilemap(midpoint_x, midpoint_y)) {
|
||||||
|
case '!':
|
||||||
stages_beat[selection_index] = true;
|
stages_beat[selection_index] = true;
|
||||||
if (selection_index < STAGES - 1)
|
if (selection_index < STAGES - 1)
|
||||||
selection_index++;
|
selection_index++;
|
||||||
game_mode = TITLESCREEN;
|
game_mode = TITLESCREEN;
|
||||||
initialize();
|
initialize();
|
||||||
return;
|
return;
|
||||||
|
case 'A':
|
||||||
|
switches_state = SWITCH1;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -351,6 +367,8 @@ static void draw_tiles(void) {
|
||||||
case 'g': tile = grass_tile; break;
|
case 'g': tile = grass_tile; break;
|
||||||
case 'd': tile = dirt_tile; break;
|
case 'd': tile = dirt_tile; break;
|
||||||
case '!': tile = flag_tile; break;
|
case '!': tile = flag_tile; break;
|
||||||
|
case 'A': tile = switches_state == SWITCH1 ? switch1_on_tile : switch1_off_tile; break;
|
||||||
|
case '1': tile = switches_state == SWITCH1 ? tile1_on_tile : tile1_off_tile; break;
|
||||||
}
|
}
|
||||||
if (tile)
|
if (tile)
|
||||||
draw_tile(tile, tx * TILE_SIDE, ty * TILE_SIDE);
|
draw_tile(tile, tx * TILE_SIDE, ty * TILE_SIDE);
|
||||||
|
@ -413,6 +431,9 @@ 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),
|
||||||
|
[SWITCH_SWITCH] = make_color(200, 64, 0),
|
||||||
|
[SWITCH1_HIGHLIGHT] = make_color(0, 255, 0),
|
||||||
|
[TILE1] = make_color(0, 255, 0),
|
||||||
[STAR_STAR] = make_color(255, 255, 0),
|
[STAR_STAR] = make_color(255, 255, 0),
|
||||||
[ERROR] = make_color(255, 0, 255),
|
[ERROR] = make_color(255, 0, 255),
|
||||||
};
|
};
|
||||||
|
|
|
@ -0,0 +1,14 @@
|
||||||
|
xSWITCH_SWITCH
|
||||||
|
tTEXT
|
||||||
|
BG
|
||||||
|
----------
|
||||||
|
|
||||||
|
xx
|
||||||
|
xx
|
||||||
|
xxxxxx
|
||||||
|
xx xx
|
||||||
|
xx xx
|
||||||
|
tt
|
||||||
|
ttt
|
||||||
|
tt
|
||||||
|
tttt
|
|
@ -0,0 +1,14 @@
|
||||||
|
xSWITCH_SWITCH
|
||||||
|
tSWITCH1_HIGHLIGHT
|
||||||
|
BG
|
||||||
|
----------
|
||||||
|
|
||||||
|
tt
|
||||||
|
ttt
|
||||||
|
tt
|
||||||
|
tttt
|
||||||
|
xx xx
|
||||||
|
xx xx
|
||||||
|
xxxxxx
|
||||||
|
xx
|
||||||
|
xx
|
|
@ -0,0 +1,14 @@
|
||||||
|
xTILE1
|
||||||
|
tTEXT
|
||||||
|
BG
|
||||||
|
----------
|
||||||
|
x x x x
|
||||||
|
x
|
||||||
|
x
|
||||||
|
tt x
|
||||||
|
x ttt
|
||||||
|
tt x
|
||||||
|
x tttt
|
||||||
|
x
|
||||||
|
x
|
||||||
|
x x x x
|
|
@ -0,0 +1,14 @@
|
||||||
|
xTILE1
|
||||||
|
tTEXT
|
||||||
|
BG
|
||||||
|
----------
|
||||||
|
xxxxxxxx
|
||||||
|
xxxxxxxxxx
|
||||||
|
xxxxxxxxxx
|
||||||
|
xxxxttxxxx
|
||||||
|
xxxtttxxxx
|
||||||
|
xxxxttxxxx
|
||||||
|
xxxttttxxx
|
||||||
|
xxxxxxxxxx
|
||||||
|
xxxxxxxxxx
|
||||||
|
xxxxxxxx
|
Loading…
Reference in New Issue