momento/src/player/init.c

40 lines
798 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,
};
/* find spawn position in level */
for (x = 0; x < level.width; x += 1)
for (y = 0; y < level.height; y += 1)
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;
goto found;
}
found:
return player;
}