Add all the types of switches

This commit is contained in:
Juhani Krekelä 2022-01-16 15:15:26 +00:00
parent 531ee88980
commit 91dfbd8db9
16 changed files with 277 additions and 28 deletions

View File

@ -10,7 +10,14 @@ TILES = player_stand_tile.inc \
player_walk2_tile.inc player_walk2_tile_reversed.inc \
grass_tile.inc dirt_tile.inc flag_tile.inc \
switch1_off_tile.inc switch1_on_tile.inc \
switch2_off_tile.inc switch2_on_tile.inc \
switch3_off_tile.inc switch3_on_tile.inc \
switch4_off_tile.inc switch4_on_tile.inc \
switch0_off_tile.inc switch0_on_tile.inc \
tile1_off_tile.inc tile1_on_tile.inc \
tile2_off_tile.inc tile2_on_tile.inc \
tile3_off_tile.inc tile3_on_tile.inc \
tile4_off_tile.inc tile4_on_tile.inc \
stage1_tile.inc stage2_tile.inc stage3_tile.inc stage4_tile.inc \
stage5_tile.inc stage6_tile.inc stage7_tile.inc stage8_tile.inc \
star_tile.inc \

14
switch0_off_tile.txt Normal file
View File

@ -0,0 +1,14 @@
xSWITCH_SWITCH
tTEXT
BG
----------
xx
xx
xxxxxx
xx xx
xx xx
tt
tt t
t tt
tt

14
switch0_on_tile.txt Normal file
View File

@ -0,0 +1,14 @@
xSWITCH_SWITCH
tTEXT
BG
----------
tt
tt t
t tt
tt
xx xx
xx xx
xxxxxx
xx
xx

14
switch2_off_tile.txt Normal file
View File

@ -0,0 +1,14 @@
xSWITCH_SWITCH
tTEXT
BG
----------
xx
xx
xxxxxx
xx xx
xx xx
tt
t t
t
ttt

14
switch2_on_tile.txt Normal file
View File

@ -0,0 +1,14 @@
xSWITCH_SWITCH
tTILE2
BG
----------
tt
t t
t
ttt
xx xx
xx xx
xxxxxx
xx
xx

14
switch3_off_tile.txt Normal file
View File

@ -0,0 +1,14 @@
xSWITCH_SWITCH
tTEXT
BG
----------
xx
xx
xxxxxx
xx xx
xx xx
ttt
tt
t
ttt

14
switch3_on_tile.txt Normal file
View File

@ -0,0 +1,14 @@
xSWITCH_SWITCH
tTILE3
BG
----------
ttt
tt
t
ttt
xx xx
xx xx
xxxxxx
xx
xx

14
switch4_off_tile.txt Normal file
View File

@ -0,0 +1,14 @@
xSWITCH_SWITCH
tTEXT
BG
----------
xx
xx
xxxxxx
xx xx
xx xx
t t
t t
tttt
t

14
switch4_on_tile.txt Normal file
View File

@ -0,0 +1,14 @@
xSWITCH_SWITCH
tTILE4
BG
----------
t t
t t
tttt
t
xx xx
xx xx
xxxxxx
xx
xx

View File

