Moved player init code main.c->player.c

This commit is contained in:
KikooDX 2021-01-09 10:42:16 +01:00
parent 493eacdf55
commit bffaf264dd
3 changed files with 14 additions and 10 deletions

View File

@ -20,6 +20,7 @@ typedef struct Player {
#include "camera.h"
#include "input.h"
void player_init(Player *player);
void player_move(Player *player, const Level *level);
void player_step(Player *player, Input *input, const Level *level, uint step);
void player_draw(Player *player, Camera *camera);

View File

@ -28,16 +28,8 @@ int main(void) {
int play_level(uint level_id) {
/* create player */
Player player = {
.pos = {TILE_SIZE, TILE_SIZE},
.spd = {0, 0},
.hbox = {TILE_SIZE - 1, TILE_SIZE - 1},
.vbox = {7, 7},
.origin = {0 * VEC_PRECISION, 0 * VEC_PRECISION},
.grace = 0,
.jump_held = false,
.dead = false
};
Player player;
player_init(&player);
/* set level */
const Level *level;

View File

@ -23,6 +23,17 @@
#define SGN(x) (((x) > 0) ? (1) : (((x) < 0) ? (-1) : (0)))
#define PLAYER_COLLIDE_SOLID(pos) (player_collide_or(player, pos, level) & F_SOLID)
void player_init(Player *player) {
player->pos = (Vec){TILE_SIZE, TILE_SIZE};
player->spd = (Vec){0, 0};
player->hbox = (Vec){TILE_SIZE - 1, TILE_SIZE - 1};
player->vbox = (Vec){7, 7};
player->origin = (Vec){0 * VEC_PRECISION, 0 * VEC_PRECISION};
player->grace = 0;
player->jump_held = false;
player->dead = false;
}
void player_move(Player *player, const Level *level) {
/* TODO: Take into account player's hitbox */
const int sgn_spd_x = SGN(player->spd.x);