summaryrefslogtreecommitdiff
path: root/src/plugins
diff options
context:
space:
mode:
Diffstat (limited to 'src/plugins')
-rw-r--r--src/plugins/pong.c21
1 files changed, 13 insertions, 8 deletions
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 @@
2 2
3#include <gfx/app.h> 3#include <gfx/app.h>
4#include <gfx/gfx.h> 4#include <gfx/gfx.h>
5#include <gfx/llr/llr.h>
5#include <gfx/renderer.h> 6#include <gfx/renderer.h>
7#include <gfx/renderer/imm_renderer.h>
6 8
9#include <math/aabb2.h>
7#include <math/mat4.h> 10#include <math/mat4.h>
8#include <math/vec2.h> 11#include <math/vec2.h>
9#include <math/vec4.h> 12#include <math/vec4.h>
@@ -35,7 +38,7 @@ typedef struct State {
35 Player human; 38 Player human;
36 Player enemy; 39 Player enemy;
37 Ball ball; 40 Ball ball;
38 mat4 viewProjection; 41 mat4 projection;
39} State; 42} State;
40 43
41bool init(Game* game, State** pp_state) { 44bool init(Game* game, State** pp_state) {
@@ -94,14 +97,14 @@ void move_enemy_player(int width, Player* player, R t) {
94 player->position.x = half_width + amplitude * sinf(t * ENEMY_SPEED); 97 player->position.x = half_width + amplitude * sinf(t * ENEMY_SPEED);
95} 98}
96 99
97void move_human_player(Player* player, R dt) { 100void move_human_player(GfxApp* app, Player* player, R dt) {
98 assert(player); 101 assert(player);
99 102
100 R speed = 0; 103 R speed = 0;
101 if (gfx_app_is_key_pressed('a')) { 104 if (gfx_app_is_key_pressed(app, KeyA)) {
102 speed -= PLAYER_SPEED; 105 speed -= PLAYER_SPEED;
103 } 106 }
104 if (gfx_app_is_key_pressed('d')) { 107 if (gfx_app_is_key_pressed(app, KeyD)) {
105 speed += PLAYER_SPEED; 108 speed += PLAYER_SPEED;
106 } 109 }
107 110
@@ -158,7 +161,7 @@ void update(Game* game, State* state, double t, double dt) {
158 // TODO: Move game width/height to GfxApp query functions? 161 // TODO: Move game width/height to GfxApp query functions?
159 const vec2 old_ball_position = state->ball.position; 162 const vec2 old_ball_position = state->ball.position;
160 move_ball(&state->ball, (R)dt, game->width, game->height); 163 move_ball(&state->ball, (R)dt, game->width, game->height);
161 move_human_player(&state->human, (R)dt); 164 move_human_player(game->app, &state->human, (R)dt);
162 move_enemy_player(game->width, &state->enemy, (R)t); 165 move_enemy_player(game->width, &state->enemy, (R)t);
163 clamp_player(&state->human, game->width); 166 clamp_player(&state->human, game->width);
164 collide_ball(old_ball_position, &state->human, &state->ball); 167 collide_ball(old_ball_position, &state->human, &state->ball);
@@ -194,10 +197,12 @@ void render(const Game* game, const State* state) {
194 assert(game); 197 assert(game);
195 assert(state); 198 assert(state);
196 199
200 LLR* llr = gfx_get_llr(game->gfx);
197 ImmRenderer* imm = gfx_get_imm_renderer(game->gfx); 201 ImmRenderer* imm = gfx_get_imm_renderer(game->gfx);
202
203 gfx_llr_set_projection_matrix(llr, &state->projection);
204 gfx_llr_load_identity(llr);
198 gfx_imm_start(imm); 205 gfx_imm_start(imm);
199 gfx_imm_set_view_projection_matrix(imm, &state->viewProjection);
200 gfx_imm_load_identity(imm);
201 gfx_imm_set_colour(imm, vec4_make(1, 1, 1, 1)); 206 gfx_imm_set_colour(imm, vec4_make(1, 1, 1, 1));
202 draw_player(imm, &state->human); 207 draw_player(imm, &state->human);
203 draw_player(imm, &state->enemy); 208 draw_player(imm, &state->enemy);
@@ -213,7 +218,7 @@ void resize(Game* game, State* state, int width, int height) {
213 assert(game); 218 assert(game);
214 assert(state); 219 assert(state);
215 220
216 state->viewProjection = mat4_ortho(0, (R)width, 0, (R)height, -1, 1); 221 state->projection = mat4_ortho(0, (R)width, 0, (R)height, -1, 1);
217 222
218 state->human.position.y = PLAYER_Y_OFFSET; 223 state->human.position.y = PLAYER_Y_OFFSET;
219 state->enemy.position.y = (R)height - PLAYER_Y_OFFSET; 224 state->enemy.position.y = (R)height - PLAYER_Y_OFFSET;