Bomberman Multiplayer
Authoritative multiplayer networking layer for Bomberman.
Loading...
Searching...
No Matches
SpawnSlots.h
Go to the documentation of this file.
1
6#ifndef BOMBERMAN_SIM_SPAWNSLOTS_H
7#define BOMBERMAN_SIM_SPAWNSLOTS_H
8
9#include <array>
10#include <cstddef>
11#include <cstdint>
12
13#include "Sim/Movement.h"
14
15namespace bomberman::sim
16{
17 constexpr uint8_t kLeftSpawnCol = 1;
18 constexpr uint8_t kRightSpawnCol = static_cast<uint8_t>(tileArrayWidth - 2);
19 constexpr uint8_t kTopSpawnRow = 1;
20 constexpr uint8_t kBottomSpawnRow = 9;
21
24 {
25 uint8_t col = 0;
26 uint8_t row = 0;
27 };
28
36 constexpr std::array<SpawnSlotCell, 4> kDefaultSpawnSlots{{
37 {kLeftSpawnCol, kTopSpawnRow},
38 {kLeftSpawnCol, kBottomSpawnRow},
39 {kRightSpawnCol, kTopSpawnRow},
40 {kRightSpawnCol, kBottomSpawnRow},
41 }};
42
43 static_assert(baseTiles[kTopSpawnRow][kLeftSpawnCol] == Tile::EmptyGrass, "Top-left spawn must stay clear");
44 static_assert(baseTiles[kBottomSpawnRow][kLeftSpawnCol] == Tile::EmptyGrass, "Bottom-left spawn must stay clear");
45 static_assert(baseTiles[kTopSpawnRow][kRightSpawnCol] == Tile::EmptyGrass, "Top-right spawn must stay clear");
46 static_assert(baseTiles[kBottomSpawnRow][kRightSpawnCol] == Tile::EmptyGrass, "Bottom-right spawn must stay clear");
47
49 [[nodiscard]]
50 constexpr SpawnSlotCell spawnSlotCellForPlayerId(const uint8_t playerId)
51 {
52 return kDefaultSpawnSlots[static_cast<std::size_t>(playerId) % kDefaultSpawnSlots.size()];
53 }
54
56 [[nodiscard]]
58 {
59 return {
60 static_cast<int32_t>(slot.col) * 256 + 128,
61 static_cast<int32_t>(slot.row) * 256 + 128
62 };
63 }
64
66 [[nodiscard]]
67 constexpr TilePos spawnTilePosForPlayerId(const uint8_t playerId)
68 {
70 }
71
72} // namespace bomberman::sim
73
74#endif // BOMBERMAN_SIM_SPAWNSLOTS_H
constexpr unsigned int tileArrayWidth
Tile map width in tiles.
Definition Const.h:43
Shared authoritative movement simulation primitives.
Shared simulation primitives and constants used by both the client and the authoritative server.
Definition Movement.h:21
constexpr std::array< SpawnSlotCell, 4 > kDefaultSpawnSlots
Default player-id keyed spawn slots for the current arena layout.
Definition SpawnSlots.h:36
constexpr TilePos spawnSlotTilePos(const SpawnSlotCell slot)
Converts one tile-cell spawn slot to a center-position tile-Q8 coordinate.
Definition SpawnSlots.h:57
constexpr SpawnSlotCell spawnSlotCellForPlayerId(const uint8_t playerId)
Returns the default spawn slot assigned to the given player id.
Definition SpawnSlots.h:50
constexpr TilePos spawnTilePosForPlayerId(const uint8_t playerId)
Returns the default center-position tile-Q8 spawn for the given player id.
Definition SpawnSlots.h:67
One multiplayer spawn slot expressed in tile-cell coordinates.
Definition SpawnSlots.h:24
Tile-space Q8 position representing the CENTER of the entity.
Definition Movement.h:30