-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpathmap.php
72 lines (71 loc) · 2.12 KB
/
pathmap.php
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
<?php
include 'mapclass.php';
include 'dungeon.php';
include 'dblogin.php';
class Pathmap{
public $distances;
public function __construct($dungeonspace,$goal){
foreach ($dungeonspace->terrain as $index=>$type){
$this->distances[$index]=-1;
}
$this->distances[$goal]=0;
$edge=$dungeonspace->getnearindices($goal,1);
$step=1;
while (count($edge)>0){
foreach ($edge as $edgeindex=>$tileindex){
if ($dungeonspace->terrain[$tileindex]==1||$this->distances[$tileindex]>=0){
unset($edge[$edgeindex]);
} else {
$this->distances[$tileindex]=$step;
}
}
foreach ($edge as $edgeindex=>$tileindex){
$neartiles=$dungeonspace->getnearindices($tileindex,1);
foreach ($neartiles as $tileindex){
if ($dungeonspace->terrain[$tileindex]!=1&&
$this->distances[$tileindex]<0&&
!in_array($tileindex,$edge)){
$edge[]=$tileindex;
}
}
}
$step++;
}
}
public function drawpicture(){
$picture=imagecreatetruecolor(300,300);
$maxdistance=max($this->distances);
for ($i=0;$i<3600;$i++){
$tilexy = array(
"x"=>$i%60,
"y"=>floor($i/60),
);
$imagex = 5*$tilexy["x"];
$imagey = 5*$tilexy["y"];
if ($this->distances[$i]<0){
$colour=imagecolorallocate($picture,0,0,0);
} else {
$colour=imagecolorallocate($picture,intval(255*(1-$this->distances[$i]/$maxdistance)),0,intval(255*$this->distances[$i]/$maxdistance));
}
imagefilledrectangle($picture,$imagex,$imagey,$imagex+4,$imagey+4,$colour);
}
header('Content-Type: image/png');
imagepng($picture);
imagedestroy($picture);
}
}
session_start();
$floor=$_SESSION["currentfloor"];
$terrain=$_SESSION["terrain"][$floor];
$decals=$_SESSION["decals"][$floor];
$creatures=$_SESSION["creatures"][$floor];
$items=$_SESSION["items"][$floor];
$explored=$_SESSION["explored"][$floor];
$visible=$_SESSION["visible"][$floor];
$boardsize = array("x"=>60,"y"=>60);
$dungeonspace = new Terrain($boardsize,$terrain);
$dungeon = new Dungeon($dungeonspace,$creatures,$items,$explored,$decals,$visible);
$path=$dungeon->buildpath(260);
$reversepath=$dungeon->reversepath($path);
var_dump($path);
var_dump($reversepath);