@@ -15,12 +15,13 @@ class PickupSpawner
1515 * Scan the game layer for pickup entities and spawn them in the world.
1616 *
1717 * @param array<int, int> $respawnTimes Entity type => respawn ticks (-1 = never respawn)
18+ * @param array<int, int> $spawnDelays Entity type => initial spawn delay in ticks (0 = immediately available)
1819 */
19- public static function spawn (AbstractWorld $ world , GameLayer $ gameLayer , array $ respawnTimes = []): void
20+ public static function spawn (AbstractWorld $ world , GameLayer $ gameLayer , array $ respawnTimes = [], array $ spawnDelays = [] ): void
2021 {
2122 foreach ($ gameLayer ->getEntityPositions () as $ entity ) {
2223 $ pos = new Vector2 ($ entity ['x ' ], $ entity ['y ' ]);
23- $ pickup = self ::createPickup ($ entity ['type ' ], $ pos , $ respawnTimes );
24+ $ pickup = self ::createPickup ($ entity ['type ' ], $ pos , $ respawnTimes, $ spawnDelays );
2425
2526 if ($ pickup !== null ) {
2627 $ world ->addEntity ($ pickup );
@@ -32,18 +33,20 @@ public static function spawn(AbstractWorld $world, GameLayer $gameLayer, array $
3233 * Map a game layer entity type to a PickupEntity.
3334 *
3435 * @param array<int, int> $respawnTimes
36+ * @param array<int, int> $spawnDelays
3537 */
36- private static function createPickup (int $ entityType , Vector2 $ pos , array $ respawnTimes ): ?PickupEntity
38+ private static function createPickup (int $ entityType , Vector2 $ pos , array $ respawnTimes, array $ spawnDelays ): ?PickupEntity
3739 {
38- $ respawn = $ respawnTimes [$ entityType ] ?? -1 ;
40+ $ respawn = $ respawnTimes [$ entityType ] ?? -1 ;
41+ $ spawnDelay = $ spawnDelays [$ entityType ] ?? 0 ;
3942
4043 return match ($ entityType ) {
41- GameLayer::ENTITY_ARMOR_1 => new PickupEntity ($ pos , NetworkMessages::POWERUP_ARMOR , respawnTime: $ respawn ),
42- GameLayer::ENTITY_HEALTH_1 => new PickupEntity ($ pos , NetworkMessages::POWERUP_HEALTH , respawnTime: $ respawn ),
43- GameLayer::ENTITY_WEAPON_SHOTGUN => new PickupEntity ($ pos , NetworkMessages::POWERUP_WEAPON , GameConstants::WEAPON_SHOTGUN , respawnTime: $ respawn ),
44- GameLayer::ENTITY_WEAPON_GRENADE => new PickupEntity ($ pos , NetworkMessages::POWERUP_WEAPON , GameConstants::WEAPON_GRENADE , respawnTime: $ respawn ),
45- GameLayer::ENTITY_WEAPON_RIFLE => new PickupEntity ($ pos , NetworkMessages::POWERUP_WEAPON , GameConstants::WEAPON_RIFLE , respawnTime: $ respawn ),
46- GameLayer::ENTITY_POWERUP_NINJA => new PickupEntity ($ pos , NetworkMessages::POWERUP_NINJA , respawnTime: $ respawn ),
44+ GameLayer::ENTITY_ARMOR_1 => new PickupEntity ($ pos , NetworkMessages::POWERUP_ARMOR , respawnTime: $ respawn, spawnDelay: $ spawnDelay ),
45+ GameLayer::ENTITY_HEALTH_1 => new PickupEntity ($ pos , NetworkMessages::POWERUP_HEALTH , respawnTime: $ respawn, spawnDelay: $ spawnDelay ),
46+ GameLayer::ENTITY_WEAPON_SHOTGUN => new PickupEntity ($ pos , NetworkMessages::POWERUP_WEAPON , GameConstants::WEAPON_SHOTGUN , respawnTime: $ respawn, spawnDelay: $ spawnDelay ),
47+ GameLayer::ENTITY_WEAPON_GRENADE => new PickupEntity ($ pos , NetworkMessages::POWERUP_WEAPON , GameConstants::WEAPON_GRENADE , respawnTime: $ respawn, spawnDelay: $ spawnDelay ),
48+ GameLayer::ENTITY_WEAPON_RIFLE => new PickupEntity ($ pos , NetworkMessages::POWERUP_WEAPON , GameConstants::WEAPON_RIFLE , respawnTime: $ respawn, spawnDelay: $ spawnDelay ),
49+ GameLayer::ENTITY_POWERUP_NINJA => new PickupEntity ($ pos , NetworkMessages::POWERUP_NINJA , respawnTime: $ respawn, spawnDelay: $ spawnDelay ),
4750 default => null ,
4851 };
4952 }
0 commit comments