Загрузил(а) файлы в 'src/Insallah/Player'

Signed-off-by: Ivor Barhansky <lopar@noreply.lopar.us>
This commit is contained in:
Ivor Barhansky 2022-02-20 23:12:11 +00:00
parent b714e32dcc
commit d7c85bc110

View File

@ -0,0 +1,45 @@
<?php
# Date: 20.02.2022 (17:47)
namespace Insallah\Player;
class Player
{
public static function start(array $xy, $force = null)
{
if (!isset($_SESSION['x']) || !isset($_SESSION['y']) || !is_null($force)) {
$_SESSION['x'] = $xy[0];
$_SESSION['y'] = $xy[1];
}
}
public static function getPos(): array
{
return [$_SESSION['x'], $_SESSION['y']];
}
/**
* @param int $x_pos
*/
public static function modXPos(int $x_pos): void
{
if ($_SESSION['x'] + $x_pos >= 0) {
$_SESSION['x'] += $x_pos;
}
}
/**
* @param int $y_pos
*/
public static function modYPos(int $y_pos): void
{
if ($_SESSION['y'] + $y_pos >= 0) {
$_SESSION['y'] += $y_pos;
}
}
public static function clear()
{
session_destroy();
header('Location: ' . $_SERVER['REQUEST_URI']);
}
}