summaryrefslogtreecommitdiff
path: root/src/game.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/game.c')
-rw-r--r--src/game.c26
1 files changed, 21 insertions, 5 deletions
diff --git a/src/game.c b/src/game.c
index 5ac4f25..b067fb4 100644
--- a/src/game.c
+++ b/src/game.c
@@ -1,4 +1,6 @@
#include "game.h"
+// TODO: remove this
+#include <math.h>
#include <stdbool.h>
#include <stdio.h>
@@ -34,6 +36,14 @@ void game_update(struct GameState *game_state, struct GameControllerInput game_i
// TODO: handle invalid pointer error
return;
}
+
+ game_state->thrust_vector.angle = atan2f(game_input.left_stick_y, game_input.left_stick_x);
+ game_state->thrust_vector.length = 100 * hypotf(game_input.left_stick_x, game_input.left_stick_y);
+ printf("(lx: %f, ly: %f, thrust_a: %f, thrust_l: %f)\n",
+ game_input.left_stick_x,
+ game_input.left_stick_y,
+ game_state->thrust_vector.angle,
+ game_state->thrust_vector.length);
}
@@ -46,6 +56,11 @@ void game_render(struct OffscreenBuffer *buffer, float dt, struct GameState *gam
}
struct Entity player = game_state->player;
game_render_circle(buffer, player.x, player.y, player.size, player.color);
+ game_render_circle(buffer,
+ player.x + (game_state->thrust_vector.length * cos(game_state->thrust_vector.angle)),
+ player.y + (game_state->thrust_vector.length * sin(game_state->thrust_vector.angle)),
+ 10,
+ 0x0000FF);
}
@@ -63,11 +78,6 @@ void game_render_circle(struct OffscreenBuffer *buffer, float center_x, float ce
}
}
-float game_calc_render_offset(float zoom, float delta, float pos, float center)
-{
- return ((1 - zoom) * center) + (pos + delta) * zoom;
-}
-
void game_set_pixel(struct OffscreenBuffer *buffer, uint32_t x, uint32_t y, uint32_t color)
{
@@ -91,6 +101,12 @@ void game_set_pixel(struct OffscreenBuffer *buffer, uint32_t x, uint32_t y, uint
}
+float game_calc_render_offset(float zoom, float delta, float pos, float center)
+{
+ return ((1 - zoom) * center) + (pos + delta) * zoom;
+}
+
+
void game_cleanup(struct GameState *game_state)
{
if (!game_state)