diff options
author | kdx <kikoodx@paranoici.org> | 2023-11-24 04:08:37 +0100 |
---|---|---|
committer | kdx <kikoodx@paranoici.org> | 2023-11-24 04:08:37 +0100 |
commit | 22385b85e54d172d4557478723ce062c2608d5b4 (patch) | |
tree | a1784f9aa37eab71d6a1386869341da491db0ca7 | |
parent | 1dfbb71fd6b235d41fc8a6160434c00ddf0a800a (diff) | |
download | aancyk-22385b85e54d172d4557478723ce062c2608d5b4.tar.gz |
move between cells with wasd
-rw-r--r-- | inc/world.h | 1 | ||||
-rw-r--r-- | src/editor.c | 9 | ||||
-rw-r--r-- | src/world.c | 7 |
3 files changed, 17 insertions, 0 deletions
diff --git a/inc/world.h b/inc/world.h index 0459cfc..20e94eb 100644 --- a/inc/world.h +++ b/inc/world.h @@ -20,6 +20,7 @@ int world_next_id(World *this); Cell *world_new_cell(World *this, int x, int y); Cell *world_cell_at(World *this, int x, int y); // can return null void world_goto(World *this, int x, int y, bool save); +void world_move(World *this, int x, int y); void world_save_cell(World *this, Cell *cell); void world_load_cell(World *this, Cell *cell); int world_cell_count(World *this); diff --git a/src/editor.c b/src/editor.c index 8b373b2..85bfb9d 100644 --- a/src/editor.c +++ b/src/editor.c @@ -195,4 +195,13 @@ _ev_key(Window *this, Root *root) grid_flip_x(root->brush); this->redraw = true; } + + if (input_key_pressed(input, SDL_SCANCODE_W)) + world_move(root->world, 0, -1); + if (input_key_pressed(input, SDL_SCANCODE_A)) + world_move(root->world, -1, 0); + if (input_key_pressed(input, SDL_SCANCODE_S)) + world_move(root->world, 0, 1); + if (input_key_pressed(input, SDL_SCANCODE_D)) + world_move(root->world, 1, 0); } diff --git a/src/world.c b/src/world.c index babac9b..166dea5 100644 --- a/src/world.c +++ b/src/world.c @@ -198,6 +198,13 @@ world_goto(World *this, int x, int y, bool save) } void +world_move(World *this, int x, int y) +{ + assert(this != NULL); + world_goto(this, this->x + x, this->y + y, true); +} + +void world_save_cell(World *this, Cell *cell) { assert(this != NULL); |