/* 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 = { .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; while (x-- > 0) { y = level.height; 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; }