PHPackages                             pew-pew/map - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. pew-pew/map

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

pew-pew/map
===========

Map loader and entities component

0.3.0(2y ago)03.1k↑25%MITPHPPHP ^8.3

Since Mar 8Pushed 2y ago1 watchersCompare

[ Source](https://github.com/pew-pew-team/map)[ Packagist](https://packagist.org/packages/pew-pew/map)[ RSS](/packages/pew-pew-map/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (4)Dependencies (6)Versions (5)Used By (0)

 [![](https://raw.githubusercontent.com/pew-pew-team/.github/master/assets/logo.svg)](https://github.com/pew-pew-team)

 [![PHP 8.3+](https://camo.githubusercontent.com/14ef1c909d2211d9d8b69f3524b8f23aa7592cd7723c161b54a4d8c9b49d2269/68747470733a2f2f706f7365722e707567782e6f72672f7065772d7065772f6d61702f726571756972652f7068703f7374796c653d666f722d7468652d6261646765)](https://packagist.org/packages/pew-pew/map) [![Latest Stable Version](https://camo.githubusercontent.com/87c2777e379278f530b8c76d80ff85a0cba833adc023769fa77b28ec5f1e4f41/68747470733a2f2f706f7365722e707567782e6f72672f7065772d7065772f6d61702f76657273696f6e3f7374796c653d666f722d7468652d6261646765)](https://packagist.org/packages/pew-pew/map) [![Latest Unstable Version](https://camo.githubusercontent.com/580158e01b62db821dd18069b7eea4f35458fea3e14547bba7c319901316b9cf/68747470733a2f2f706f7365722e707567782e6f72672f7065772d7065772f6d61702f762f756e737461626c653f7374796c653d666f722d7468652d6261646765)](https://packagist.org/packages/pew-pew/map) [![License MIT](https://camo.githubusercontent.com/cfd56d26487f0e86bc91ba5ee1e3d7beceddb4ffa423b2c47fa20d6e8862da82/68747470733a2f2f706f7365722e707567782e6f72672f7065772d7065772f6d61702f6c6963656e73653f7374796c653d666f722d7468652d6261646765)](https://raw.githubusercontent.com/pew-pew-team/map/blob/master/LICENSE)

 [![](https://github.com/pew-pew-team/map/workflows/tests/badge.svg)](https://github.com/pew-pew-team/map/actions) [![](https://github.com/pew-pew-team/map/workflows/codestyle/badge.svg)](https://github.com/pew-pew-team/map/actions) [![](https://github.com/pew-pew-team/map/workflows/security/badge.svg)](https://github.com/pew-pew-team/map/actions) [![](https://github.com/pew-pew-team/map/workflows/static-analysis/badge.svg)](https://github.com/pew-pew-team/map/actions)

Map
===

[](#map)

This component provides basic DTOs for storing, analyzing and transmitting game maps data, as well as loaders for loading this data from arbitrary formats.

Installation
------------

[](#installation)

PewPew Map is available as Composer repository and can be installed using the following command in a root of your project:

```
$ composer require pew-pew/map
```

More detailed installation [instructions are here](https://getcomposer.org/doc/01-basic-usage.md).

Usage
-----

[](#usage)

Below is a list of available component value objects, their parameters and methods.

### Size

[](#size)

The size object is responsible for the physical two-dimensional dimensions of arbitrary objects.

```
$size = new \PewPew\Map\Data\Size\IntSize(
    width: 100, // optional, default = 1
    height: 50, // optional, default = 1
);
```

**Size Area**

Get the total area of an object provided by size.

```
$size = new \PewPew\Map\Data\Size\IntSize(100, 50);

echo $size->getArea(); // 5000
```

**Position By ID**

In particular, any 3x3 object can be represented in the following form, where each number denotes the corresponding identifier:

```
┌─────┬─────┬─────┐   ┌─────┬─────┬─────┐
│ 0x0 │ 1x0 │ 2x0 │   │  0  │  2  │  3  │
├─────┼─────┼─────┤   ├─────┼─────┼─────┤
│ 0x1 │ 1x1 │ 2x1 │ → │  4  │  5  │  6  │
├─────┼─────┼─────┤   ├─────┼─────┼─────┤
│ 0x2 │ 1x2 │ 2x2 │   │  7  │  8  │  9  │
└─────┴─────┴─────┘   └─────┴─────┴─────┘

```

Any coordinates can be represented as a scalar ID. To obtain a position by this ID, you can use the following methods.

```
$size = new \PewPew\Map\Data\Size\IntSize(3, 3);

echo $size->getX(id: 1); // X = 1
echo $size->getY(id: 1); // Y = 0

echo $size->getPosition(id: 1); // object { x: 1, y: 0 }
```

### Position

[](#position)

A position is a primitive object that provides coordinates within an object.

The object does not provide any additional methods.

```
$position = new \PewPew\Map\Data\Position\IntPosition(
    x: 1, // optional, default = 0
    y: 0, // optional, default = 0
);
```

### Layers

[](#layers)

A layer is one of the map elements that can define a set of objects to draw, a set of collisions, a set of triggers, or anything else.

Each layer contains a position within the map and its own size.

```
$layer = new \PewPew\Map\Data\Layer(
    // optional, default = { width: 1, height: 1 }
    size: new \PewPew\Map\Data\Size\IntSize(
        width: 3,
        height: 3,
    ),
    // optional, default = { x: 0, y: 0 }
    position: new \PewPew\Map\Data\Position\IntPosition(
        x: 0,
        y: 0,
    ),
);
```

**Tiles Layer**

For a layer containing tiles, you should create a corresponding `PewPew\Map\Data\TilesLayer` object. In addition to `size` and `position`, it also contains an array of tile IDs.

The size of the tiles array directly depends on the size of the layer and can be obtained using the `Size::getArea()` method.

Note

For the 3x3 layer, the number of used tile elements corresponds to 9. If there are extra tiles, they are not used.

Note

If any tile ID is missing, then it corresponds to 0, that means no tile.

```
$layer = new \PewPew\Map\Data\Layer\TilesLayer(
    tiles: [
        0, 2, 1,
        1, 2, 1,
        0, 0, 1,
    ],
    size: new \PewPew\Map\Data\Size\IntSize(3, 3),
);
```

### TileSet

[](#tileset)

A tile set is an object containing information about an image containing a set of other images (tiles).

```
$tileSet = new \PewPew\Map\Data\TileSet(
    // required
    pathname: __DIR__ . '/tiles.png',
    // optional, default = 1
    tileIdStartsAt: 1,
    // optional, default = { width: 1, height: 1 }
    size: new \PewPew\Map\Data\Size\IntSize(
        width: 3,
        height: 3,
    ),
);
```

The `tileIdStartsAt` constructor parameter is responsible for the starting ID of the tile, so a 2x2 tile set with `tileIdStartsAt: 42` will contains `42`, `43`, `44` and `45` tile IDs.

Warning

The "tileIdStartsAt" cannot be less than 1.

**Tile ID Availability**

To check the availability of a tile ID, you can use the `containsId()` method.

```
$set = new \PewPew\Map\Data\TileSet(
    pathname: ...,
    tileIdStartsAt: 1,
    size: new \PewPew\Map\Data\Size\IntSize(1, 1),
);

$set->containsId(tileId: 0); // bool(false)
$set->containsId(tileId: 1); // bool(true)
$set->containsId(tileId: 2); // bool(false)
```

**Position Of A Tile**

```
$set = new \PewPew\Map\Data\TileSet( ... );

$set->getX(tileId: 1);          // X = 0
$set->getY(tileId: 1);          // Y = 0

$set->getPosition(tileId: 1);   // object { x: 0, y: 0 }
```

**Updating Tile Pathname**

```
$previous = new \PewPew\Map\Data\TileSet(
    pathname: __DIR__ . '/tiles-1.png',
);

$new = $previous->withPathname(
    pathname: __DIR__ . '/tiles-2.png',
);

echo $previous->pathname; // string(".../tiles-1.png")
echo $new->pathname; // string(".../tiles-2.png")
```

Examples
--------

[](#examples)

Example map

```
use PewPew\Map\Data\Layer\TilesLayer;
use PewPew\Map\Data\Size\IntSize;
use PewPew\Map\Data\TileSet;
use PewPew\Map\Map;

$map = new Map(
    layers: [
        new TilesLayer(
            tiles: [
                0, 1, 2,
                0, 1, 1,
                1, 2, 1,
            ],
            size: new IntSize(3, 3),
        ),
    ],
    tileSets: [
        new TileSet(
            pathname: __DIR__ . '/tiles.png',
            size: new IntSize(2, 2),
        ),
    ],
    size: new IntSize(3, 3),
);

echo \json_encode($map);
```

Expected output:

```
{
    "layers": [
        {
            "size": { "width": 3, "height": 3 },
            "position": { "x": 0, "y": 0 },
            "tiles": [
                0, 1, 2,
                0, 1, 1,
                1, 2, 1
            ]
        }
    ],
    "tileSets": [
        {
            "pathname": "..path/to/map/tiles.png",
            "tileIdStartsAt": 1,
            "size": { "width": 2, "height": 2 }
        }
    ],
    "size": { "width": 3, "height": 3 }
}
```

###  Health Score

27

—

LowBetter than 49% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity21

Limited adoption so far

Community4

Small or concentrated contributor base

Maturity49

Maturing project, gaining track record

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~2 days

Total

4

Last Release

794d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/150420?v=4)[Ruslan Sharipov](/maintainers/Serafim)[@serafim](https://github.com/serafim)

---

Tags

dtoloadermaptilesets

###  Code Quality

TestsPHPUnit

Static AnalysisPsalm

Code StylePHP CS Fixer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/pew-pew-map/health.svg)

```
[![Health](https://phpackages.com/badges/pew-pew-map/health.svg)](https://phpackages.com/packages/pew-pew-map)
```

###  Alternatives

[joetannenbaum/mr-clean

23044.5k](/packages/joetannenbaum-mr-clean)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
