Y draw offset is now set manually.

Using tan and →, the player can now move the view.
This commit is contained in:
KikooDX 2021-03-05 23:45:55 +01:00
parent e843b5706b
commit d363b6e5af
4 changed files with 16 additions and 5 deletions

View File

@ -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

View File

@ -8,13 +8,15 @@
#include <stdbool.h>
#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
};

View File

@ -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;

View File

@ -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);