initial commit
This commit is contained in:
commit
e8c3f9862a
193 files changed
+29795
No files matched your search
@@ -0,0 +1,56 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Game;
|
||||
|
||||
abstract class GameObject
|
||||
{
|
||||
private static int $nextId = 0;
|
||||
|
||||
public readonly int $eid;
|
||||
|
||||
public Vector2 $pos;
|
||||
|
||||
public Vector2 $velocity;
|
||||
|
||||
public float $width;
|
||||
|
||||
public float $height;
|
||||
|
||||
public function __construct(float $x = 0.0, float $y = 0.0)
|
||||
{
|
||||
$this->eid = ++self::$nextId;
|
||||
$this->pos = new Vector2($x, $y);
|
||||
$this->velocity = Vector2::zero();
|
||||
$this->width = 0.0;
|
||||
$this->height = 0.0;
|
||||
}
|
||||
|
||||
public function update(float $dt): void
|
||||
{
|
||||
$this->move($dt);
|
||||
}
|
||||
|
||||
/** Integrate position from velocity; used directly by subclasses that override update(). */
|
||||
public function move(float $dt): void
|
||||
{
|
||||
$this->pos = new Vector2(
|
||||
$this->pos->x + $this->velocity->x * $dt,
|
||||
$this->pos->y + $this->velocity->y * $dt,
|
||||
);
|
||||
}
|
||||
|
||||
public function intersects(GameObject $other): bool
|
||||
{
|
||||
return abs($this->pos->x - $other->pos->x) * 2.0 < $this->width + $other->width
|
||||
&& abs($this->pos->y - $other->pos->y) * 2.0 < $this->height + $other->height;
|
||||
}
|
||||
|
||||
public function removeFrom(EntityList $container): void
|
||||
{
|
||||
$container->remove($this);
|
||||
}
|
||||
|
||||
abstract public function kind(): string;
|
||||
}
|
||||
Reference in new issue
Block a user