@ -34,6 +34,9 @@ enum palette {
FLAG_FLAG,
SWITCH_SWITCH,
TILE1,
TILE2,
TILE3,
TILE4,
STAR_STAR,
};
static enum palette playfield[PLAYFIELD_SIDE * PLAYFIELD_SIDE];
@ -47,10 +50,26 @@ static enum palette playfield[PLAYFIELD_SIDE * PLAYFIELD_SIDE];
#include "grass_tile.inc"
#include "dirt_tile.inc"
#include "flag_tile.inc"
#include "switch1_off_tile.inc"
#include "switch1_on_tile.inc"
#include "switch2_off_tile.inc"
#include "switch2_on_tile.inc"
#include "switch3_off_tile.inc"
#include "switch3_on_tile.inc"
#include "switch4_off_tile.inc"
#include "switch4_on_tile.inc"
#include "switch0_off_tile.inc"
#include "switch0_on_tile.inc"
#include "tile1_off_tile.inc"
#include "tile1_on_tile.inc"
#include "tile2_off_tile.inc"
#include "tile2_on_tile.inc"
#include "tile3_off_tile.inc"
#include "tile3_on_tile.inc"
#include "tile4_off_tile.inc"
#include "tile4_on_tile.inc"
#include "stage1_tile.inc"
#include "stage2_tile.inc"
@ -97,34 +116,34 @@ static char *stages[] = {
"ggg gg",
" "
" "
"B N"
"2222222222"
" 1 "
" "
"1 "
" "
"@A1 !"
"g1 gg",
" d "
" d N "
" d "
" d g "
" d "
"Adg ggg"
" 1 !"
" g g"
" gd gd"
"ggggddggdd",
" !"
" D 4"
"C 3 44"
"3 3 4 "
" B"
" 222 2 2"
" "
" "
" "
" "
" "
" ",
" "
" "
" "
" "
" "
" "
" "
" "
" "
" ",
" "
" "
" "
" "
" "
" "
" "
" "
" "
" ",
" A 1 111"
"@g "
"gd ",
" "
" "
" "
@ -157,7 +176,7 @@ static char *stages[] = {
" ",
};
enum switches_state { ALL_OFF, SWITCH1 };
enum switches_state { ALL_OFF, SWITCH1, SWITCH2, SWITCH3, SWITCH4 };
enum switches_state switches_state;
static uint32_t main_window = 0;
@ -250,8 +269,12 @@ static char sample_tilemap(size_t x, size_t y) {
static bool solid_tile(size_t x, size_t y) {
char tile = sample_tilemap(x, y);
return tile != ' ' && tile != '!' && tile != '@' && tile != 'A' &&
(tile != '1' || switches_state == SWITCH1);
return tile != ' ' && tile != '!' && tile != '@' &&
tile != 'A' && (tile != '1' || switches_state == SWITCH1) &&
tile != 'B' && (tile != '2' || switches_state == SWITCH2) &&
tile != 'C' && (tile != '3' || switches_state == SWITCH3) &&
tile != 'D' && (tile != '4' || switches_state == SWITCH4) &&
tile != 'N';
}
static bool jumping = false;
@ -431,6 +454,17 @@ static void update_stage(struct timespec now, struct timespec dt_timespec) {
case 'A':
switches_state = SWITCH1;
break;
case 'B':
switches_state = SWITCH2;
break;
case 'C':
switches_state = SWITCH3;
break;
case 'D':
switches_state = SWITCH4;
break;
case 'N':
switches_state = ALL_OFF;
}
}
@ -484,7 +518,14 @@ static void draw_tiles(void) {
case 'd': tile = dirt_tile; break;
case '!': tile = flag_tile; break;
case 'A': tile = switches_state == SWITCH1 ? switch1_on_tile : switch1_off_tile; break;
case 'B': tile = switches_state == SWITCH2 ? switch2_on_tile : switch2_off_tile; break;
case 'C': tile = switches_state == SWITCH3 ? switch3_on_tile : switch3_off_tile; break;
case 'D': tile = switches_state == SWITCH4 ? switch4_on_tile : switch4_off_tile; break;
case 'N': tile = switches_state == ALL_OFF ? switch0_on_tile : switch0_off_tile; break;
case '1': tile = switches_state == SWITCH1 ? tile1_on_tile : tile1_off_tile; break;
case '2': tile = switches_state == SWITCH2 ? tile2_on_tile : tile2_off_tile; break;
case '3': tile = switches_state == SWITCH3 ? tile3_on_tile : tile3_off_tile; break;
case '4': tile = switches_state == SWITCH4 ? tile4_on_tile : tile4_off_tile; break;
}
if (tile)
draw_tile(tile, tx * TILE_SIDE, ty * TILE_SIDE);
@ -594,6 +635,9 @@ int main(int argc, char *argv[]) {
[FLAG_FLAG] = make_color(255, 0, 0),
[SWITCH_SWITCH] = make_color(200, 64, 0),
[TILE1] = make_color(0, 255, 0),
[TILE2] = make_color(0, 0, 255),
[TILE3] = make_color(255, 0, 0),
[TILE4] = make_color(255, 255, 0),
[STAR_STAR] = make_color(255, 255, 0),
};

14
tile2_off_tile.txt Normal file
View File

@ -0,0 +1,14 @@
xTILE2
tTEXT
BG
----------
x x x x
x
x
tt x
x t t
t x
x ttt
x
x
x x x x

14
tile2_on_tile.txt Normal file
View File

@ -0,0 +1,14 @@
xTILE2
tTEXT
BG
----------
xxxxxxxx
xxxxxxxxxx
xxxxxxxxxx
xxxxttxxxx
xxxtxxtxxx
xxxxxtxxxx
xxxxtttxxx
xxxxxxxxxx
xxxxxxxxxx
xxxxxxxx

14
tile3_off_tile.txt Normal file
View File

@ -0,0 +1,14 @@
xTILE3
tTEXT
BG
----------
x x x x
x
x
ttt x
x tt
t x
x ttt
x
x
x x x x

15
tile3_on_tile.txt Normal file
View File

@ -0,0 +1,15 @@
xTILE3
tTEXT
TILE3
.BG
----------
.x x x x .
x
x
ttt x
x tt
t x
x ttt
x
x
. x x x x.

14
tile4_off_tile.txt Normal file
View File

@ -0,0 +1,14 @@
xTILE4
tTEXT
BG
----------
x x x x
x
x
t t x
x t t
tttt x
x t
x
x
x x x x

15
tile4_on_tile.txt Normal file
View File

@ -0,0 +1,15 @@
xTILE4
tTEXT
.BG
TILE4
----------
.x x x x .
x
x
t t x
x t t
tttt x
x t
x
x
. x x x x.