ohsp

Prototype for a game with dual thruster controls.
git clone git://git.amin.space/ohsp.git
Log | Files | Refs | LICENSE

commit 794953f645df5bfa202f13f5f85f77f6913a50c1
parent e0f69810802448aa96b41897bf9803314e02c7e3
Author: amin <dev@aminmesbah.com>
Date:   Wed, 25 Oct 2017 05:41:28 +0000

Control two thrust vectors

FossilOrigin-Name: 41bf4bb1a2604babba702821b5023a5a243c6f32d0a731eae4566b9585beaf81
Diffstat:
Msrc/game.c | 42++++++++++++++++++++++++++++++++++--------
Msrc/game.h | 4+++-
2 files changed, 37 insertions(+), 9 deletions(-)

diff --git a/src/game.c b/src/game.c @@ -37,16 +37,31 @@ void game_update(struct GameState *game_state, struct GameControllerInput game_i 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); + game_state->thrust_vector01.angle = atan2f(game_input.left_stick_y, game_input.left_stick_x); + game_state->thrust_vector01.length = 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); + game_state->thrust_vector01.angle, + game_state->thrust_vector01.length); + + game_state->thrust_vector02.angle = atan2f(game_input.right_stick_y, game_input.right_stick_x); + game_state->thrust_vector02.length = hypotf(game_input.right_stick_x, game_input.right_stick_y); + printf("(rx: %f, ry: %f, thrust_a: %f, thrust_l: %f)\n", + game_input.right_stick_x, + game_input.right_stick_y, + game_state->thrust_vector02.angle, + game_state->thrust_vector02.length); + + game_state->thrust_vector_sum = vec2d_add( + game_state->thrust_vector01.angle, + game_state->thrust_vector01.length, + game_state->thrust_vector02.angle, + game_state->thrust_vector02.length); struct Entity *player = &game_state->player; - entity_accelerate(player, game_state->thrust_vector.angle, game_state->thrust_vector.length * 0.001); + entity_accelerate(player, game_state->thrust_vector_sum.angle, game_state->thrust_vector_sum.length * 0.001); + player->x += player->speed * cos(player->angle); player->y += player->speed * sin(player->angle); } @@ -62,15 +77,26 @@ 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)), + player.x + 100 * (game_state->thrust_vector01.length * cos(game_state->thrust_vector01.angle)), + player.y + 100 * (game_state->thrust_vector01.length * sin(game_state->thrust_vector01.angle)), 10, 0x0000FF); game_render_circle(buffer, + player.x + 100 * (game_state->thrust_vector02.length * cos(game_state->thrust_vector02.angle)), + player.y + 100 * (game_state->thrust_vector02.length * sin(game_state->thrust_vector02.angle)), + 10, + 0xFF0000); + game_render_circle(buffer, + player.x + 100 * (game_state->thrust_vector_sum.length * cos(game_state->thrust_vector_sum.angle)), + player.y + 100 * (game_state->thrust_vector_sum.length * sin(game_state->thrust_vector_sum.angle)), + 10, + 0xFF00FF); + + game_render_circle(buffer, player.x + 100 * (player.speed * cos(player.angle)), player.y + 100 * (player.speed * sin(player.angle)), 10, - 0xFF00FF); + 0x00FF00); } diff --git a/src/game.h b/src/game.h @@ -48,7 +48,9 @@ struct GameView struct GameState { struct Entity player; - struct Vec2d thrust_vector; + struct Vec2d thrust_vector01; + struct Vec2d thrust_vector02; + struct Vec2d thrust_vector_sum; struct GameView view; };