mirror of https://git.sr.ht/~kikoodx/crystal-tower
lock direction after walljump
This commit is contained in:
parent
cbf55c5d38
commit
a51212acc7
|
@ -7,6 +7,7 @@ struct Player {
|
|||
struct VecF rem;
|
||||
int jump_grace;
|
||||
int jump_buffer;
|
||||
int lock_direction;
|
||||
};
|
||||
|
||||
void player_init(struct Vec pos);
|
||||
|
|
|
@ -2,3 +2,4 @@
|
|||
|
||||
int sign(int);
|
||||
float signf(float);
|
||||
int abs(int);
|
||||
|
|
16
src/player.c
16
src/player.c
|
@ -22,14 +22,17 @@ player_init(struct Vec pos)
|
|||
self.rem = VECFZ;
|
||||
self.jump_grace = 0;
|
||||
self.jump_buffer = 0;
|
||||
self.lock_direction = 0;
|
||||
}
|
||||
|
||||
void
|
||||
player_update(void)
|
||||
{
|
||||
const int on_ground = collide_solid(self.pos.x, self.pos.y + 1);
|
||||
const struct Vec dir = VEC(input_down(K_RIGHT) - input_down(K_LEFT),
|
||||
input_down(K_DOWN) - input_down(K_UP));
|
||||
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;
|
||||
|
||||
/* acceleration & friction */
|
||||
if (on_ground && !dir.x) {
|
||||
|
@ -56,6 +59,10 @@ player_update(void)
|
|||
if (!jump(on_ground))
|
||||
walljump();
|
||||
|
||||
/* unlock direction */
|
||||
if (self.lock_direction && abs(self.spd.x) < MAX_WALK_SPEED / 2)
|
||||
self.lock_direction = 0;
|
||||
|
||||
player_move(player_update_rem());
|
||||
}
|
||||
|
||||
|
@ -92,6 +99,7 @@ walljump(void)
|
|||
self.jump_buffer = 0;
|
||||
self.spd.y = JUMP_SPD;
|
||||
self.spd.x = wall_adjacent * MAX_WALK_SPEED;
|
||||
self.lock_direction = wall_adjacent;
|
||||
shatter_pos.x +=
|
||||
(wall_adjacent == 1) ? (-2) : (PLAYER_WIDTH + 1);
|
||||
shatter(shatter_pos.x, shatter_pos.y);
|
||||
|
@ -125,8 +133,8 @@ player_update_rem(void)
|
|||
void
|
||||
player_move(struct Vec spd)
|
||||
{
|
||||
float sign_x = signf(spd.x);
|
||||
const float sign_y = signf(spd.y);
|
||||
float sign_x = signf(self.spd.x);
|
||||
const float sign_y = signf(self.spd.y);
|
||||
if (!sign_x && !sign_y)
|
||||
sign_x = 1.0f;
|
||||
|
||||
|
|
|
@ -11,3 +11,9 @@ signf(float n)
|
|||
{
|
||||
return (n > 0.0) - (n < 0.0);
|
||||
}
|
||||
|
||||
int
|
||||
abs(int n)
|
||||
{
|
||||
return (n > 0) ? (n) : (-n);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue