a-game

2D platformer written from scratch.
git clone git://git.amin.space/a-game.git
Log | Files | Refs | README | LICENSE

commit e612d0b7b3ae5d7b79732259fed75cf417eda8bf
parent ef3c281c99242ed4adda9855082d5908e768b69f
Author: amin <dev@aminmesbah.com>
Date:   Mon,  1 Jul 2019 01:06:38 +0000

Add floating movement mode for debug purposes

FossilOrigin-Name: 14adb062c716528ab5c1f5974b726253147b31141f65e8c20c1dc160a8bcfd2f
Diffstat:
Msrc/game.c | 34+++++++++++++++++++++++++++++++++-
Msrc/game.h | 1+
Msrc/platform.h | 1+
Msrc/platform_linux.c | 1+
4 files changed, 36 insertions(+), 1 deletion(-)

diff --git a/src/game.c b/src/game.c @@ -29,6 +29,9 @@ internal void move_mode_print(enum MoveMode s) case MOVE_MODE_CLIMBING: printf("CLIMBING\n"); break; + case MOVE_MODE_FLOATING: + printf("FLOATING\n"); + break; default: printf("INVALID\n"); break; @@ -279,6 +282,18 @@ void game_update_and_render(struct GameMemory *game_memory, struct GameInput *ga player->velocity.x = player->velocity.x * friction; } + if (btn_is_down(button_states, BTN_DEBUG_FLOAT)) + { + if (player->move_mode == MOVE_MODE_FLOATING) + { + player->move_mode = MOVE_MODE_FALLING; + } + else + { + player->move_mode = MOVE_MODE_FLOATING; + } + } + rect player_rect = math_rect_from_center_dim(player->pos.local, player->dimensions); // TODO: tune these acceleration rates @@ -340,6 +355,23 @@ void game_update_and_render(struct GameMemory *game_memory, struct GameInput *ga } break; } + case MOVE_MODE_FLOATING: + { + if (btn_is_down(button_states, BTN_UP)) + { + player->acceleration.y = acceleration_rate; + } + else if (btn_is_down(button_states, BTN_DOWN)) + { + player->acceleration.y = -acceleration_rate; + } + else + { + player->acceleration.y = 0.0f; + player->velocity.y = player->velocity.y * friction; + } + break; + } default: assert(false); break; @@ -439,7 +471,7 @@ void game_update_and_render(struct GameMemory *game_memory, struct GameInput *ga } } - if (collision_occurred) + if (collision_occurred && player->move_mode != MOVE_MODE_FLOATING) { if (edges_collided[RECT_EDGE_TOP] && player->move_mode == MOVE_MODE_FALLING) { diff --git a/src/game.h b/src/game.h @@ -43,6 +43,7 @@ enum MoveMode MOVE_MODE_GROUNDED, MOVE_MODE_CLIMBING, MOVE_MODE_JUMPING, + MOVE_MODE_FLOATING, }; enum Direction diff --git a/src/platform.h b/src/platform.h @@ -14,6 +14,7 @@ enum GameButton BTN_UP, BTN_DOWN, BTN_JUMP, + BTN_DEBUG_FLOAT, NUM_GAME_BUTTONS, NULL_GAME_BUTTON, diff --git a/src/platform_linux.c b/src/platform_linux.c @@ -17,6 +17,7 @@ global_variable int platform_input_map[NUM_GAME_BUTTONS] = { [BTN_UP] = GLFW_KEY_UP, [BTN_DOWN] = GLFW_KEY_DOWN, [BTN_JUMP] = GLFW_KEY_S, + [BTN_DEBUG_FLOAT] = GLFW_KEY_F11, }; int main(void)