actually fun gameplay

This commit is contained in:
KikooDX 2021-11-11 16:03:17 +01:00
parent 5f14f2394a
commit 31536578fa
4 changed files with 15 additions and 6 deletions

View File

@ -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

View File

@ -8,6 +8,7 @@ struct Player {
int jump_grace;
int jump_buffer;
int lock_direction;
int last_direction;
};
void player_init(struct Vec pos);

View File

@ -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

View File

@ -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);