momento/src/player/init.c

45 lines
852 B
C
Raw Normal View History

/* SPDX-License-Identifier: GPL-3.0-or-later */
/* Copyright (C) 2021 KikooDX */
#include "conf.h"
#include "level.h"
#include "player.h"
#include "tiles.h"
extern struct Level level;
struct Player player_init(void)
{
int x = 0;
int y = 0;
struct Player player = {
2021-03-30 22:57:49 +02:00
.spd_x = 0.0,
.spd_y = 0.0,
.rem_x = 0.0,
.rem_y = 0.0,
.k_jump_previous = 0,
.jump_buffer = 0,
.jump_grace = 0,
.jumps_left = 0,
.air_state = AirNeutral,
};
/* find spawn position in level */
x = level.width;
2021-04-08 00:38:40 +02:00
while (x-- > 0) {
y = level.height;
2021-04-08 00:38:40 +02:00
while (y-- > 0) {
if (level.data[x + y * level.width] ==
TILE_START) {
player.x =
x * TILE_WIDTH +
(TILE_WIDTH - PLAYER_WIDTH) / 2;
player.y = y * TILE_HEIGHT +
TILE_HEIGHT - PLAYER_HEIGHT;
return player;
}
}
}
return player;
}