ohsp

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

commit 8d688b8a74ec8b51db71103c8e4ef7846dcd2816
parent 66a5e8ef34618f8b4bf1e30a89947a281cbd0af1
Author: amin <dev@aminmesbah.com>
Date:   Fri, 10 Nov 2017 08:04:45 +0000

Wrap player position

FossilOrigin-Name: 4a1314a7dfe4886690ca38b8ec5024c9d2f05c9dfcd6b290ad7eda24146ff756
Diffstat:
Msrc/game.c | 21++++++++++++++++++++-
1 file changed, 20 insertions(+), 1 deletion(-)

diff --git a/src/game.c b/src/game.c @@ -35,6 +35,23 @@ void game_init(struct GameState *game_state, int field_width, int field_height) } +float wrap(float n, float min, float max) +{ + if (n > max) + { + return min; + } + else if (n < min) + { + return max; + } + else + { + return n; + } +} + + void game_update(struct GameState *game_state, struct GameControllerInput game_input, int field_width, int field_height) { if (!game_state) @@ -66,10 +83,12 @@ void game_update(struct GameState *game_state, struct GameControllerInput game_i game_state->thrust_vector02.length); struct Entity *player = &game_state->player; - entity_accelerate(player, game_state->thrust_vector_sum.angle, game_state->thrust_vector_sum.length * 0.001); + entity_accelerate(player, game_state->thrust_vector_sum.angle, game_state->thrust_vector_sum.length * 0.01); player->x += player->speed * cos(player->angle); player->y += player->speed * sin(player->angle); + player->x = wrap(player->x, 0, field_width); + player->y = wrap(player->y, 0, field_height); }