diff --git a/inc/conf.h b/inc/conf.h index 54abfe1..3ef3a21 100644 --- a/inc/conf.h +++ b/inc/conf.h @@ -7,7 +7,7 @@ #define GRAVITY 0.2f #define AIR_RESISTANCE 0.03f #define MAX_WALK_SPEED 2.0f -#define ACCELERATION_AIR 0.1f +#define ACCELERATION_AIR 0.4f #define ACCELERATION_GROUND 0.4f #define FRICTION_AIR (ACCELERATION_AIR / MAX_WALK_SPEED) #define FRICTION_GROUND (ACCELERATION_GROUND / MAX_WALK_SPEED) @@ -15,3 +15,4 @@ #define JUMP_GRACE 1 #define JUMP_BUFFER 12 #define JUMP_SPD -4.4 +#define WJUMP_LOCK 15 diff --git a/inc/player.h b/inc/player.h index 78a6a8d..8b9757c 100644 --- a/inc/player.h +++ b/inc/player.h @@ -8,6 +8,7 @@ struct Player { int jump_grace; int jump_buffer; int lock_direction; + int last_direction; }; void player_init(struct Vec pos); diff --git a/src/level.c b/src/level.c index 3ad3059..9a358de 100644 --- a/src/level.c +++ b/src/level.c @@ -19,9 +19,8 @@ level_load(struct LevelBin *s) self.size = i; self.data = malloc(i); self.source = s; - while (i-- > 0) { + while (i-- > 0) self.data[i] = s->data[i]; - } } void diff --git a/src/player.c b/src/player.c index d3f824b..185d595 100644 --- a/src/player.c +++ b/src/player.c @@ -25,6 +25,7 @@ player_init(struct Vec pos) self.jump_grace = 0; self.jump_buffer = 0; self.lock_direction = 0; + self.last_direction = 1; } void @@ -33,8 +34,14 @@ player_update(void) const int on_ground = collide_solid(self.pos.x, self.pos.y + 1); struct Vec dir = VEC(input_down(K_RIGHT) - input_down(K_LEFT), input_down(K_DOWN) - input_down(K_UP)); - if (self.lock_direction && dir.x != self.lock_direction) - dir.x = 0; + if (self.lock_direction) { + self.lock_direction--; + if (self.spd.x == 0.0f) + self.lock_direction = 0; + else + dir.x = self.last_direction; + } else if (dir.x) + self.last_direction = dir.x; /* acceleration & friction */ if (on_ground && !dir.x) { @@ -106,7 +113,8 @@ walljump(void) self.jump_buffer = 0; self.spd.y = JUMP_SPD; self.spd.x = wall_adjacent * MAX_WALK_SPEED; - self.lock_direction = wall_adjacent; + self.lock_direction = WJUMP_LOCK; + self.last_direction = wall_adjacent; shatter_pos.x += (wall_adjacent == 1) ? (-2) : (PLAYER_WIDTH + 1); shatter(shatter_pos.x, shatter_pos.y);