php db new PDO mysql host 127 dbname alonar charset UTF8 root _user db

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
<?php
$db = new PDO('mysql:host=127.0.0.1;dbname=alonar;charset=UTF8', 'root', '');
$_user = $db -> prepare('SELECT * FROM `users` WHERE `id` = ?');
$_user -> execute([1]);
$user = $_user -> fetch();
$coord = [
'x' => $user['x'],
'y' => $user['y']
];
$max_x = ($coord['x'] - 2 < 0 ? 0 : $coord['x'] - 2);
$max_y = ($coord['y'] - 2 < 0 ? 0 : $coord['y'] - 2);
$min_x = $coord['x'] + 3;
$min_y = $coord['y'] + 3;
$map_arr = [
'0.0' => '8.png',
'0.1' => '1.png',
'0.2' => '1.png',
'0.3' => '1.png',
'0.4' => '2.png',
'1.0' => '7.png',
'1.1' => '9.png',
'1.2' => '9.png',
'1.3' => '9.png',
'1.4' => '3.png',
'2.0' => '7.png',
'2.1' => '9.png',
'2.2' => '9.png',
'2.3' => '9.png',
'2.4' => '3.png',
'3.0' => '7.png',
'3.1' => '9.png',
'3.2' => '9.png',
'3.3' => '9.png',
'3.4' => '3.png',
'4.0' => '6.png',
'4.1' => '5.png',
'4.2' => '5.png',
'4.3' => '5.png',
'4.4' => '4.png',
];
switch($_GET['i']){
default:
echo '
<style>
.map {
position:absolute;
left:0px;
}
.map a.href{
width:16px;
height:16px;
position:absolute;
}
</style>
<div class="map">
';
for ($x = $max_x; $x < $min_x; ++$x) {
for ($y = $max_y; $y < $min_y; ++$y) {
echo '
<a class="href" style="left:'.($y * 16).'px;top:'.($x * 16).'px;" href="?x='.$x.'&y='.$y.'"></a>
';
}
}
echo '
<img class="ss" src="?i=image" />
</div>
';
break;
case 'image':
$image = new Imagick();
$image->newImage(5*16, 5*16, new ImagickPixel('white'));
$image->setImageFormat('png');
for ($x = $max_x; $x < $min_x; ++$x) {
for ($y = $max_y; $y < $min_y; ++$y) {
if ($map_arr[$x.'.'.$y]) $map = new Imagick('C:/OpenServer/domains/lol/map/'.$map_arr[$x.'.'.$y]);
else $map = new Imagick('C:/OpenServer/domains/lol/map/7.png');
$image->compositeImage($map, $map->getImageCompose(), $y * 16, $x * 16);
if($coord['x'] == $x and $coord['y'] == $y){
$user = new Imagick('C:/OpenServer/domains/lol/char/1/1.png');
$image->compositeImage($user, $user->getImageCompose(), $y * 16, $x * 16);
}
}
}
header('Content-type: image/png');
echo $image;
break;
}