diff --git a/include/conf.h b/include/conf.h index 4504986..ae88f1c 100644 --- a/include/conf.h +++ b/include/conf.h @@ -15,4 +15,7 @@ #define LEVEL_WIDTH_PX (LEVEL_WIDTH * TILE_SIZE) #define LEVEL_HEIGHT_PX (LEVEL_HEIGHT * TILE_SIZE) #define DRAW_OFFSET_X 70 -#define DRAW_OFFSET_Y -16 +#define DRAW_OFFSET_Y_MIN -32 +#define DRAW_OFFSET_Y_MAX 0 +#define DRAW_OFFSET_Y_STEP 8 +#define DRAW_OFFSET_Y_DEFAULT -16 diff --git a/include/input.h b/include/input.h index f66a7c7..cd48473 100644 --- a/include/input.h +++ b/include/input.h @@ -8,13 +8,15 @@ #include #include "lazyint.h" -#define KEYS_COUNT 6 +#define KEYS_COUNT 8 enum { K_LEFT, K_RIGHT, K_DOWN, K_JUMP, K_RESTART, + K_CAM_UP, + K_CAM_DOWN, K_EXIT }; diff --git a/src/input.c b/src/input.c index ae55f39..993240a 100644 --- a/src/input.c +++ b/src/input.c @@ -40,6 +40,8 @@ void input_init(Input *input) { input->keys[K_DOWN] = KEY_DOWN; input->keys[K_JUMP] = KEY_SHIFT; input->keys[K_RESTART] = KEY_6; + input->keys[K_CAM_UP] = KEY_TAN; + input->keys[K_CAM_DOWN] = KEY_ARROW; input->keys[K_EXIT] = KEY_EXIT; for (u8 i = 0; i < KEYS_COUNT; ++i) input->states[i] = S_UP; diff --git a/src/main.c b/src/main.c index 16105f1..5ded71b 100644 --- a/src/main.c +++ b/src/main.c @@ -31,6 +31,8 @@ int main(void) { /* Initialize input. */ Input input = (Input){}; input_init(&input); + /* Initalize y offset. */ + i16 y_offset = DRAW_OFFSET_Y_DEFAULT; /* UPS control. */ volatile bool has_ticked = true; @@ -47,10 +49,12 @@ int main(void) { /* Update. */ input_update(&input); player_update(&player, &level, input, &level_id); + /* Y offset. */ + if (input_is_pressed(input, K_CAM_UP) && y_offset < DRAW_OFFSET_Y_MAX) + y_offset += DRAW_OFFSET_Y_STEP; + if (input_is_pressed(input, K_CAM_DOWN) && y_offset > DRAW_OFFSET_Y_MIN) + y_offset -= DRAW_OFFSET_Y_STEP; } - /* Calculate y offset ("camera"). */ - const i16 y_offset = ((f32)player.pos.y / (f32)LEVEL_HEIGHT_PX) * - (DHEIGHT - LEVEL_HEIGHT_PX); /* Draw. */ dclear(C_BLACK); level_draw(level, y_offset);