2021-03-28 23:44:24 +02:00
|
|
|
/* 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,
|
2021-03-28 23:44:24 +02:00
|
|
|
.rem_x = 0.0,
|
|
|
|
.rem_y = 0.0,
|
2021-03-31 11:51:03 +02:00
|
|
|
.jump_buffer = 0,
|
|
|
|
.jump_grace = 0,
|
2021-04-03 23:49:14 +02:00
|
|
|
.jumps_left = 0,
|
2021-04-01 01:25:13 +02:00
|
|
|
.air_state = AirNeutral,
|
2021-03-28 23:44:24 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
/* find spawn position in level */
|
2021-04-08 00:21:26 +02:00
|
|
|
x = level.width;
|
2021-04-08 00:38:40 +02:00
|
|
|
while (x-- > 0) {
|
2021-04-08 00:21:26 +02:00
|
|
|
y = level.height;
|
2021-04-08 00:38:40 +02:00
|
|
|
while (y-- > 0) {
|
2021-03-28 23:44:24 +02:00
|
|
|
if (level.data[x + y * level.width] ==
|
|
|
|
TILE_START) {
|
2021-04-09 00:31:24 +02:00
|
|
|
/* set player position */
|
2021-03-28 23:44:24 +02:00
|
|
|
player.x =
|
|
|
|
x * TILE_WIDTH +
|
|
|
|
(TILE_WIDTH - PLAYER_WIDTH) / 2;
|
|
|
|
player.y = y * TILE_HEIGHT +
|
|
|
|
TILE_HEIGHT - PLAYER_HEIGHT;
|
2021-04-08 00:21:26 +02:00
|
|
|
return player;
|
2021-03-28 23:44:24 +02:00
|
|
|
}
|
2021-04-08 00:21:26 +02:00
|
|
|
}
|
|
|
|
}
|
2021-03-28 23:44:24 +02:00
|
|
|
return player;
|
|
|
|
}
|