Add control rebinding
This commit is contained in:
parent
21fbcef511
commit
0ca305f230
7
Makefile
7
Makefile
|
@ -11,7 +11,12 @@ TILES = player_stand_tile.inc \
|
|||
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 \
|
||||
rebind_rebind1_tile.inc rebind_rebind2_tile.inc rebind_rebind3_tile.inc \
|
||||
rebind_left1_tile.inc rebind_left2_tile.inc \
|
||||
rebind_right1_tile.inc rebind_right2_tile.inc \
|
||||
rebind_jump1_tile.inc rebind_jump2_tile.inc \
|
||||
rebind_rebind1_alt_tile.inc
|
||||
|
||||
all: $(NAME)
|
||||
|
||||
|
|
|
@ -0,0 +1,13 @@
|
|||
xTEXT
|
||||
BG
|
||||
----------
|
||||
|
||||
|
||||
x
|
||||
x x x
|
||||
x x x xx
|
||||
x x x x
|
||||
x x xx x
|
||||
x x x x
|
||||
x
|
||||
x
|
|
@ -0,0 +1,13 @@
|
|||
xTEXT
|
||||
BG
|
||||
----------
|
||||
|
||||
|
||||
|
||||
xxx
|
||||
x xx x x
|
||||
x x x x
|
||||
x x x x
|
||||
x x xxx
|
||||
x
|
||||
x
|
|
@ -0,0 +1,13 @@
|
|||
xTEXT
|
||||
BG
|
||||
----------
|
||||
x x
|
||||
x x
|
||||
x x
|
||||
x xx xxx
|
||||
x x x x
|
||||
x xxx x
|
||||
x x x
|
||||
x xx x
|
||||
|
||||
|
|
@ -0,0 +1,13 @@
|
|||
xTEXT
|
||||
BG
|
||||
----------
|
||||
|
||||
|
||||
x
|
||||
xxx
|
||||
x
|
||||
x
|
||||
x
|
||||
x
|
||||
|
||||
|
|
@ -0,0 +1,13 @@
|
|||
xTEXT
|
||||
BG
|
||||
----------
|
||||
|
||||
|
||||
|
||||
x x xx
|
||||
xx x x x
|
||||
x xxx
|
||||
x x
|
||||
x xx
|
||||
|
||||
|
|
@ -0,0 +1,13 @@
|
|||
xTEXT
|
||||
BG
|
||||
----------
|
||||
xxx
|
||||
x x
|
||||
xxx
|
||||
x x xx
|
||||
x x x x
|
||||
x x xxx
|
||||
x x x
|
||||
x x xx
|
||||
|
||||
|
|
@ -0,0 +1,13 @@
|
|||
xTEXT
|
||||
BG
|
||||
----------
|
||||
x
|
||||
x
|
||||
x x
|
||||
xxx x
|
||||
x x x xxx
|
||||
x x x x
|
||||
x x x x
|
||||
xxx x x
|
||||
|
||||
|
|
@ -0,0 +1,13 @@
|
|||
xTEXT
|
||||
BG
|
||||
----------
|
||||
x
|
||||
x
|
||||
x
|
||||
xxx
|
||||
x x
|
||||
x x x
|
||||
x x x
|
||||
x xxx
|
||||
|
||||
|
|
@ -0,0 +1,13 @@
|
|||
xTEXT
|
||||
BG
|
||||
----------
|
||||
|
||||
|
||||
x
|
||||
x x xx
|
||||
xx x x x
|
||||
x x x
|
||||
x x x
|
||||
x x xx
|
||||
|
||||
x
|
|
@ -0,0 +1,13 @@
|
|||
xTEXT
|
||||
BG
|
||||
----------
|
||||
x
|
||||
x
|
||||
x x
|
||||
x xxx xxx
|
||||
x x x x
|
||||
x x x x
|
||||
x x x x
|
||||
x x x x
|
||||
x
|
||||
|
100
switcher.c
100
switcher.c
|
@ -56,6 +56,17 @@ static enum palette playfield[PLAYFIELD_SIDE * PLAYFIELD_SIDE];
|
|||
#include "stage2_tile.inc"
|
||||
#include "star_tile.inc"
|
||||
|
||||
#include "rebind_rebind1_tile.inc"
|
||||
#include "rebind_rebind2_tile.inc"
|
||||
#include "rebind_rebind3_tile.inc"
|
||||
#include "rebind_left1_tile.inc"
|
||||
#include "rebind_left2_tile.inc"
|
||||
#include "rebind_right1_tile.inc"
|
||||
#include "rebind_right2_tile.inc"
|
||||
#include "rebind_jump1_tile.inc"
|
||||
#include "rebind_jump2_tile.inc"
|
||||
#include "rebind_rebind1_alt_tile.inc"
|
||||
|
||||
static char tilemap[TILES * TILES + 1];
|
||||
static char *stages[] = {
|
||||
" "
|
||||
|
@ -99,19 +110,49 @@ static bool left_held, right_held, jump_held;
|
|||
static double jump_maxheight = 21;
|
||||
static double jump_duration = 0.4;
|
||||
|
||||
static int left_key = KBKEY_LEFT;
|
||||
static int right_key = KBKEY_RIGHT;
|
||||
static int jump_key = KBKEY_SPACE;
|
||||
static int rebind_key = KBKEY_R;
|
||||
|
||||
enum rebind_state { PLAYING, LEFT, RIGHT, JUMP, REBIND };
|
||||
enum rebind_state rebind_state;
|
||||
|
||||
static void on_keyboard(void *context, uint32_t window, uint32_t codepoint) {
|
||||
(void) context;
|
||||
if (window != main_window)
|
||||
return;
|
||||
int key = KBKEY_DECODE(codepoint);
|
||||
switch (key) {
|
||||
// TODO: rebinding
|
||||
case KBKEY_LEFT: left_held = true; break;
|
||||
case -KBKEY_LEFT: left_held = false; break;
|
||||
case KBKEY_RIGHT: right_held = true; break;
|
||||
case -KBKEY_RIGHT: right_held = false; break;
|
||||
case KBKEY_SPACE: jump_held = true; break;
|
||||
case -KBKEY_SPACE: jump_held = false; break;
|
||||
switch (rebind_state) {
|
||||
case PLAYING:
|
||||
if (key == -rebind_key) rebind_state = LEFT;
|
||||
else if (key == left_key) left_held = true;
|
||||
else if (key == -left_key) left_held = false;
|
||||
else if (key == right_key) right_held = true;
|
||||
else if (key == -right_key) right_held = false;
|
||||
else if (key == jump_key) jump_held = true;
|
||||
else if (key == -jump_key) jump_held = false;
|
||||
break;
|
||||
case LEFT:
|
||||
if (key >= 0) return;
|
||||
left_key = -key;
|
||||
rebind_state = RIGHT;
|
||||
break;
|
||||
case RIGHT:
|
||||
if (key >= 0) return;
|
||||
right_key = -key;
|
||||
rebind_state = JUMP;
|
||||
break;
|
||||
case JUMP:
|
||||
if (key >= 0) return;
|
||||
jump_key = -key;
|
||||
rebind_state = REBIND;
|
||||
break;
|
||||
case REBIND:
|
||||
if (key >= 0) return;
|
||||
rebind_key = -key;
|
||||
rebind_state = PLAYING;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -185,7 +226,7 @@ static void initialize(void) {
|
|||
switch (game_mode) {
|
||||
case TITLESCREEN: initialize_titlescreen(); break;
|
||||
case STAGE: initialize_stage(); break;
|
||||
default: printf("%i\n", game_mode); break;
|
||||
default: printf("game_mode %i\n", game_mode);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -347,10 +388,11 @@ static void update_titlescreen(struct timespec now, struct timespec dt_timespec)
|
|||
}
|
||||
|
||||
static void update(struct timespec now, struct timespec dt_timespec) {
|
||||
if (rebind_state != PLAYING) return;
|
||||
switch (game_mode) {
|
||||
case TITLESCREEN: update_titlescreen(now, dt_timespec); break;
|
||||
case STAGE: update_stage(now, dt_timespec); break;
|
||||
default: printf("%i\n", game_mode); break;
|
||||
default: printf("game_mode %i\n", game_mode);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -385,7 +427,6 @@ static void draw_tiles(void) {
|
|||
}
|
||||
|
||||
static void draw_stage(struct timespec now) {
|
||||
memset(playfield, 0, sizeof(playfield));
|
||||
draw_tiles();
|
||||
if (right_held && now.tv_nsec % 500000000L < 250000000L && on_ground)
|
||||
draw_tile(player_walk2_tile, player_x, player_y);
|
||||
|
@ -401,7 +442,6 @@ static void draw_stage(struct timespec now) {
|
|||
|
||||
static void draw_titlescreen(struct timespec now) {
|
||||
(void) now;
|
||||
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;
|
||||
|
@ -417,10 +457,38 @@ static void draw_titlescreen(struct timespec now) {
|
|||
}
|
||||
|
||||
static void draw(struct timespec now) {
|
||||
switch (game_mode) {
|
||||
case TITLESCREEN: draw_titlescreen(now); break;
|
||||
case STAGE: draw_stage(now); break;
|
||||
default: printf("%i\n", game_mode); break;
|
||||
memset(playfield, 0, sizeof(playfield));
|
||||
if (rebind_state == PLAYING) {
|
||||
switch (game_mode) {
|
||||
case TITLESCREEN: draw_titlescreen(now); break;
|
||||
case STAGE: draw_stage(now); break;
|
||||
default: printf("game_mode %i\n", game_mode);
|
||||
}
|
||||
} else {
|
||||
draw_tile(rebind_rebind1_tile, 0 * TILE_SIDE, 0);
|
||||
draw_tile(rebind_rebind2_tile, 1 * TILE_SIDE, 0);
|
||||
draw_tile(rebind_rebind3_tile, 2 * TILE_SIDE, 0);
|
||||
switch (rebind_state) {
|
||||
case LEFT:
|
||||
draw_tile(rebind_left1_tile, 3 * TILE_SIDE, 0);
|
||||
draw_tile(rebind_left2_tile, 4 * TILE_SIDE, 0);
|
||||
break;
|
||||
case RIGHT:
|
||||
draw_tile(rebind_right1_tile, 3 * TILE_SIDE, 0);
|
||||
draw_tile(rebind_right2_tile, 4 * TILE_SIDE, 0);
|
||||
break;
|
||||
case JUMP:
|
||||
draw_tile(rebind_jump1_tile, 3 * TILE_SIDE, 0);
|
||||
draw_tile(rebind_jump2_tile, 4 * TILE_SIDE, 0);
|
||||
break;
|
||||
case REBIND:
|
||||
draw_tile(rebind_rebind1_alt_tile, 3 * TILE_SIDE, 0);
|
||||
draw_tile(rebind_rebind2_tile, 4 * TILE_SIDE, 0);
|
||||
draw_tile(rebind_rebind3_tile, 5 * TILE_SIDE, 0);
|
||||
break;
|
||||
default:
|
||||
printf("rebind_state %i\n", rebind_state);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue