summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/game.c26
-rw-r--r--src/game.h1
-rw-r--r--src/platform_sdl.c11
-rw-r--r--src/platform_sdl.h2
4 files changed, 29 insertions, 11 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)
diff --git a/src/game.h b/src/game.h
index 1b8f957..06dc9e1 100644
--- a/src/game.h
+++ b/src/game.h
@@ -48,6 +48,7 @@ struct GameView
struct GameState
{
struct Entity player;
+ struct Vec2d thrust_vector;
struct GameView view;
};
diff --git a/src/platform_sdl.c b/src/platform_sdl.c
index f31bc58..f6bc08e 100644
--- a/src/platform_sdl.c
+++ b/src/platform_sdl.c
@@ -69,6 +69,7 @@ void clear_screen(struct SDLOffscreenBuffer *buffer, uint32_t pixel_value)
}
+// TODO: make the deadzone circular
float sdl_process_controller_axis_value(int16_t value, int16_t deadzone_threshold)
{
float result = 0.0;
@@ -120,11 +121,11 @@ bool sdl_handle_event(SDL_Event *event, struct GameControllerInput *controller_i
// down and right are positive
float normalized_axis_value = sdl_process_controller_axis_value(event->caxis.value, DEADZONE_THRESHOLD);
- printf("SDL_CONTROLLERAXISMOTION (%d, %s, %d, %f)\n",
- event->caxis.which,
- SDL_GameControllerGetStringForAxis(event->caxis.axis),
- event->caxis.value,
- normalized_axis_value);
+ //printf("SDL_CONTROLLERAXISMOTION (%d, %s, %d, %f)\n",
+ // event->caxis.which,
+ // SDL_GameControllerGetStringForAxis(event->caxis.axis),
+ // event->caxis.value,
+ // normalized_axis_value);
switch(event->caxis.axis)
{
diff --git a/src/platform_sdl.h b/src/platform_sdl.h
index fa66f96..e33835e 100644
--- a/src/platform_sdl.h
+++ b/src/platform_sdl.h
@@ -3,7 +3,7 @@
#include "SDL.h"
#define MAX_CONTROLLERS 4
-#define DEADZONE_THRESHOLD 1000
+#define DEADZONE_THRESHOLD 9000
struct SDLOffscreenBuffer
{