summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAmin Mesbah <mesbahamin@gmail.com>2017-11-10 00:04:46 -0800
committerAmin Mesbah <mesbahamin@gmail.com>2017-11-10 00:04:46 -0800
commitbde61bd1485d04205ee0509df7fd0f5b871004e5 (patch)
tree124de9e0522fbfe13f6186e421e367d41be70338 /src
parentbf032658c2b29421e689a9e5d106f6e01d76346b (diff)
downloadohsp-bde61bd1485d04205ee0509df7fd0f5b871004e5.zip
ohsp-bde61bd1485d04205ee0509df7fd0f5b871004e5.tar.gz
Wrap player position
Diffstat (limited to 'src')
-rw-r--r--src/game.c21
1 files changed, 20 insertions, 1 deletions
diff --git a/src/game.c b/src/game.c
index 83f89f1..776aac7 100644
--- 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);
}