mirror of https://git.sr.ht/~kikoodx/crystal-tower
base sideview physics
This commit is contained in:
parent
c0c4630095
commit
69fb783dc6
16
inc/conf.h
16
inc/conf.h
|
@ -1,6 +1,14 @@
|
|||
#pragma once
|
||||
|
||||
#define TARGET_FPS 60
|
||||
#define TILE_SIZE 16
|
||||
#define PLAYER_WIDTH 12
|
||||
#define PLAYER_HEIGHT 12
|
||||
#define TARGET_FPS 60
|
||||
#define TILE_SIZE 16
|
||||
#define PLAYER_WIDTH 14
|
||||
#define PLAYER_HEIGHT 14
|
||||
#define GRAVITY 0.2f
|
||||
#define AIR_RESISTANCE 0.02f
|
||||
#define MAX_WALK_SPEED 2.0f
|
||||
#define ACCELERATION_AIR 0.1f
|
||||
#define ACCELERATION_GROUND 0.4f
|
||||
#define FRICTION_AIR (ACCELERATION_AIR / MAX_WALK_SPEED)
|
||||
#define FRICTION_GROUND (ACCELERATION_GROUND / MAX_WALK_SPEED)
|
||||
#define FRICTION_BREAK (0.6f / MAX_WALK_SPEED)
|
||||
|
|
21
src/player.c
21
src/player.c
|
@ -1,5 +1,6 @@
|
|||
#include "player.h"
|
||||
#include "conf.h"
|
||||
#include "input.h"
|
||||
#include "level.h"
|
||||
#include "util.h"
|
||||
#include "vec.h"
|
||||
|
@ -20,7 +21,25 @@ player_init(struct Vec pos)
|
|||
void
|
||||
player_update(void)
|
||||
{
|
||||
self.spd.x = 0.9f;
|
||||
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));
|
||||
|
||||
/* acceleration & friction */
|
||||
if (on_ground && !dir.x) {
|
||||
self.spd.x *= 1.0f * FRICTION_BREAK;
|
||||
} else {
|
||||
self.spd.x *=
|
||||
1.0f - (on_ground ? FRICTION_GROUND : FRICTION_AIR);
|
||||
self.spd.x +=
|
||||
(on_ground ? ACCELERATION_GROUND : ACCELERATION_AIR) *
|
||||
dir.x;
|
||||
}
|
||||
|
||||
/* resistance & gravity */
|
||||
self.spd.y *= 1.0f - AIR_RESISTANCE;
|
||||
self.spd.y += GRAVITY;
|
||||
|
||||
player_move(player_update_rem());
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue