From 76602adf5a819fb50baf2af31a6d0a99e982c7cb Mon Sep 17 00:00:00 2001 From: 3gg <3gg@shellblade.net> Date: Fri, 24 Oct 2025 14:57:07 -0700 Subject: Updates after gfx lib updates --- src/plugins/pong.c | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) (limited to 'src/plugins/pong.c') diff --git a/src/plugins/pong.c b/src/plugins/pong.c index c1c55be..f8d455d 100644 --- a/src/plugins/pong.c +++ b/src/plugins/pong.c @@ -2,8 +2,11 @@ #include #include +#include #include +#include +#include #include #include #include @@ -35,7 +38,7 @@ typedef struct State { Player human; Player enemy; Ball ball; - mat4 viewProjection; + mat4 projection; } State; bool init(Game* game, State** pp_state) { @@ -94,14 +97,14 @@ void move_enemy_player(int width, Player* player, R t) { player->position.x = half_width + amplitude * sinf(t * ENEMY_SPEED); } -void move_human_player(Player* player, R dt) { +void move_human_player(GfxApp* app, Player* player, R dt) { assert(player); R speed = 0; - if (gfx_app_is_key_pressed('a')) { + if (gfx_app_is_key_pressed(app, KeyA)) { speed -= PLAYER_SPEED; } - if (gfx_app_is_key_pressed('d')) { + if (gfx_app_is_key_pressed(app, KeyD)) { speed += PLAYER_SPEED; } @@ -158,7 +161,7 @@ void update(Game* game, State* state, double t, double dt) { // TODO: Move game width/height to GfxApp query functions? const vec2 old_ball_position = state->ball.position; move_ball(&state->ball, (R)dt, game->width, game->height); - move_human_player(&state->human, (R)dt); + move_human_player(game->app, &state->human, (R)dt); move_enemy_player(game->width, &state->enemy, (R)t); clamp_player(&state->human, game->width); collide_ball(old_ball_position, &state->human, &state->ball); @@ -194,10 +197,12 @@ void render(const Game* game, const State* state) { assert(game); assert(state); + LLR* llr = gfx_get_llr(game->gfx); ImmRenderer* imm = gfx_get_imm_renderer(game->gfx); + + gfx_llr_set_projection_matrix(llr, &state->projection); + gfx_llr_load_identity(llr); gfx_imm_start(imm); - gfx_imm_set_view_projection_matrix(imm, &state->viewProjection); - gfx_imm_load_identity(imm); gfx_imm_set_colour(imm, vec4_make(1, 1, 1, 1)); draw_player(imm, &state->human); draw_player(imm, &state->enemy); @@ -213,7 +218,7 @@ void resize(Game* game, State* state, int width, int height) { assert(game); assert(state); - state->viewProjection = mat4_ortho(0, (R)width, 0, (R)height, -1, 1); + state->projection = mat4_ortho(0, (R)width, 0, (R)height, -1, 1); state->human.position.y = PLAYER_Y_OFFSET; state->enemy.position.y = (R)height - PLAYER_Y_OFFSET; -- cgit v1.2.3