summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAmin Mesbah <mesbahamin@gmail.com>2017-10-24 22:41:29 -0700
committerAmin Mesbah <mesbahamin@gmail.com>2017-10-24 22:41:29 -0700
commitadb9c001034df1ee3948320b1022b3b4f2ccdc8a (patch)
tree68bd3fdf6eb2ce9f6d31100bafab932155bb49d5 /src
parent4bdfd2a5efd2151d32275cb48e96ac1e981bbfb9 (diff)
downloadohsp-adb9c001034df1ee3948320b1022b3b4f2ccdc8a.zip
ohsp-adb9c001034df1ee3948320b1022b3b4f2ccdc8a.tar.gz
Control two thrust vectors
Diffstat (limited to 'src')
-rw-r--r--src/game.c42
-rw-r--r--src/game.h4
2 files changed, 37 insertions, 9 deletions
diff --git a/src/game.c b/src/game.c
index 946d53a..7065572 100644
--- 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
index 06dc9e1..2cec081 100644
--- 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;
};