Break out spawnable entities and use a registry to spawn them.
Signed-off-by: Hans Kokx <hans.d.kokx@gmail.com>
This commit is contained in:
35
lib/features/entities/entity_registry.dart
Normal file
35
lib/features/entities/entity_registry.dart
Normal file
@@ -0,0 +1,35 @@
|
||||
import 'package:wolf_dart/features/entities/decorative.dart';
|
||||
import 'package:wolf_dart/features/entities/enemies/brown_guard.dart';
|
||||
import 'package:wolf_dart/features/entities/entity.dart';
|
||||
|
||||
typedef EntitySpawner =
|
||||
Entity? Function(int objId, double x, double y, int difficultyLevel);
|
||||
|
||||
abstract class EntityRegistry {
|
||||
// Add future enemies (SSGuard, Dog, etc.) to this list!
|
||||
static final List<EntitySpawner> _spawners = [
|
||||
Decorative.trySpawn,
|
||||
BrownGuard.trySpawn,
|
||||
];
|
||||
|
||||
static Entity? spawn(
|
||||
int objId,
|
||||
double x,
|
||||
double y,
|
||||
int difficultyLevel,
|
||||
int maxSprites,
|
||||
) {
|
||||
for (final spawner in _spawners) {
|
||||
Entity? entity = spawner(objId, x, y, difficultyLevel);
|
||||
|
||||
if (entity != null) {
|
||||
// Safety bounds check for the VSWAP array
|
||||
if (entity.spriteIndex >= 0 && entity.spriteIndex < maxSprites) {
|
||||
return entity;
|
||||
}
|
||||
return null; // VSWAP doesn't have this sprite!
|
||||
}
|
||||
}
|
||||
return null; // No class claimed this Map ID
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user