Added shift + hjkl binds for faster movement.

This commit is contained in:
Sheldon Lee 2020-07-06 23:04:34 +01:00
parent 031393a7b3
commit 1620659db6

39
game.c
View File

@ -74,12 +74,7 @@ bool isRunning() { return running; }
void handleInput(char ch) void handleInput(char ch)
{ {
switch (ch) { switch (ch) {
case 'q': // {{{ movement
running = false;
break;
case ' ':
toggleStepMode();
break;
case 'h': case 'h':
moveVect2i(&cursor, -1, 0); moveVect2i(&cursor, -1, 0);
break; break;
@ -92,26 +87,48 @@ void handleInput(char ch)
case 'l': case 'l':
moveVect2i(&cursor, 1, 0); moveVect2i(&cursor, 1, 0);
break; break;
case 'H':
moveVect2i(&cursor, -10, 0);
break;
case 'J':
moveVect2i(&cursor, 0, 10);
break;
case 'K':
moveVect2i(&cursor, 0, -10);
break;
case 'L':
moveVect2i(&cursor, 10, 0);
break;
// }}}
// {{{ Cell
case 'r': case 'r':
randomizeGrid(grid); randomizeGrid(grid);
break; break;
case 'c': case 'c':
clearGrid(grid); clearGrid(grid);
break; break;
case '\n':
do_step = true;
break;
case 'i': case 'i':
toggleCell(); toggleCell();
break; break;
// }}}
// {{{ game load/save
case 'e': case 'e':
loadGame("test.txt"); loadGame("test.txt");
break; break;
case 'w': case 'w':
saveGame("test.txt"); saveGame("test.txt");
break; break;
// }}}
// {{{ flow
case 'q':
running = false;
break;
case ' ':
toggleStepMode();
break;
default: default:
if (ch != -1) do_step = true; if (ch != -1) do_step = true;
// }}}
} }
} }
@ -165,14 +182,16 @@ void loadGame(char* name)
unsigned int width, height, size; unsigned int width, height, size;
bool* pixels; bool* pixels;
// read data frrom file
fread(&width, sizeof(unsigned int), 1, file); fread(&width, sizeof(unsigned int), 1, file);
fread(&size, sizeof(unsigned int), 1, file); fread(&size, sizeof(unsigned int), 1, file);
height = size/width; height = size/width;
pixels = (bool*)malloc(sizeof(bool)*size); pixels = (bool*)malloc(sizeof(bool)*size);
fread(pixels, sizeof(bool), size, file); fread(pixels, sizeof(bool), size, file);
unsigned int grid_width, grid_height; unsigned int grid_width, grid_height;
// map & copy new pixels array to current grid
getDimensions(grid, &grid_width, &grid_height); getDimensions(grid, &grid_width, &grid_height);
for (int y =0; y < min(grid_height, height); y++) { for (int y =0; y < min(grid_height, height); y++) {
for (int x =0; x < min(grid_width, width); x++) { for (int x =0; x < min(grid_width, width); x++) {