forked from solcloud/Counter-Strike
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWall.php
More file actions
63 lines (52 loc) · 1.65 KB
/
Wall.php
File metadata and controls
63 lines (52 loc) · 1.65 KB
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
<?php
namespace cs\Core;
class Wall extends Plane
{
public function __construct(
Point $start,
private bool $widthOnXAxis = true,
public readonly int $width = 1,
public readonly int $height = 3800
)
{
if ($width <= 0 || $height <= 0) {
throw new GameException("Width and height cannot be lower than or equal zero");
}
if ($widthOnXAxis) {
parent::__construct($start, new Point($start->x + $width, $start->y + $height, $start->z), 'xy');
$this->setNormal(0, 0);
} else {
parent::__construct($start, new Point($start->x, $start->y + $height, $start->z + $width), 'zy');
$this->setNormal(90, 0);
}
}
public function getBase(): int
{
return ($this->widthOnXAxis ? $this->getStart()->z : $this->getStart()->x);
}
public function isWidthOnXAxis(): bool
{
return $this->widthOnXAxis;
}
public function getFloor(): int
{
return $this->point2DStart->y;
}
public function getCeiling(): int
{
return $this->point2DEnd->y;
}
public static function fromArray(array $data): self
{
$start = new Point($data['s']['x'], $data['s']['y'], $data['s']['z']);
$end = new Point($data['e']['x'], $data['e']['y'], $data['e']['z']);
$axis = $data['p'];
$widthOnXAxis = true;
$width = $end->x - $start->x;
if ($axis === 'zy') {
$widthOnXAxis = false;
$width = $end->z - $start->z;
}
return new self($start, $widthOnXAxis, $width, $end->y - $start->y);
}
}